aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-09-06 00:45:20 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-09-06 00:45:20 +0800
commita7b2131db77b72379f0d57eaff694d5a925191cd (patch)
treef7c5d443f4bcbd9ee702c8897d1c60a7b6056510 /src
parentf0572679557ebdc6956d079ea2b1f54fd52c2c67 (diff)
downloaddexon-sol-tools-a7b2131db77b72379f0d57eaff694d5a925191cd.tar
dexon-sol-tools-a7b2131db77b72379f0d57eaff694d5a925191cd.tar.gz
dexon-sol-tools-a7b2131db77b72379f0d57eaff694d5a925191cd.tar.bz2
dexon-sol-tools-a7b2131db77b72379f0d57eaff694d5a925191cd.tar.lz
dexon-sol-tools-a7b2131db77b72379f0d57eaff694d5a925191cd.tar.xz
dexon-sol-tools-a7b2131db77b72379f0d57eaff694d5a925191cd.tar.zst
dexon-sol-tools-a7b2131db77b72379f0d57eaff694d5a925191cd.zip
Decode logs args in awaitTransactionMinedAsync
Diffstat (limited to 'src')
-rw-r--r--src/0x.ts43
-rw-r--r--src/contract_wrappers/ether_token_wrapper.ts4
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts4
-rw-r--r--src/contract_wrappers/token_registry_wrapper.ts4
-rw-r--r--src/contract_wrappers/token_transfer_proxy_wrapper.ts4
-rw-r--r--src/contract_wrappers/token_wrapper.ts7
-rw-r--r--src/globals.d.ts15
-rw-r--r--src/types.ts13
8 files changed, 79 insertions, 15 deletions
diff --git a/src/0x.ts b/src/0x.ts
index 209b2704d..d88683c3d 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -1,6 +1,7 @@
import * as _ from 'lodash';
import * as BigNumber from 'bignumber.js';
import * as Web3 from 'web3';
+import * as abiDecoder from 'abi-decoder';
import {SchemaValidator, schemas} from '0x-json-schemas';
import {bigNumberConfigs} from './bignumber_config';
import * as ethUtil from 'ethereumjs-util';
@@ -11,12 +12,24 @@ import {constants} from './utils/constants';
import {utils} from './utils/utils';
import {signatureUtils} from './utils/signature_utils';
import {assert} from './utils/assert';
+import {artifacts} from './artifacts';
import {ExchangeWrapper} from './contract_wrappers/exchange_wrapper';
import {TokenRegistryWrapper} from './contract_wrappers/token_registry_wrapper';
import {EtherTokenWrapper} from './contract_wrappers/ether_token_wrapper';
import {TokenWrapper} from './contract_wrappers/token_wrapper';
import {TokenTransferProxyWrapper} from './contract_wrappers/token_transfer_proxy_wrapper';
-import {ECSignature, ZeroExError, Order, SignedOrder, Web3Provider, ZeroExConfig, TransactionReceipt} from './types';
+import {
+ ECSignature,
+ ZeroExError,
+ Order,
+ SignedOrder,
+ Web3Provider,
+ ZeroExConfig,
+ TransactionReceipt,
+ DecodedLogArgs,
+ TransactionReceiptWithDecodedLogs,
+ LogWithDecodedArgs,
+} from './types';
// Customize our BigNumber instances
bigNumberConfigs.configure();
@@ -170,6 +183,7 @@ export class ZeroEx {
// We re-assign the send method so that Web3@1.0 providers work with 0x.js
(provider as any).sendAsync = (provider as any).send;
}
+ this._registerArtifactsWithinABIDecoder();
const gasPrice = _.isUndefined(config) ? undefined : config.gasPrice;
const defaults = {
gasPrice,
@@ -264,11 +278,34 @@ export class ZeroEx {
const intervalId = setInterval(async () => {
const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash);
if (!_.isNull(transactionReceipt)) {
- clearInterval(intervalId);
- resolve(transactionReceipt);
+ clearInterval(intervalId);
+ const logsWithDecodedArgs = _.map(transactionReceipt.logs, (log: Web3.LogEntry) => {
+ const decodedLog = abiDecoder.decodeLogs([log])[0];
+ const decodedArgs = decodedLog.events;
+ const args: DecodedLogArgs = {};
+ _.forEach(decodedArgs, arg => {
+ args[arg.name] = arg.value;
+ });
+ const logWithDecodedArgs: LogWithDecodedArgs = {
+ ...log,
+ args,
+ event: decodedLog.name,
+ };
+ return logWithDecodedArgs;
+ });
+ const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = {
+ ...transactionReceipt,
+ logs: logsWithDecodedArgs,
+ };
+ resolve(transactionReceiptWithDecodedLogArgs);
}
}, pollingIntervalMs);
});
return txReceiptPromise;
}
+ private _registerArtifactsWithinABIDecoder(): void {
+ for (const artifact of _.values(artifacts)) {
+ abiDecoder.addABI(artifact.abi);
+ }
+ }
}
diff --git a/src/contract_wrappers/ether_token_wrapper.ts b/src/contract_wrappers/ether_token_wrapper.ts
index d31069b22..b86309f90 100644
--- a/src/contract_wrappers/ether_token_wrapper.ts
+++ b/src/contract_wrappers/ether_token_wrapper.ts
@@ -4,7 +4,7 @@ import {ContractWrapper} from './contract_wrapper';
import {TokenWrapper} from './token_wrapper';
import {EtherTokenContract, ZeroExError} from '../types';
import {assert} from '../utils/assert';
-import * as EtherTokenArtifacts from '../artifacts/EtherToken.json';
+import {artifacts} from '../artifacts';
/**
* This class includes all the functionality related to interacting with a wrapped Ether ERC20 token contract.
@@ -76,7 +76,7 @@ export class EtherTokenWrapper extends ContractWrapper {
return this._etherTokenContractIfExists;
}
const contractInstance = await this._instantiateContractIfExistsAsync<EtherTokenContract>(
- EtherTokenArtifacts as any as Artifact,
+ artifacts.EtherTokenArtifact,
);
this._etherTokenContractIfExists = contractInstance as EtherTokenContract;
return this._etherTokenContractIfExists;
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index 2ce9b2922..115bd1110 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -35,7 +35,7 @@ import {ContractWrapper} from './contract_wrapper';
import {constants} from '../utils/constants';
import {TokenWrapper} from './token_wrapper';
import {decorators} from '../utils/decorators';
-import * as ExchangeArtifacts from '../artifacts/Exchange.json';
+import {artifacts} from '../artifacts';
/**
* This class includes all the functionality related to calling methods and subscribing to
@@ -706,7 +706,7 @@ export class ExchangeWrapper extends ContractWrapper {
return this._exchangeContractIfExists;
}
const contractInstance = await this._instantiateContractIfExistsAsync<ExchangeContract>(
- (ExchangeArtifacts as any as Artifact),
+ artifacts.ExchangeArtifact,
);
this._exchangeContractIfExists = contractInstance as ExchangeContract;
return this._exchangeContractIfExists;
diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts
index 79eb516fe..528a88e06 100644
--- a/src/contract_wrappers/token_registry_wrapper.ts
+++ b/src/contract_wrappers/token_registry_wrapper.ts
@@ -4,7 +4,7 @@ import {assert} from '../utils/assert';
import {Token, TokenRegistryContract, TokenMetadata} from '../types';
import {constants} from '../utils/constants';
import {ContractWrapper} from './contract_wrapper';
-import * as TokenRegistryArtifacts from '../artifacts/TokenRegistry.json';
+import {artifacts} from '../artifacts';
/**
* This class includes all the functionality related to interacting with the 0x Token Registry smart contract.
@@ -102,7 +102,7 @@ export class TokenRegistryWrapper extends ContractWrapper {
return this._tokenRegistryContractIfExists;
}
const contractInstance = await this._instantiateContractIfExistsAsync<TokenRegistryContract>(
- TokenRegistryArtifacts as any as Artifact,
+ artifacts.TokenRegistryArtifact,
);
this._tokenRegistryContractIfExists = contractInstance as TokenRegistryContract;
return this._tokenRegistryContractIfExists;
diff --git a/src/contract_wrappers/token_transfer_proxy_wrapper.ts b/src/contract_wrappers/token_transfer_proxy_wrapper.ts
index 2ed198be6..528d661d1 100644
--- a/src/contract_wrappers/token_transfer_proxy_wrapper.ts
+++ b/src/contract_wrappers/token_transfer_proxy_wrapper.ts
@@ -1,6 +1,6 @@
import * as _ from 'lodash';
import {ContractWrapper} from './contract_wrapper';
-import * as TokenTransferProxyArtifacts from '../artifacts/TokenTransferProxy.json';
+import {artifacts} from '../artifacts';
import {TokenTransferProxyContract} from '../types';
/**
@@ -45,7 +45,7 @@ export class TokenTransferProxyWrapper extends ContractWrapper {
return this._tokenTransferProxyContractIfExists;
}
const contractInstance = await this._instantiateContractIfExistsAsync<TokenTransferProxyContract>(
- TokenTransferProxyArtifacts as any as Artifact,
+ artifacts.TokenTransferProxyArtifact,
);
this._tokenTransferProxyContractIfExists = contractInstance as TokenTransferProxyContract;
return this._tokenTransferProxyContractIfExists;
diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts
index db1ce22b2..f1f967286 100644
--- a/src/contract_wrappers/token_wrapper.ts
+++ b/src/contract_wrappers/token_wrapper.ts
@@ -7,8 +7,7 @@ import {utils} from '../utils/utils';
import {eventUtils} from '../utils/event_utils';
import {constants} from '../utils/constants';
import {ContractWrapper} from './contract_wrapper';
-import * as TokenArtifacts from '../artifacts/Token.json';
-import * as TokenTransferProxyArtifacts from '../artifacts/TokenTransferProxy.json';
+import {artifacts} from '../artifacts';
import {
TokenContract,
ZeroExError,
@@ -286,7 +285,7 @@ export class TokenWrapper extends ContractWrapper {
return tokenContract;
}
const contractInstance = await this._instantiateContractIfExistsAsync<TokenContract>(
- TokenArtifacts as any as Artifact, tokenAddress,
+ artifacts.TokenArtifact, tokenAddress,
);
tokenContract = contractInstance as TokenContract;
this._tokenContractsByAddress[tokenAddress] = tokenContract;
@@ -296,7 +295,7 @@ export class TokenWrapper extends ContractWrapper {
const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync();
const proxyNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ?
undefined :
- (TokenTransferProxyArtifacts as any).networks[networkIdIfExists];
+ artifacts.TokenTransferProxyArtifact.networks[networkIdIfExists];
if (_.isUndefined(proxyNetworkConfigsIfExists)) {
throw new Error(ZeroExError.ContractNotDeployedOnNetwork);
}
diff --git a/src/globals.d.ts b/src/globals.d.ts
index 6f5f13b4e..39d0860eb 100644
--- a/src/globals.d.ts
+++ b/src/globals.d.ts
@@ -69,3 +69,18 @@ declare class HDWalletProvider {
declare module 'truffle-hdwallet-provider' {
export = HDWalletProvider;
}
+
+// abi-decoder declarations
+interface DecodedLogArg {
+ name: string;
+ value: string|BigNumber.BigNumber;
+}
+interface DecodedLog {
+ name: string;
+ events: DecodedLogArg[];
+}
+declare module 'abi-decoder' {
+ import * as Web3 from 'web3';
+ const addABI: (abi: Web3.AbiDefinition) => void;
+ const decodeLogs: (logs: Web3.LogEntry[]) => DecodedLog[];
+}
diff --git a/src/types.ts b/src/types.ts
index ddf449c16..9d3f77127 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -397,3 +397,16 @@ export enum AbiType {
Event = 'event',
Fallback = 'fallback',
}
+
+export interface DecodedLogArgs {
+ [argName: string]: ContractEventArg;
+}
+
+export interface LogWithDecodedArgs extends Web3.LogEntry {
+ args: DecodedLogArgs;
+ event: string;
+}
+
+export interface TransactionReceiptWithDecodedLogs extends Web3.TransactionReceipt {
+ logs: LogWithDecodedArgs[];
+}