diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-02-10 05:20:15 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-04-21 04:56:16 +0800 |
commit | edf837ed622d782e43b0d25dd46a27469b9b0381 (patch) | |
tree | a53e4b40f1b4aae9ae80b42e2ab998b105358539 /packages/contracts/src/utils/log_decoder.ts | |
parent | 7201a74aeaa6b646e97d7c9c2c4cc979ace5f4f7 (diff) | |
download | dexon-sol-tools-edf837ed622d782e43b0d25dd46a27469b9b0381.tar.gz dexon-sol-tools-edf837ed622d782e43b0d25dd46a27469b9b0381.tar.zst dexon-sol-tools-edf837ed622d782e43b0d25dd46a27469b9b0381.zip |
Add logDecoder, remove outdated tests
Diffstat (limited to 'packages/contracts/src/utils/log_decoder.ts')
-rw-r--r-- | packages/contracts/src/utils/log_decoder.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/packages/contracts/src/utils/log_decoder.ts b/packages/contracts/src/utils/log_decoder.ts new file mode 100644 index 000000000..98dd8eab6 --- /dev/null +++ b/packages/contracts/src/utils/log_decoder.ts @@ -0,0 +1,29 @@ +import { LogWithDecodedArgs, RawLog } from '@0xproject/types'; +import { AbiDecoder } from '@0xproject/utils'; +import * as _ from 'lodash'; +import * as Web3 from 'web3'; + +import { artifacts } from './artifacts'; +import { Artifact } from './types'; + +export class LogDecoder { + private _abiDecoder: AbiDecoder; + constructor(networkId: number) { + if (_.isUndefined(networkId)) { + throw new Error('networkId not specified'); + } + const abiArrays: Web3.AbiDefinition[][] = []; + _.forEach(artifacts, (artifact: Artifact) => { + const network = artifact.networks[networkId]; + if (_.isUndefined(network)) { + throw new Error(`Artifact does not exist on network ${networkId}`); + } + abiArrays.push(network.abi); + }); + this._abiDecoder = new AbiDecoder(abiArrays); + } + public tryToDecodeLogOrNoop<ArgsType>(log: Web3.LogEntry): LogWithDecodedArgs<ArgsType> | RawLog { + const logWithDecodedArgs = this._abiDecoder.tryToDecodeLogOrNoop(log); + return logWithDecodedArgs; + } +} |