aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-07-18 17:32:01 +0800
committerFabio Berger <me@fabioberger.com>2018-07-18 17:32:01 +0800
commit25160d7344f9e1616654dfe09a24d8fc69fa8036 (patch)
tree2ec339700c0a1da1453671719e055692142c5efd /packages/order-utils/src
parent50ed7d2af26d6210f869352ed41084875d2af3d0 (diff)
downloaddexon-sol-tools-25160d7344f9e1616654dfe09a24d8fc69fa8036.tar
dexon-sol-tools-25160d7344f9e1616654dfe09a24d8fc69fa8036.tar.gz
dexon-sol-tools-25160d7344f9e1616654dfe09a24d8fc69fa8036.tar.bz2
dexon-sol-tools-25160d7344f9e1616654dfe09a24d8fc69fa8036.tar.lz
dexon-sol-tools-25160d7344f9e1616654dfe09a24d8fc69fa8036.tar.xz
dexon-sol-tools-25160d7344f9e1616654dfe09a24d8fc69fa8036.tar.zst
dexon-sol-tools-25160d7344f9e1616654dfe09a24d8fc69fa8036.zip
Move encodeUint256 & decodeUint256 out of assetDataUtils since we don't want them exported
Diffstat (limited to 'packages/order-utils/src')
-rw-r--r--packages/order-utils/src/asset_data_utils.ts36
-rw-r--r--packages/order-utils/src/constants.ts1
2 files changed, 12 insertions, 25 deletions
diff --git a/packages/order-utils/src/asset_data_utils.ts b/packages/order-utils/src/asset_data_utils.ts
index 6a4e7600d..ae4da4bb0 100644
--- a/packages/order-utils/src/asset_data_utils.ts
+++ b/packages/order-utils/src/asset_data_utils.ts
@@ -7,19 +7,6 @@ import ethUtil = require('ethereumjs-util');
import { constants } from './constants';
export const assetDataUtils = {
- encodeUint256(value: BigNumber): Buffer {
- const base = 10;
- const formattedValue = new BN(value.toString(base));
- const encodedValue = ethUtil.toBuffer(formattedValue);
- // tslint:disable-next-line:custom-no-magic-numbers
- const paddedValue = ethUtil.setLengthLeft(encodedValue, constants.WORD_LENGTH);
- return paddedValue;
- },
- decodeUint256(encodedValue: Buffer): BigNumber {
- const formattedValue = ethUtil.bufferToHex(encodedValue);
- const value = new BigNumber(formattedValue, constants.BASE_16);
- return value;
- },
encodeERC20AssetData(tokenAddress: string): string {
return ethUtil.bufferToHex(ethAbi.simpleEncode('ERC20Token(address)', tokenAddress));
},
@@ -95,7 +82,7 @@ export const assetDataUtils = {
);
}
const encodedAssetProxyId = encodedAssetData.slice(0, constants.SELECTOR_LENGTH);
- const assetProxyId = assetDataUtils._decodeAssetProxyId(encodedAssetProxyId);
+ const assetProxyId = decodeAssetProxyId(encodedAssetProxyId);
return assetProxyId;
},
decodeAssetData(assetData: string): ERC20AssetData | ERC721AssetData {
@@ -111,14 +98,15 @@ export const assetDataUtils = {
throw new Error(`Unrecognized asset proxy id: ${assetProxyId}`);
}
},
- _decodeAssetProxyId(encodedAssetProxyId: Buffer): AssetProxyId {
- const hexString = ethUtil.bufferToHex(encodedAssetProxyId);
- if (hexString === AssetProxyId.ERC20) {
- return AssetProxyId.ERC20;
- }
- if (hexString === AssetProxyId.ERC721) {
- return AssetProxyId.ERC721;
- }
- throw new Error(`Invalid ProxyId: ${hexString}`);
- },
};
+
+function decodeAssetProxyId(encodedAssetProxyId: Buffer): AssetProxyId {
+ const hexString = ethUtil.bufferToHex(encodedAssetProxyId);
+ if (hexString === AssetProxyId.ERC20) {
+ return AssetProxyId.ERC20;
+ }
+ if (hexString === AssetProxyId.ERC721) {
+ return AssetProxyId.ERC721;
+ }
+ throw new Error(`Invalid ProxyId: ${hexString}`);
+}
diff --git a/packages/order-utils/src/constants.ts b/packages/order-utils/src/constants.ts
index 383a657b8..bb7482184 100644
--- a/packages/order-utils/src/constants.ts
+++ b/packages/order-utils/src/constants.ts
@@ -6,7 +6,6 @@ export const constants = {
UNLIMITED_ALLOWANCE_IN_BASE_UNITS: new BigNumber(2).pow(256).minus(1),
TESTRPC_NETWORK_ID: 50,
ADDRESS_LENGTH: 20,
- WORD_LENGTH: 32,
ERC20_ASSET_DATA_BYTE_LENGTH: 36,
ERC721_ASSET_DATA_MINIMUM_BYTE_LENGTH: 53,
SELECTOR_LENGTH: 4,