aboutsummaryrefslogtreecommitdiffstats
path: root/contracts/core/test/utils/log_decoder.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-11-23 21:03:48 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-12-03 19:09:28 +0800
commit0faa8b3231ddfc15723a4bdda0b6ed7aeb742bd4 (patch)
tree1d1f4ec74287ff12e305a18fee459772345c2ff1 /contracts/core/test/utils/log_decoder.ts
parent450c72035f13b02cb3cbd24f68a9fcb743aceb26 (diff)
downloaddexon-sol-tools-0faa8b3231ddfc15723a4bdda0b6ed7aeb742bd4.tar
dexon-sol-tools-0faa8b3231ddfc15723a4bdda0b6ed7aeb742bd4.tar.gz
dexon-sol-tools-0faa8b3231ddfc15723a4bdda0b6ed7aeb742bd4.tar.bz2
dexon-sol-tools-0faa8b3231ddfc15723a4bdda0b6ed7aeb742bd4.tar.lz
dexon-sol-tools-0faa8b3231ddfc15723a4bdda0b6ed7aeb742bd4.tar.xz
dexon-sol-tools-0faa8b3231ddfc15723a4bdda0b6ed7aeb742bd4.tar.zst
dexon-sol-tools-0faa8b3231ddfc15723a4bdda0b6ed7aeb742bd4.zip
Refactor contracts-core into contracts-multisig, contracts-core and contracts-test-utils
Diffstat (limited to 'contracts/core/test/utils/log_decoder.ts')
-rw-r--r--contracts/core/test/utils/log_decoder.ts53
1 files changed, 0 insertions, 53 deletions
diff --git a/contracts/core/test/utils/log_decoder.ts b/contracts/core/test/utils/log_decoder.ts
deleted file mode 100644
index 05b0a9204..000000000
--- a/contracts/core/test/utils/log_decoder.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-import { AbiDecoder, BigNumber } from '@0x/utils';
-import { Web3Wrapper } from '@0x/web3-wrapper';
-import {
- AbiDefinition,
- ContractArtifact,
- DecodedLogArgs,
- LogEntry,
- LogWithDecodedArgs,
- RawLog,
- TransactionReceiptWithDecodedLogs,
-} from 'ethereum-types';
-import * as _ from 'lodash';
-
-import { artifacts } from '../../src/artifacts';
-
-import { constants } from './constants';
-
-export class LogDecoder {
- private readonly _web3Wrapper: Web3Wrapper;
- private readonly _abiDecoder: AbiDecoder;
- public static 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]);
- }
- }
- }
- constructor(web3Wrapper: Web3Wrapper) {
- this._web3Wrapper = web3Wrapper;
- const abiArrays: AbiDefinition[][] = [];
- _.forEach(artifacts, (artifact: ContractArtifact) => {
- const compilerOutput = artifact.compilerOutput;
- abiArrays.push(compilerOutput.abi);
- });
- this._abiDecoder = new AbiDecoder(abiArrays);
- }
- public decodeLogOrThrow<ArgsType extends DecodedLogArgs>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog {
- const logWithDecodedArgsOrLog = this._abiDecoder.tryToDecodeLogOrNoop(log);
- // tslint:disable-next-line:no-unnecessary-type-assertion
- if (_.isUndefined((logWithDecodedArgsOrLog as LogWithDecodedArgs<ArgsType>).args)) {
- throw new Error(`Unable to decode log: ${JSON.stringify(log)}`);
- }
- LogDecoder.wrapLogBigNumbers(logWithDecodedArgsOrLog);
- return logWithDecodedArgsOrLog;
- }
- public async getTxWithDecodedLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> {
- const tx = await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS);
- tx.logs = _.map(tx.logs, log => this.decodeLogOrThrow(log));
- return tx;
- }
-}