aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/utils')
-rw-r--r--packages/utils/CHANGELOG.json18
-rw-r--r--packages/utils/CHANGELOG.md6
-rw-r--r--packages/utils/package.json11
-rw-r--r--packages/utils/src/abi_decoder.ts19
-rw-r--r--packages/utils/src/address_utils.ts16
-rw-r--r--packages/utils/src/interval_utils.ts8
-rw-r--r--packages/utils/src/log_utils.ts3
7 files changed, 55 insertions, 26 deletions
diff --git a/packages/utils/CHANGELOG.json b/packages/utils/CHANGELOG.json
index d3c7da7b9..616a17d62 100644
--- a/packages/utils/CHANGELOG.json
+++ b/packages/utils/CHANGELOG.json
@@ -1,5 +1,23 @@
[
{
+ "timestamp": 1527009133,
+ "version": "0.6.2",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "version": "0.7.0",
+ "changes": [
+ {
+ "note": "Add logUtils.warn",
+ "pr": 589
+ }
+ ]
+ },
+ {
"timestamp": 1525477860,
"version": "0.6.1",
"changes": [
diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md
index 92e466b17..0c01bf4f1 100644
--- a/packages/utils/CHANGELOG.md
+++ b/packages/utils/CHANGELOG.md
@@ -5,7 +5,11 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
-## v0.6.1 - _May 5, 2018_
+## v0.6.2 - _May 22, 2018_
+
+ * Dependencies updated
+
+## v0.6.1 - _May 4, 2018_
* Dependencies updated
diff --git a/packages/utils/package.json b/packages/utils/package.json
index 66dc682fa..24551dd93 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -1,6 +1,6 @@
{
"name": "@0xproject/utils",
- "version": "0.6.1",
+ "version": "0.6.2",
"engines": {
"node": ">=6.12"
},
@@ -24,8 +24,8 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/utils/README.md",
"devDependencies": {
- "@0xproject/monorepo-scripts": "^0.1.19",
- "@0xproject/tslint-config": "^0.4.17",
+ "@0xproject/monorepo-scripts": "^0.1.20",
+ "@0xproject/tslint-config": "^0.4.18",
"@types/lodash": "4.14.104",
"copyfiles": "^1.2.0",
"make-promises-safe": "^1.1.0",
@@ -35,9 +35,10 @@
"typescript": "2.7.1"
},
"dependencies": {
- "@0xproject/types": "^0.6.3",
- "@0xproject/typescript-typings": "^0.3.1",
+ "@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 d329f917a..d2d8364ca 100644
--- a/packages/utils/src/abi_decoder.ts
+++ b/packages/utils/src/abi_decoder.ts
@@ -12,20 +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);
- }
-
- formatted = _.padStart(formatted, 40, '0');
- return `0x${formatted}`;
- }
constructor(abiArrays: AbiDefinition[][]) {
_.forEach(abiArrays, this.addABI.bind(this));
}
@@ -45,16 +37,17 @@ export class AbiDecoder {
const dataTypes = _.map(nonIndexedInputs, input => input.type);
const decodedData = ethersInterface.events[event.name].parse(log.data);
- let failedToDecode = false;
+ let didFailToDecode = false;
_.forEach(event.inputs, (param: EventParameter, i: number) => {
// Indexed parameters are stored in topics. Non-indexed ones in decodedData
let value: BigNumber | string | number = param.indexed ? log.topics[topicsIndex++] : decodedData[i];
if (_.isUndefined(value)) {
- failedToDecode = true;
+ didFailToDecode = true;
return;
}
if (param.type === SolidityTypes.Address) {
- value = AbiDecoder._padZeros(new BigNumber(value).toString(16));
+ const baseHex = 16;
+ 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) {
@@ -63,7 +56,7 @@ export class AbiDecoder {
decodedParams[param.name] = value;
});
- if (failedToDecode) {
+ if (didFailToDecode) {
return log;
} else {
return {
diff --git a/packages/utils/src/address_utils.ts b/packages/utils/src/address_utils.ts
index f94985441..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,11 +12,15 @@ export const addressUtils = {
const unprefixedAddress = address.replace('0x', '');
const addressHash = jsSHA3.keccak256(unprefixedAddress.toLowerCase());
- for (let i = 0; i < 40; 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;
if (
- (parseInt(addressHash[i], 16) > 7 && unprefixedAddress[i].toUpperCase() !== unprefixedAddress[i]) ||
- (parseInt(addressHash[i], 16) <= 7 && unprefixedAddress[i].toLowerCase() !== unprefixedAddress[i])
+ (parseInt(addressHash[i], hexBase) > lowercaseRange &&
+ unprefixedAddress[i].toUpperCase() !== unprefixedAddress[i]) ||
+ (parseInt(addressHash[i], hexBase) <= lowercaseRange &&
+ unprefixedAddress[i].toLowerCase() !== unprefixedAddress[i])
) {
return false;
}
@@ -33,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/interval_utils.ts b/packages/utils/src/interval_utils.ts
index 6984bf42d..6784d5b35 100644
--- a/packages/utils/src/interval_utils.ts
+++ b/packages/utils/src/interval_utils.ts
@@ -6,18 +6,18 @@ export const intervalUtils = {
intervalMs: number,
onError: (err: Error) => void,
): NodeJS.Timer {
- let locked = false;
+ let isLocked = false;
const intervalId = setInterval(async () => {
- if (locked) {
+ if (isLocked) {
return;
} else {
- locked = true;
+ isLocked = true;
try {
await fn();
} catch (err) {
onError(err);
}
- locked = false;
+ isLocked = false;
}
}, intervalMs);
return intervalId;
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
+ },
};