aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-08-13 08:32:32 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-08-17 08:31:21 +0800
commitaeb9ffbf5a09f52d8b2c5b75cdd18f541739b1ea (patch)
tree3bc5c8f0db7c6d321ee5e9c2b7b621d63a81dde1 /packages
parent6dde6d7cb7b9e69fc8f9a7660dfa0141ff6db4b2 (diff)
downloaddexon-sol-tools-aeb9ffbf5a09f52d8b2c5b75cdd18f541739b1ea.tar
dexon-sol-tools-aeb9ffbf5a09f52d8b2c5b75cdd18f541739b1ea.tar.gz
dexon-sol-tools-aeb9ffbf5a09f52d8b2c5b75cdd18f541739b1ea.tar.bz2
dexon-sol-tools-aeb9ffbf5a09f52d8b2c5b75cdd18f541739b1ea.tar.lz
dexon-sol-tools-aeb9ffbf5a09f52d8b2c5b75cdd18f541739b1ea.tar.xz
dexon-sol-tools-aeb9ffbf5a09f52d8b2c5b75cdd18f541739b1ea.tar.zst
dexon-sol-tools-aeb9ffbf5a09f52d8b2c5b75cdd18f541739b1ea.zip
Store methodId and number of indexed args in AbiDecoder to differentiate between events with same function signature
Diffstat (limited to 'packages')
-rw-r--r--packages/utils/src/abi_decoder.ts14
1 files changed, 9 insertions, 5 deletions
diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts
index 7f93e746e..cc05321ab 100644
--- a/packages/utils/src/abi_decoder.ts
+++ b/packages/utils/src/abi_decoder.ts
@@ -16,17 +16,18 @@ import { addressUtils } from './address_utils';
import { BigNumber } from './configured_bignumber';
export class AbiDecoder {
- private readonly _methodIds: { [signatureHash: string]: EventAbi } = {};
+ private readonly _methodIds: { [signatureHash: string]: { [numIndexedArgs: number]: EventAbi } } = {};
constructor(abiArrays: AbiDefinition[][]) {
_.forEach(abiArrays, this.addABI.bind(this));
}
// This method can only decode logs from the 0x & ERC20 smart contracts
public tryToDecodeLogOrNoop<ArgsType extends DecodedLogArgs>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog {
const methodId = log.topics[0];
- const event = this._methodIds[methodId];
- if (_.isUndefined(event)) {
+ const numIndexedArgs = log.topics.length - 1;
+ if (_.isUndefined(this._methodIds[methodId]) || _.isUndefined(this._methodIds[methodId][numIndexedArgs])) {
return log;
}
+ const event = this._methodIds[methodId][numIndexedArgs];
const ethersInterface = new ethers.Interface([event]);
const decodedParams: DecodedLogArgs = {};
let topicsIndex = 1;
@@ -45,7 +46,6 @@ export class AbiDecoder {
}
throw error;
}
-
let didFailToDecode = false;
_.forEach(event.inputs, (param: EventParameter, i: number) => {
// Indexed parameters are stored in topics. Non-indexed ones in decodedData
@@ -83,7 +83,11 @@ export class AbiDecoder {
_.map(abiArray, (abi: AbiDefinition) => {
if (abi.type === AbiType.Event) {
const topic = ethersInterface.events[abi.name].topics[0];
- this._methodIds[topic] = abi;
+ const numIndexedArgs = _.reduce(abi.inputs, (sum, input) => (input.indexed ? sum + 1 : sum), 0);
+ this._methodIds[topic] = {
+ ...this._methodIds[topic],
+ [numIndexedArgs]: abi,
+ };
}
});
}