aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src/utils/log_decoder.ts
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-05-25 08:24:52 +0800
committerGitHub <noreply@github.com>2018-05-25 08:24:52 +0800
commit654698b20880398eded74342c8030a6009938103 (patch)
tree0c206bee801971372866051b08b1710a05eb431a /packages/contracts/src/utils/log_decoder.ts
parent895a9093aa5f204f9f7ad0fedb2934a8b6c40b17 (diff)
parent237ebb07161c46fa85ca778a1c2ff60f63611bd7 (diff)
downloaddexon-sol-tools-654698b20880398eded74342c8030a6009938103.tar
dexon-sol-tools-654698b20880398eded74342c8030a6009938103.tar.gz
dexon-sol-tools-654698b20880398eded74342c8030a6009938103.tar.bz2
dexon-sol-tools-654698b20880398eded74342c8030a6009938103.tar.lz
dexon-sol-tools-654698b20880398eded74342c8030a6009938103.tar.xz
dexon-sol-tools-654698b20880398eded74342c8030a6009938103.tar.zst
dexon-sol-tools-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.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]);
- }
- }
-}
+ },
+};