aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/utils/src')
-rw-r--r--packages/utils/src/abi_decoder.ts13
-rw-r--r--packages/utils/src/address_utils.ts9
-rw-r--r--packages/utils/src/log_utils.ts3
3 files changed, 12 insertions, 13 deletions
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..1fc960408 100644
--- a/packages/utils/src/address_utils.ts
+++ b/packages/utils/src/address_utils.ts
@@ -1,7 +1,10 @@
+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})$/;
+const ADDRESS_LENGTH = 40;
export const addressUtils = {
isChecksumAddress(address: string): boolean {
@@ -9,8 +12,7 @@ export const addressUtils = {
const unprefixedAddress = address.replace('0x', '');
const addressHash = jsSHA3.keccak256(unprefixedAddress.toLowerCase());
- const addressLength = 40;
- for (let i = 0; i < addressLength; i++) {
+ for (let i = 0; i < ADDRESS_LENGTH; i++) {
// The nth letter should be uppercase if the nth digit of casemap is 1
const hexBase = 16;
const lowercaseRange = 7;
@@ -38,4 +40,7 @@ export const addressUtils = {
return isValidChecksummedAddress;
}
},
+ padZeros(address: string): string {
+ return addHexPrefix(_.padStart(stripHexPrefix(address), ADDRESS_LENGTH, '0'));
+ },
};
diff --git a/packages/utils/src/log_utils.ts b/packages/utils/src/log_utils.ts
index d0f0e34c9..87f8479b5 100644
--- a/packages/utils/src/log_utils.ts
+++ b/packages/utils/src/log_utils.ts
@@ -2,4 +2,7 @@ export const logUtils = {
log(...args: any[]): void {
console.log(...args); // tslint:disable-line:no-console
},
+ warn(...args: any[]): void {
+ console.warn(...args); // tslint:disable-line:no-console
+ },
};