diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-06-07 08:14:13 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-06-08 06:39:40 +0800 |
commit | db086de84ae7a238b91b5ce79fcc1a8e4c830ac5 (patch) | |
tree | e4e94a44b0dc0e7f99ab44fc968ff4d7457de68d | |
parent | 37684c6af0d2962f7c7822dd14531787bd7b4212 (diff) | |
download | dexon-sol-tools-db086de84ae7a238b91b5ce79fcc1a8e4c830ac5.tar dexon-sol-tools-db086de84ae7a238b91b5ce79fcc1a8e4c830ac5.tar.gz dexon-sol-tools-db086de84ae7a238b91b5ce79fcc1a8e4c830ac5.tar.bz2 dexon-sol-tools-db086de84ae7a238b91b5ce79fcc1a8e4c830ac5.tar.lz dexon-sol-tools-db086de84ae7a238b91b5ce79fcc1a8e4c830ac5.tar.xz dexon-sol-tools-db086de84ae7a238b91b5ce79fcc1a8e4c830ac5.tar.zst dexon-sol-tools-db086de84ae7a238b91b5ce79fcc1a8e4c830ac5.zip |
Union types for generalized decodeAssetData
-rw-r--r-- | packages/contracts/test/asset_proxy/decoder.ts | 4 | ||||
-rw-r--r-- | packages/order-utils/src/asset_proxy_utils.ts | 17 | ||||
-rw-r--r-- | packages/types/src/index.ts | 6 |
3 files changed, 6 insertions, 21 deletions
diff --git a/packages/contracts/test/asset_proxy/decoder.ts b/packages/contracts/test/asset_proxy/decoder.ts index 6a60c07bb..2577dbba5 100644 --- a/packages/contracts/test/asset_proxy/decoder.ts +++ b/packages/contracts/test/asset_proxy/decoder.ts @@ -1,6 +1,6 @@ import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils'; -import { AssetData, AssetProxyId, ERC20AssetData, ERC721AssetData } from '@0xproject/types'; +import { AssetProxyId, ERC20AssetData, ERC721AssetData } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import BN = require('bn.js'); @@ -19,7 +19,7 @@ chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); -describe('TestAssetDataDecoders', () => { +describe.only('TestAssetDataDecoders', () => { let owner: string; let testAssetProxyDecoder: TestAssetDataDecodersContract; let testAddress: string; diff --git a/packages/order-utils/src/asset_proxy_utils.ts b/packages/order-utils/src/asset_proxy_utils.ts index c7b301c1a..1d34172c7 100644 --- a/packages/order-utils/src/asset_proxy_utils.ts +++ b/packages/order-utils/src/asset_proxy_utils.ts @@ -1,4 +1,4 @@ -import { AssetData, AssetProxyId, ERC20AssetData, ERC721AssetData } from '@0xproject/types'; +import { AssetProxyId, ERC20AssetData, ERC721AssetData } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import BN = require('bn.js'); import ethUtil = require('ethereumjs-util'); @@ -157,24 +157,15 @@ export const assetProxyUtils = { const assetProxyId = assetProxyUtils.decodeAssetProxyId(encodedAssetProxyId); return assetProxyId; }, - decodeAssetData(assetData: string): AssetData { + decodeAssetData(assetData: string): ERC20AssetData | ERC721AssetData { const assetProxyId = assetProxyUtils.decodeAssetDataId(assetData); switch (assetProxyId) { case AssetProxyId.ERC20: const erc20AssetData = assetProxyUtils.decodeERC20AssetData(assetData); - const generalizedERC20AssetData = { - assetProxyId, - tokenAddress: erc20AssetData.tokenAddress, - }; - return generalizedERC20AssetData; + return erc20AssetData; case AssetProxyId.ERC721: const erc721AssetData = assetProxyUtils.decodeERC721AssetData(assetData); - const generalizedERC721AssetData = { - assetProxyId, - tokenAddress: erc721AssetData.tokenAddress, - data: erc721AssetData.tokenId, - }; - return generalizedERC721AssetData; + return erc721AssetData; default: throw new Error(`Unrecognized asset proxy id: ${assetProxyId}`); } diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 0f7bb73be..a5da947e1 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -167,9 +167,3 @@ export interface ERC721AssetData { tokenId: BigNumber; receiverData: string; } - -export interface AssetData { - assetProxyId: AssetProxyId; - tokenAddress?: string; - data?: any; -} |