diff options
Diffstat (limited to 'packages/0x.js/src/utils/abi_decoder.ts')
-rw-r--r-- | packages/0x.js/src/utils/abi_decoder.ts | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/packages/0x.js/src/utils/abi_decoder.ts b/packages/0x.js/src/utils/abi_decoder.ts index df0fb2d6f..f26b057f0 100644 --- a/packages/0x.js/src/utils/abi_decoder.ts +++ b/packages/0x.js/src/utils/abi_decoder.ts @@ -1,12 +1,22 @@ -import * as Web3 from 'web3'; -import * as _ from 'lodash'; import BigNumber from 'bignumber.js'; -import {AbiType, DecodedLogArgs, LogWithDecodedArgs, RawLog, SolidityTypes, ContractEventArgs} from '../types'; +import * as _ from 'lodash'; +import * as Web3 from 'web3'; import * as SolidityCoder from 'web3/lib/solidity/coder'; +import {AbiType, ContractEventArgs, DecodedLogArgs, LogWithDecodedArgs, RawLog, SolidityTypes} from '../types'; + export class AbiDecoder { private savedABIs: Web3.AbiDefinition[] = []; private methodIds: {[signatureHash: string]: Web3.EventAbi} = {}; + private static padZeros(address: string) { + let formatted = address; + if (_.startsWith(formatted, '0x')) { + formatted = formatted.slice(2); + } + + formatted = _.padStart(formatted, 40, '0'); + return `0x${formatted}`; + } constructor(abiArrays: Web3.AbiDefinition[][]) { _.map(abiArrays, this.addABI.bind(this)); } @@ -31,7 +41,7 @@ export class AbiDecoder { // Indexed parameters are stored in topics. Non-indexed ones in decodedData let value = param.indexed ? log.topics[topicsIndex++] : decodedData[dataIndex++]; if (param.type === SolidityTypes.Address) { - value = this.padZeros(new BigNumber(value).toString(16)); + value = AbiDecoder.padZeros(new BigNumber(value).toString(16)); } else if (param.type === SolidityTypes.Uint256 || param.type === SolidityTypes.Uint8 || param.type === SolidityTypes.Uint) { @@ -56,13 +66,4 @@ export class AbiDecoder { }); this.savedABIs = this.savedABIs.concat(abiArray); } - private padZeros(address: string) { - let formatted = address; - if (_.startsWith(formatted, '0x')) { - formatted = formatted.slice(2); - } - - formatted = _.padStart(formatted, 40, '0'); - return `0x${formatted}`; - } } |