aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-05-23 02:05:24 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-05-23 06:27:17 +0800
commit83c37c6a7a320326975c8afd9d49a42c9afcefd4 (patch)
treedd58346c8211d7f289a2c822a2309fe932442579 /packages/utils
parentac52ad88a1884979c74f418398bbf428d727cf34 (diff)
downloaddexon-sol-tools-83c37c6a7a320326975c8afd9d49a42c9afcefd4.tar
dexon-sol-tools-83c37c6a7a320326975c8afd9d49a42c9afcefd4.tar.gz
dexon-sol-tools-83c37c6a7a320326975c8afd9d49a42c9afcefd4.tar.bz2
dexon-sol-tools-83c37c6a7a320326975c8afd9d49a42c9afcefd4.tar.lz
dexon-sol-tools-83c37c6a7a320326975c8afd9d49a42c9afcefd4.tar.xz
dexon-sol-tools-83c37c6a7a320326975c8afd9d49a42c9afcefd4.tar.zst
dexon-sol-tools-83c37c6a7a320326975c8afd9d49a42c9afcefd4.zip
Address feedback
Diffstat (limited to 'packages/utils')
-rw-r--r--packages/utils/package.json1
-rw-r--r--packages/utils/src/abi_decoder.ts13
-rw-r--r--packages/utils/src/address_utils.ts5
3 files changed, 8 insertions, 11 deletions
diff --git a/packages/utils/package.json b/packages/utils/package.json
index 99d3d9256..24551dd93 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -38,6 +38,7 @@
"@0xproject/types": "^0.7.0",
"@0xproject/typescript-typings": "^0.3.2",
"@types/node": "^8.0.53",
+ "ethereumjs-util": "^5.1.1",
"bignumber.js": "~4.1.0",
"ethers": "^3.0.15",
"js-sha3": "^0.7.0",
diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts
index c78bfa343..d2d8364ca 100644
--- a/packages/utils/src/abi_decoder.ts
+++ b/packages/utils/src/abi_decoder.ts
@@ -12,21 +12,12 @@ import {
import * as ethers from 'ethers';
import * as _ from 'lodash';
+import { addressUtils } from './address_utils';
import { BigNumber } from './configured_bignumber';
export class AbiDecoder {
private _savedABIs: AbiDefinition[] = [];
private _methodIds: { [signatureHash: string]: EventAbi } = {};
- private static _padZeros(address: string): string {
- let formatted = address;
- if (_.startsWith(formatted, '0x')) {
- formatted = formatted.slice(2);
- }
-
- const addressLength = 40;
- formatted = _.padStart(formatted, addressLength, '0');
- return `0x${formatted}`;
- }
constructor(abiArrays: AbiDefinition[][]) {
_.forEach(abiArrays, this.addABI.bind(this));
}
@@ -56,7 +47,7 @@ export class AbiDecoder {
}
if (param.type === SolidityTypes.Address) {
const baseHex = 16;
- value = AbiDecoder._padZeros(new BigNumber(value).toString(baseHex));
+ value = addressUtils.padZeros(new BigNumber(value).toString(baseHex));
} else if (param.type === SolidityTypes.Uint256 || param.type === SolidityTypes.Uint) {
value = new BigNumber(value);
} else if (param.type === SolidityTypes.Uint8) {
diff --git a/packages/utils/src/address_utils.ts b/packages/utils/src/address_utils.ts
index e25bde249..cc43bd477 100644
--- a/packages/utils/src/address_utils.ts
+++ b/packages/utils/src/address_utils.ts
@@ -1,4 +1,6 @@
+import { addHexPrefix, stripHexPrefix } from 'ethereumjs-util';
import * as jsSHA3 from 'js-sha3';
+import * as _ from 'lodash';
const BASIC_ADDRESS_REGEX = /^(0x)?[0-9a-f]{40}$/i;
const SAME_CASE_ADDRESS_REGEX = /^(0x)?([0-9a-f]{40}|[0-9A-F]{40})$/;
@@ -38,4 +40,7 @@ export const addressUtils = {
return isValidChecksummedAddress;
}
},
+ padZeros(address: string): string {
+ return addHexPrefix(_.padStart(stripHexPrefix(address), 40, '0'));
+ },
};