aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-07-18 17:47:42 +0800
committerFabio Berger <me@fabioberger.com>2018-07-18 17:47:42 +0800
commit89313883098b545c2afe9c4d84bc02b8bc8fd370 (patch)
treecaaf5b1665593e24d2456732298214ed98b16f74 /packages
parent25160d7344f9e1616654dfe09a24d8fc69fa8036 (diff)
downloaddexon-sol-tools-89313883098b545c2afe9c4d84bc02b8bc8fd370.tar
dexon-sol-tools-89313883098b545c2afe9c4d84bc02b8bc8fd370.tar.gz
dexon-sol-tools-89313883098b545c2afe9c4d84bc02b8bc8fd370.tar.bz2
dexon-sol-tools-89313883098b545c2afe9c4d84bc02b8bc8fd370.tar.lz
dexon-sol-tools-89313883098b545c2afe9c4d84bc02b8bc8fd370.tar.xz
dexon-sol-tools-89313883098b545c2afe9c4d84bc02b8bc8fd370.tar.zst
dexon-sol-tools-89313883098b545c2afe9c4d84bc02b8bc8fd370.zip
Add java doc comments to assetDataUtils
Diffstat (limited to 'packages')
-rw-r--r--packages/order-utils/src/asset_data_utils.ts35
1 files changed, 34 insertions, 1 deletions
diff --git a/packages/order-utils/src/asset_data_utils.ts b/packages/order-utils/src/asset_data_utils.ts
index ae4da4bb0..732849f6f 100644
--- a/packages/order-utils/src/asset_data_utils.ts
+++ b/packages/order-utils/src/asset_data_utils.ts
@@ -7,9 +7,20 @@ import ethUtil = require('ethereumjs-util');
import { constants } from './constants';
export const assetDataUtils = {
+ /**
+ * Encodes an ERC20 token address into a hex encoded assetData string, usable in the makerAssetData or
+ * takerAssetData fields in a 0x order.
+ * @param tokenAddress The ERC20 token address to encode
+ * @return The hex encoded assetData string
+ */
encodeERC20AssetData(tokenAddress: string): string {
return ethUtil.bufferToHex(ethAbi.simpleEncode('ERC20Token(address)', tokenAddress));
},
+ /**
+ * Decodes an ERC20 assetData hex string into it's corresponding ERC20 tokenAddress & assetProxyId
+ * @param assetData Hex encoded assetData string to decode
+ * @return An object containing the decoded tokenAddress & assetProxyId
+ */
decodeERC20AssetData(assetData: string): ERC20AssetData {
const data = ethUtil.toBuffer(assetData);
if (data.byteLength < constants.ERC20_ASSET_DATA_BYTE_LENGTH) {
@@ -33,6 +44,13 @@ export const assetDataUtils = {
tokenAddress: ethUtil.addHexPrefix(tokenAddress),
};
},
+ /**
+ * Encodes an ERC721 token address into a hex encoded assetData string, usable in the makerAssetData or
+ * takerAssetData fields in a 0x order.
+ * @param tokenAddress The ERC721 token address to encode
+ * @param tokenId The ERC721 tokenId to encode
+ * @return The hex encoded assetData string
+ */
encodeERC721AssetData(tokenAddress: string, tokenId: BigNumber, receiverData?: string): string {
// TODO: Pass `tokendId` as a BigNumber.
return ethUtil.bufferToHex(
@@ -44,6 +62,11 @@ export const assetDataUtils = {
),
);
},
+ /**
+ * Decodes an ERC721 assetData hex string into it's corresponding ERC721 tokenAddress, tokenId & assetProxyId
+ * @param assetData Hex encoded assetData string to decode
+ * @return An object containing the decoded tokenAddress, tokenId & assetProxyId
+ */
decodeERC721AssetData(assetData: string): ERC721AssetData {
const data = ethUtil.toBuffer(assetData);
if (data.byteLength < constants.ERC721_ASSET_DATA_MINIMUM_BYTE_LENGTH) {
@@ -72,11 +95,16 @@ export const assetDataUtils = {
receiverData: ethUtil.bufferToHex(receiverData),
};
},
+ /**
+ * Decode and return the assetProxyId from the assetData
+ * @param assetData Hex encoded assetData string to decode
+ * @return The assetProxyId
+ */
decodeAssetDataId(assetData: string): AssetProxyId {
const encodedAssetData = ethUtil.toBuffer(assetData);
if (encodedAssetData.byteLength < constants.SELECTOR_LENGTH) {
throw new Error(
- `Could not decode Proxy Data. Expected length of encoded data to be at least 4. Got ${
+ `Could not decode assetData. Expected length of encoded data to be at least 4. Got ${
encodedAssetData.byteLength
}`,
);
@@ -85,6 +113,11 @@ export const assetDataUtils = {
const assetProxyId = decodeAssetProxyId(encodedAssetProxyId);
return assetProxyId;
},
+ /**
+ * Decode any assetData into it's corresponding assetData object
+ * @param assetData Hex encoded assetData string to decode
+ * @return Either a ERC20 or ERC721 assetData object
+ */
decodeAssetData(assetData: string): ERC20AssetData | ERC721AssetData {
const assetProxyId = assetDataUtils.decodeAssetDataId(assetData);
switch (assetProxyId) {