diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-05-25 08:24:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-25 08:24:52 +0800 |
commit | 654698b20880398eded74342c8030a6009938103 (patch) | |
tree | 0c206bee801971372866051b08b1710a05eb431a /packages/contracts/src/utils/log_decoder.ts | |
parent | 895a9093aa5f204f9f7ad0fedb2934a8b6c40b17 (diff) | |
parent | 237ebb07161c46fa85ca778a1c2ff60f63611bd7 (diff) | |
download | dexon-0x-contracts-654698b20880398eded74342c8030a6009938103.tar dexon-0x-contracts-654698b20880398eded74342c8030a6009938103.tar.gz dexon-0x-contracts-654698b20880398eded74342c8030a6009938103.tar.bz2 dexon-0x-contracts-654698b20880398eded74342c8030a6009938103.tar.lz dexon-0x-contracts-654698b20880398eded74342c8030a6009938103.tar.xz dexon-0x-contracts-654698b20880398eded74342c8030a6009938103.tar.zst dexon-0x-contracts-654698b20880398eded74342c8030a6009938103.zip |
Merge pull request #571 from 0xProject/feature/contracts/proxyOwner
Update MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress
Diffstat (limited to 'packages/contracts/src/utils/log_decoder.ts')
-rw-r--r-- | packages/contracts/src/utils/log_decoder.ts | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/packages/contracts/src/utils/log_decoder.ts b/packages/contracts/src/utils/log_decoder.ts index 747c7644d..d2e65d176 100644 --- a/packages/contracts/src/utils/log_decoder.ts +++ b/packages/contracts/src/utils/log_decoder.ts @@ -5,35 +5,29 @@ import * as _ from 'lodash'; import { artifacts } from './artifacts'; -export class LogDecoder { - private _abiDecoder: AbiDecoder; - constructor(networkIdIfExists?: number) { - if (_.isUndefined(networkIdIfExists)) { - throw new Error('networkId not specified'); +const abiArrays: AbiDefinition[][] = []; +_.forEach(artifacts, (artifact: ContractArtifact) => { + const compilerOutput = artifact.compilerOutput; + abiArrays.push(compilerOutput.abi); +}); +const abiDecoder = new AbiDecoder(abiArrays); + +export const logDecoder = { + wrapLogBigNumbers(log: any): any { + const argNames = _.keys(log.args); + for (const argName of argNames) { + const isWeb3BigNumber = _.startsWith(log.args[argName].constructor.toString(), 'function BigNumber('); + if (isWeb3BigNumber) { + log.args[argName] = new BigNumber(log.args[argName]); + } } - const abiArrays: AbiDefinition[][] = []; - _.forEach(artifacts, (artifact: ContractArtifact) => { - const compilerOutput = artifact.compilerOutput; - abiArrays.push(compilerOutput.abi); - }); - this._abiDecoder = new AbiDecoder(abiArrays); - } - public decodeLogOrThrow<ArgsType>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog { - const logWithDecodedArgsOrLog = this._abiDecoder.tryToDecodeLogOrNoop(log); + }, + decodeLogOrThrow<ArgsType>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog { + const logWithDecodedArgsOrLog = abiDecoder.tryToDecodeLogOrNoop(log); if (_.isUndefined((logWithDecodedArgsOrLog as LogWithDecodedArgs<ArgsType>).args)) { throw new Error(`Unable to decode log: ${JSON.stringify(log)}`); } - wrapLogBigNumbers(logWithDecodedArgsOrLog); + logDecoder.wrapLogBigNumbers(logWithDecodedArgsOrLog); return logWithDecodedArgsOrLog; - } -} - -function wrapLogBigNumbers(log: any): any { - const argNames = _.keys(log.args); - for (const argName of argNames) { - const isWeb3BigNumber = _.startsWith(log.args[argName].constructor.toString(), 'function BigNumber('); - if (isWeb3BigNumber) { - log.args[argName] = new BigNumber(log.args[argName]); - } - } -} + }, +}; |