aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/utils/log_decoder.ts
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-05-25 06:33:56 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-05-25 06:39:19 +0800
commit237ebb07161c46fa85ca778a1c2ff60f63611bd7 (patch)
tree67deae8c77054c06435521b05016fda3ac63e780 /packages/contracts/src/utils/log_decoder.ts
parentfdea260e41111f3d27c05ab2d2523d2473c1ac05 (diff)
downloaddexon-sol-tools-237ebb07161c46fa85ca778a1c2ff60f63611bd7.tar
dexon-sol-tools-237ebb07161c46fa85ca778a1c2ff60f63611bd7.tar.gz
dexon-sol-tools-237ebb07161c46fa85ca778a1c2ff60f63611bd7.tar.bz2
dexon-sol-tools-237ebb07161c46fa85ca778a1c2ff60f63611bd7.tar.lz
dexon-sol-tools-237ebb07161c46fa85ca778a1c2ff60f63611bd7.tar.xz
dexon-sol-tools-237ebb07161c46fa85ca778a1c2ff60f63611bd7.tar.zst
dexon-sol-tools-237ebb07161c46fa85ca778a1c2ff60f63611bd7.zip
Use web3-wrapper instead of 0x.js, update logDecoder
Diffstat (limited to 'packages/contracts/src/utils/log_decoder.ts')
-rw-r--r--packages/contracts/src/utils/log_decoder.ts48
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]);
- }
- }
-}
+ },
+};