aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-03-28 22:26:05 +0800
committerGitHub <noreply@github.com>2018-03-28 22:26:05 +0800
commit8926dac78c3ac8d75ad5ffd5b4febe36def4e53c (patch)
tree01c1b3f8dba486beb4e83e67ad0bc35c3da6a14e /packages/utils
parent18cac3f0927a0424e3618fd56dba73fc9dfc0288 (diff)
parent01e27426d643b525661e044dbb8c8f27734329e7 (diff)
downloaddexon-0x-contracts-8926dac78c3ac8d75ad5ffd5b4febe36def4e53c.tar
dexon-0x-contracts-8926dac78c3ac8d75ad5ffd5b4febe36def4e53c.tar.gz
dexon-0x-contracts-8926dac78c3ac8d75ad5ffd5b4febe36def4e53c.tar.bz2
dexon-0x-contracts-8926dac78c3ac8d75ad5ffd5b4febe36def4e53c.tar.lz
dexon-0x-contracts-8926dac78c3ac8d75ad5ffd5b4febe36def4e53c.tar.xz
dexon-0x-contracts-8926dac78c3ac8d75ad5ffd5b4febe36def4e53c.tar.zst
dexon-0x-contracts-8926dac78c3ac8d75ad5ffd5b4febe36def4e53c.zip
Merge pull request #482 from 0xProject/feature/web3-types
Move common types out of web3 types
Diffstat (limited to 'packages/utils')
-rw-r--r--packages/utils/src/abi_decoder.ts27
1 files changed, 18 insertions, 9 deletions
diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts
index 2b496eb17..d49906cfb 100644
--- a/packages/utils/src/abi_decoder.ts
+++ b/packages/utils/src/abi_decoder.ts
@@ -1,13 +1,22 @@
-import { AbiType, DecodedLogArgs, LogWithDecodedArgs, RawLog, SolidityTypes } from '@0xproject/types';
+import {
+ AbiDefinition,
+ AbiType,
+ DecodedLogArgs,
+ EventAbi,
+ EventParameter,
+ LogEntry,
+ LogWithDecodedArgs,
+ RawLog,
+ SolidityTypes,
+} from '@0xproject/types';
import * as ethersContracts from 'ethers-contracts';
import * as _ from 'lodash';
-import * as Web3 from 'web3';
import { BigNumber } from './configured_bignumber';
export class AbiDecoder {
- private _savedABIs: Web3.AbiDefinition[] = [];
- private _methodIds: { [signatureHash: string]: Web3.EventAbi } = {};
+ private _savedABIs: AbiDefinition[] = [];
+ private _methodIds: { [signatureHash: string]: EventAbi } = {};
private static _padZeros(address: string) {
let formatted = address;
if (_.startsWith(formatted, '0x')) {
@@ -17,11 +26,11 @@ export class AbiDecoder {
formatted = _.padStart(formatted, 40, '0');
return `0x${formatted}`;
}
- constructor(abiArrays: Web3.AbiDefinition[][]) {
+ constructor(abiArrays: AbiDefinition[][]) {
_.forEach(abiArrays, this._addABI.bind(this));
}
// This method can only decode logs from the 0x & ERC20 smart contracts
- public tryToDecodeLogOrNoop<ArgsType>(log: Web3.LogEntry): LogWithDecodedArgs<ArgsType> | RawLog {
+ public tryToDecodeLogOrNoop<ArgsType>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog {
const methodId = log.topics[0];
const event = this._methodIds[methodId];
if (_.isUndefined(event)) {
@@ -37,7 +46,7 @@ export class AbiDecoder {
const decodedData = ethersInterface.events[event.name].parse(log.data);
let failedToDecode = false;
- _.forEach(event.inputs, (param: Web3.EventParameter, i: number) => {
+ _.forEach(event.inputs, (param: EventParameter, i: number) => {
// Indexed parameters are stored in topics. Non-indexed ones in decodedData
let value: BigNumber | string | number = param.indexed ? log.topics[topicsIndex++] : decodedData[i];
if (_.isUndefined(value)) {
@@ -64,12 +73,12 @@ export class AbiDecoder {
};
}
}
- private _addABI(abiArray: Web3.AbiDefinition[]): void {
+ private _addABI(abiArray: AbiDefinition[]): void {
if (_.isUndefined(abiArray)) {
return;
}
const ethersInterface = new ethersContracts.Interface(abiArray);
- _.map(abiArray, (abi: Web3.AbiDefinition) => {
+ _.map(abiArray, (abi: AbiDefinition) => {
if (abi.type === AbiType.Event) {
const topic = ethersInterface.events[abi.name].topic;
this._methodIds[topic] = abi;