aboutsummaryrefslogtreecommitdiffstats
path: root/src/0x.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-09-06 20:29:52 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-09-06 20:29:52 +0800
commit35f33962958ad68510de891c741f180547b7da0c (patch)
tree6c16bb4f85fee7280ab98456b5aa08e48b2fcd74 /src/0x.ts
parent10817aa33790dd4106df97d8a0dea729ed3d3257 (diff)
downloaddexon-sol-tools-35f33962958ad68510de891c741f180547b7da0c.tar
dexon-sol-tools-35f33962958ad68510de891c741f180547b7da0c.tar.gz
dexon-sol-tools-35f33962958ad68510de891c741f180547b7da0c.tar.bz2
dexon-sol-tools-35f33962958ad68510de891c741f180547b7da0c.tar.lz
dexon-sol-tools-35f33962958ad68510de891c741f180547b7da0c.tar.xz
dexon-sol-tools-35f33962958ad68510de891c741f180547b7da0c.tar.zst
dexon-sol-tools-35f33962958ad68510de891c741f180547b7da0c.zip
Implement custom ABI decoder
Diffstat (limited to 'src/0x.ts')
-rw-r--r--src/0x.ts24
1 files changed, 10 insertions, 14 deletions
diff --git a/src/0x.ts b/src/0x.ts
index 0af164b1e..ff3220757 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -12,6 +12,7 @@ import {constants} from './utils/constants';
import {utils} from './utils/utils';
import {signatureUtils} from './utils/signature_utils';
import {assert} from './utils/assert';
+import {AbiDecoder} from './utils/abi_decoder';
import {artifacts} from './artifacts';
import {ExchangeWrapper} from './contract_wrappers/exchange_wrapper';
import {TokenRegistryWrapper} from './contract_wrappers/token_registry_wrapper';
@@ -70,6 +71,7 @@ export class ZeroEx {
*/
public proxy: TokenTransferProxyWrapper;
private _web3Wrapper: Web3Wrapper;
+ private _abiDecoder: AbiDecoder;
/**
* Verifies that the elliptic curve signature `signature` was generated
* by signing `data` with the private key corresponding to the `signerAddress` address.
@@ -183,7 +185,9 @@ 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 artifactJSONs = _.values(artifacts);
+ const abiArrays = _.map(artifactJSONs, artifact => artifact.abi);
+ this._abiDecoder = new AbiDecoder(abiArrays);
const gasPrice = _.isUndefined(config) ? undefined : config.gasPrice;
const defaults = {
gasPrice,
@@ -281,16 +285,13 @@ export class ZeroEx {
if (!_.isNull(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 decodedLog = this._abiDecoder.decodeLog(log);
+ if (_.isUndefined(decodedLog)) {
+ throw new Error('Unknown log');
+ }
const logWithDecodedArgs: LogWithDecodedArgs = {
...log,
- args,
- event: decodedLog.name,
+ ...decodedLog,
};
return logWithDecodedArgs;
});
@@ -304,9 +305,4 @@ export class ZeroEx {
});
return txReceiptPromise;
}
- private _registerArtifactsWithinABIDecoder(): void {
- for (const artifact of _.values(artifacts)) {
- abiDecoder.addABI(artifact.abi);
- }
- }
}