aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src/abi_decoder.ts
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-05-24 05:16:32 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-05-24 05:16:32 +0800
commit3fe94891d3569a4615f4aa32d47f0065b5957fe9 (patch)
tree83d4e4ccf7748d2100aa935c457de0a893eaec9c /packages/utils/src/abi_decoder.ts
parentd0abc60176dba3116cb3986d298ab5164c1fe49c (diff)
parentf6b81f588d98e09e7a5806902d94e2892d029481 (diff)
downloaddexon-sol-tools-3fe94891d3569a4615f4aa32d47f0065b5957fe9.tar
dexon-sol-tools-3fe94891d3569a4615f4aa32d47f0065b5957fe9.tar.gz
dexon-sol-tools-3fe94891d3569a4615f4aa32d47f0065b5957fe9.tar.bz2
dexon-sol-tools-3fe94891d3569a4615f4aa32d47f0065b5957fe9.tar.lz
dexon-sol-tools-3fe94891d3569a4615f4aa32d47f0065b5957fe9.tar.xz
dexon-sol-tools-3fe94891d3569a4615f4aa32d47f0065b5957fe9.tar.zst
dexon-sol-tools-3fe94891d3569a4615f4aa32d47f0065b5957fe9.zip
Merge branch 'v2-prototype' into feature/website/wallet-flex-box
* v2-prototype: (95 commits) Add missing dep to website Upgrade solidity parser Fix trace test Fix linter issues Move contract utils Fix prettier Fix NameResolver Fix prettier Remove 0x.js as a dependency from website Enable 0x.js tests Fix small bug in order-utils Address feedback Fix Tslint error caused by "PromiseLike" value Fix Tslint error caused by "PromiseLike" value Update dogfood url fix contract-wrappers version Parse compiler.json in SolCompilerArtifactsAdapter Fix TokenTransferProxy artifact name since it's now suffixed with _v1 Update yarn.lock Fix signature verification test ...
Diffstat (limited to 'packages/utils/src/abi_decoder.ts')
-rw-r--r--packages/utils/src/abi_decoder.ts19
1 files changed, 6 insertions, 13 deletions
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 {