From 1c94ab7cc3819ee991800a3d2439c02e4083a891 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Sat, 21 Apr 2018 16:03:58 -0700 Subject: export proxyUtils instead of individual functions --- packages/contracts/src/utils/asset_proxy_utils.ts | 66 +++++++++++------------ 1 file changed, 32 insertions(+), 34 deletions(-) (limited to 'packages/contracts/src/utils') diff --git a/packages/contracts/src/utils/asset_proxy_utils.ts b/packages/contracts/src/utils/asset_proxy_utils.ts index da610cbcc..29e50a860 100644 --- a/packages/contracts/src/utils/asset_proxy_utils.ts +++ b/packages/contracts/src/utils/asset_proxy_utils.ts @@ -4,37 +4,35 @@ import ethUtil = require('ethereumjs-util'); import { AssetProxyId } from './types'; -export function encodeAssetProxyId(assetProxyId: AssetProxyId): Buffer { - return ethUtil.toBuffer(assetProxyId); -} - -export function encodeAddress(address: string): Buffer { - if (!ethUtil.isValidAddress(address)) { - throw new Error(`Invalid Address: ${address}`); - } - const encodedAddress = ethUtil.toBuffer(address); - return encodedAddress; -} - -export function encodeUint256(value: BigNumber): Buffer { - const formattedValue = new BN(value.toString(10)); - const encodedValue = ethUtil.toBuffer(formattedValue); - return encodedValue; -} - -export function encodeERC20ProxyData(tokenAddress: string): string { - const encodedAssetProxyId = encodeAssetProxyId(AssetProxyId.ERC20); - const encodedAddress = encodeAddress(tokenAddress); - const encodedMetadata = Buffer.concat([encodedAssetProxyId, encodedAddress]); - const encodedMetadataHex = ethUtil.bufferToHex(encodedMetadata); - return encodedMetadataHex; -} - -export function encodeERC721ProxyData(tokenAddress: string, tokenId: BigNumber): string { - const encodedAssetProxyId = encodeAssetProxyId(AssetProxyId.ERC721); - const encodedAddress = encodeAddress(tokenAddress); - const encodedTokenId = encodeUint256(tokenId); - const encodedMetadata = Buffer.concat([encodedAssetProxyId, encodedAddress, encodedTokenId]); - const encodedMetadataHex = ethUtil.bufferToHex(encodedMetadata); - return encodedMetadataHex; -} +export const proxyUtils = { + encodeAssetProxyId(assetProxyId: AssetProxyId): Buffer { + return ethUtil.toBuffer(assetProxyId); + }, + encodeAddress(address: string): Buffer { + if (!ethUtil.isValidAddress(address)) { + throw new Error(`Invalid Address: ${address}`); + } + const encodedAddress = ethUtil.toBuffer(address); + return encodedAddress; + }, + encodeUint256(value: BigNumber): Buffer { + const formattedValue = new BN(value.toString(10)); + const encodedValue = ethUtil.toBuffer(formattedValue); + return encodedValue; + }, + encodeERC20ProxyData(tokenAddress: string): string { + const encodedAssetProxyId = proxyUtils.encodeAssetProxyId(AssetProxyId.ERC20); + const encodedAddress = proxyUtils.encodeAddress(tokenAddress); + const encodedMetadata = Buffer.concat([encodedAssetProxyId, encodedAddress]); + const encodedMetadataHex = ethUtil.bufferToHex(encodedMetadata); + return encodedMetadataHex; + }, + encodeERC721ProxyData(tokenAddress: string, tokenId: BigNumber): string { + const encodedAssetProxyId = proxyUtils.encodeAssetProxyId(AssetProxyId.ERC721); + const encodedAddress = proxyUtils.encodeAddress(tokenAddress); + const encodedTokenId = proxyUtils.encodeUint256(tokenId); + const encodedMetadata = Buffer.concat([encodedAssetProxyId, encodedAddress, encodedTokenId]); + const encodedMetadataHex = ethUtil.bufferToHex(encodedMetadata); + return encodedMetadataHex; + }, +}; -- cgit v1.2.3