aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-07-17 21:26:55 +0800
committerFabio Berger <me@fabioberger.com>2018-07-17 21:26:55 +0800
commitf8dbf57582189315566704ca64e36e9c5d07014f (patch)
tree7fc07498c5ae807b1de283a0d564bdb291d9fe2d /packages/order-utils/src
parent15e92958d6e908fde7dabb92aa596adfaeb0eece (diff)
downloaddexon-sol-tools-f8dbf57582189315566704ca64e36e9c5d07014f.tar
dexon-sol-tools-f8dbf57582189315566704ca64e36e9c5d07014f.tar.gz
dexon-sol-tools-f8dbf57582189315566704ca64e36e9c5d07014f.tar.bz2
dexon-sol-tools-f8dbf57582189315566704ca64e36e9c5d07014f.tar.lz
dexon-sol-tools-f8dbf57582189315566704ca64e36e9c5d07014f.tar.xz
dexon-sol-tools-f8dbf57582189315566704ca64e36e9c5d07014f.tar.zst
dexon-sol-tools-f8dbf57582189315566704ca64e36e9c5d07014f.zip
Rename assetProxyUtils to assetDataUtils
Diffstat (limited to 'packages/order-utils/src')
-rw-r--r--packages/order-utils/src/asset_data_utils.ts (renamed from packages/order-utils/src/asset_proxy_utils.ts)49
-rw-r--r--packages/order-utils/src/index.ts2
2 files changed, 16 insertions, 35 deletions
diff --git a/packages/order-utils/src/asset_proxy_utils.ts b/packages/order-utils/src/asset_data_utils.ts
index 8140ad89d..81e34218f 100644
--- a/packages/order-utils/src/asset_proxy_utils.ts
+++ b/packages/order-utils/src/asset_data_utils.ts
@@ -13,36 +13,7 @@ interface EthAbi {
// tslint:disable:no-var-requires
const ethAbi = require('ethereumjs-abi') as EthAbi;
-export const assetProxyUtils = {
- encodeAssetProxyId(assetProxyId: AssetProxyId): Buffer {
- return ethUtil.toBuffer(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}`);
- },
- encodeAddress(address: string): Buffer {
- if (!ethUtil.isValidAddress(address)) {
- throw new Error(`Invalid Address: ${address}`);
- }
- const encodedAddress = ethUtil.toBuffer(address);
- const padded = ethUtil.setLengthLeft(encodedAddress, constants.WORD_LENGTH);
- return padded;
- },
- decodeAddress(encodedAddress: Buffer): string {
- const unpadded = ethUtil.setLengthLeft(encodedAddress, constants.ADDRESS_LENGTH);
- const address = ethUtil.bufferToHex(unpadded);
- if (!ethUtil.isValidAddress(address)) {
- throw new Error(`Invalid Address: ${address}`);
- }
- return address;
- },
+export const assetDataUtils = {
encodeUint256(value: BigNumber): Buffer {
const base = 10;
const formattedValue = new BN(value.toString(base));
@@ -131,20 +102,30 @@ export const assetProxyUtils = {
);
}
const encodedAssetProxyId = encodedAssetData.slice(0, constants.SELECTOR_LENGTH);
- const assetProxyId = assetProxyUtils.decodeAssetProxyId(encodedAssetProxyId);
+ const assetProxyId = assetDataUtils._decodeAssetProxyId(encodedAssetProxyId);
return assetProxyId;
},
decodeAssetData(assetData: string): ERC20AssetData | ERC721AssetData {
- const assetProxyId = assetProxyUtils.decodeAssetDataId(assetData);
+ const assetProxyId = assetDataUtils.decodeAssetDataId(assetData);
switch (assetProxyId) {
case AssetProxyId.ERC20:
- const erc20AssetData = assetProxyUtils.decodeERC20AssetData(assetData);
+ const erc20AssetData = assetDataUtils.decodeERC20AssetData(assetData);
return erc20AssetData;
case AssetProxyId.ERC721:
- const erc721AssetData = assetProxyUtils.decodeERC721AssetData(assetData);
+ const erc721AssetData = assetDataUtils.decodeERC721AssetData(assetData);
return erc721AssetData;
default:
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}`);
+ },
};
diff --git a/packages/order-utils/src/index.ts b/packages/order-utils/src/index.ts
index b4a7a6b67..8d748a2dc 100644
--- a/packages/order-utils/src/index.ts
+++ b/packages/order-utils/src/index.ts
@@ -19,7 +19,7 @@ export { AbstractOrderFilledCancelledFetcher } from './abstract/abstract_order_f
export { BalanceAndProxyAllowanceLazyStore } from './store/balance_and_proxy_allowance_lazy_store';
export { RemainingFillableCalculator } from './remaining_fillable_calculator';
export { OrderStateUtils } from './order_state_utils';
-export { assetProxyUtils } from './asset_proxy_utils';
+export { assetDataUtils } from './asset_data_utils';
export { EIP712Utils } from './eip712_utils';
export { OrderValidationUtils } from './order_validation_utils';
export { ExchangeTransferSimulator } from './exchange_transfer_simulator';