aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-12-04 08:58:51 +0800
committerAmir Bandeali <abandeali1@gmail.com>2019-01-08 02:31:11 +0800
commit0abace337c8309b22092519091d10e3474095878 (patch)
treec345cef8bc1a2c39c1b0b6a7648171217eab4ce7 /packages
parentc6ff77bdd8ea04e04a9be4ae2e5dc30afc89665b (diff)
downloaddexon-sol-tools-0abace337c8309b22092519091d10e3474095878.tar
dexon-sol-tools-0abace337c8309b22092519091d10e3474095878.tar.gz
dexon-sol-tools-0abace337c8309b22092519091d10e3474095878.tar.bz2
dexon-sol-tools-0abace337c8309b22092519091d10e3474095878.tar.lz
dexon-sol-tools-0abace337c8309b22092519091d10e3474095878.tar.xz
dexon-sol-tools-0abace337c8309b22092519091d10e3474095878.tar.zst
dexon-sol-tools-0abace337c8309b22092519091d10e3474095878.zip
Rename functions
Diffstat (limited to 'packages')
-rw-r--r--packages/order-utils/package.json6
-rw-r--r--packages/order-utils/src/asset_data_utils.ts28
2 files changed, 16 insertions, 18 deletions
diff --git a/packages/order-utils/package.json b/packages/order-utils/package.json
index 8a5150a48..400c9b66f 100644
--- a/packages/order-utils/package.json
+++ b/packages/order-utils/package.json
@@ -13,14 +13,12 @@
"test": "yarn run_mocha",
"rebuild_and_test": "run-s build test",
"test:circleci": "yarn test:coverage",
- "run_mocha":
- "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js --bail --exit",
+ "run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js --bail --exit",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"clean": "shx rm -rf lib generated_docs",
"lint": "tslint --format stylish --project .",
- "docs:json":
- "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
+ "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
},
"config": {
"postpublish": {
diff --git a/packages/order-utils/src/asset_data_utils.ts b/packages/order-utils/src/asset_data_utils.ts
index 1b416abd1..2adaf31b8 100644
--- a/packages/order-utils/src/asset_data_utils.ts
+++ b/packages/order-utils/src/asset_data_utils.ts
@@ -5,8 +5,8 @@ import * as _ from 'lodash';
import { constants } from './constants';
-const encodingRules: AbiEncoder.EncodingRules = { optimize: true };
-const decodingRules: AbiEncoder.DecodingRules = { structsAsObjects: true };
+const encodingRules: AbiEncoder.EncodingRules = { shouldOptimize: true };
+const decodingRules: AbiEncoder.DecodingRules = { shouldConvertStructsToObjects: true };
export const assetDataUtils = {
/**
@@ -27,13 +27,13 @@ export const assetDataUtils = {
* @return An object containing the decoded tokenAddress & assetProxyId
*/
decodeERC20AssetData(assetData: string): ERC20AssetData {
- assetDataUtils.validateERC20AssetDataThrow(assetData);
+ assetDataUtils.assertIsERC20AssetData(assetData);
const assetProxyId = assetDataUtils.decodeAssetProxyId(assetData);
const abiEncoder = new AbiEncoder.Method(constants.ERC20_METHOD_ABI as MethodAbi);
const decodedAssetData = abiEncoder.decode(assetData, decodingRules);
return {
assetProxyId,
- // TODO(abandeali1): fix decode return types
+ // TODO(abandeali1): fix return types for `AbiEncoder.Method.decode` so that we can remove type assertion
tokenAddress: (decodedAssetData as any).tokenContract,
};
},
@@ -56,13 +56,13 @@ export const assetDataUtils = {
* @return An object containing the decoded tokenAddress, tokenId & assetProxyId
*/
decodeERC721AssetData(assetData: string): ERC721AssetData {
- assetDataUtils.validateERC721AssetDataOrThrow(assetData);
+ assetDataUtils.assertIsERC721AssetData(assetData);
const assetProxyId = assetDataUtils.decodeAssetProxyId(assetData);
const abiEncoder = new AbiEncoder.Method(constants.ERC721_METHOD_ABI as MethodAbi);
const decodedAssetData = abiEncoder.decode(assetData, decodingRules);
return {
assetProxyId,
- // TODO(abandeali1): fix decode return types
+ // TODO(abandeali1): fix return types for `AbiEncoder.Method.decode` so that we can remove type assertion
tokenAddress: (decodedAssetData as any).tokenContract,
tokenId: (decodedAssetData as any).tokenId,
};
@@ -94,11 +94,11 @@ export const assetDataUtils = {
* @return An object containing the decoded amounts and nestedAssetData
*/
decodeMultiAssetData(assetData: string): MultiAssetData {
- assetDataUtils.validateMultiAssetDataOrThrow(assetData);
+ assetDataUtils.assertIsMultiAssetData(assetData);
const assetProxyId = assetDataUtils.decodeAssetProxyId(assetData);
const abiEncoder = new AbiEncoder.Method(constants.MULTI_ASSET_METHOD_ABI as MethodAbi);
const decodedAssetData = abiEncoder.decode(assetData, decodingRules);
- // TODO(abandeali1): fix decode return types
+ // TODO(abandeali1): fix return types for `AbiEncoder.Method.decode` so that we can remove type assertion
const amounts = (decodedAssetData as any).amounts;
const nestedAssetData = (decodedAssetData as any).nestedAssetData;
if (amounts.length !== nestedAssetData.length) {
@@ -141,7 +141,7 @@ export const assetDataUtils = {
* Throws if the length or assetProxyId are invalid for the ERC20Proxy.
* @param assetData Hex encoded assetData string
*/
- validateERC20AssetDataThrow(assetData: string): void {
+ assertIsERC20AssetData(assetData: string): void {
if (assetData.length < constants.ERC20_ASSET_DATA_MIN_CHAR_LENGTH_WITH_PREFIX) {
throw new Error(
`Could not decode ERC20 Proxy Data. Expected length of encoded data to be at least ${
@@ -162,7 +162,7 @@ export const assetDataUtils = {
* Throws if the length or assetProxyId are invalid for the ERC721Proxy.
* @param assetData Hex encoded assetData string
*/
- validateERC721AssetDataOrThrow(assetData: string): void {
+ assertIsERC721AssetData(assetData: string): void {
if (assetData.length < constants.ERC721_ASSET_DATA_MIN_CHAR_LENGTH_WITH_PREFIX) {
throw new Error(
`Could not decode ERC721 assetData. Expected length of encoded data to be at least ${
@@ -183,7 +183,7 @@ export const assetDataUtils = {
* Throws if the length or assetProxyId are invalid for the MultiAssetProxy.
* @param assetData Hex encoded assetData string
*/
- validateMultiAssetDataOrThrow(assetData: string): void {
+ assertIsMultiAssetData(assetData: string): void {
if (assetData.length < constants.MULTI_ASSET_DATA_MIN_CHAR_LENGTH_WITH_PREFIX) {
throw new Error(
`Could not decode MultiAsset assetData. Expected length of encoded data to be at least ${
@@ -208,13 +208,13 @@ export const assetDataUtils = {
const assetProxyId = assetDataUtils.decodeAssetProxyId(assetData);
switch (assetProxyId) {
case AssetProxyId.ERC20:
- assetDataUtils.validateERC20AssetDataThrow(assetData);
+ assetDataUtils.assertIsERC20AssetData(assetData);
break;
case AssetProxyId.ERC721:
- assetDataUtils.validateERC721AssetDataOrThrow(assetData);
+ assetDataUtils.assertIsERC721AssetData(assetData);
break;
case AssetProxyId.MultiAsset:
- assetDataUtils.validateMultiAssetDataOrThrow(assetData);
+ assetDataUtils.assertIsMultiAssetData(assetData);
break;
default:
throw new Error(`Unrecognized asset proxy id: ${assetProxyId}`);