diff options
author | Fabio Berger <me@fabioberger.com> | 2018-08-22 18:41:42 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-08-22 18:41:42 +0800 |
commit | 0248add542ac801bcb021fa7b13c182baec5612e (patch) | |
tree | 1d04404632ee381621b384f1e82ade97c06c9b92 /packages/utils | |
parent | c12f0d04bb2f0d5ad73943d02a592a110423a423 (diff) | |
parent | 80e52464a6fdf9576776214f77e46d441b959b06 (diff) | |
download | dexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.tar.gz dexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.tar.zst dexon-sol-tools-0248add542ac801bcb021fa7b13c182baec5612e.zip |
Merge development branch
Diffstat (limited to 'packages/utils')
-rw-r--r-- | packages/utils/CHANGELOG.json | 5 | ||||
-rw-r--r-- | packages/utils/src/abi_decoder.ts | 14 | ||||
-rw-r--r-- | packages/utils/src/fetch_async.ts (renamed from packages/utils/src/fetchAsync.ts) | 0 | ||||
-rw-r--r-- | packages/utils/src/index.ts | 2 |
4 files changed, 15 insertions, 6 deletions
diff --git a/packages/utils/CHANGELOG.json b/packages/utils/CHANGELOG.json index 3e3e1125b..796a99a5a 100644 --- a/packages/utils/CHANGELOG.json +++ b/packages/utils/CHANGELOG.json @@ -5,6 +5,11 @@ { "note": "Increased BigNumber decimal precision from 20 to 78", "pr": 807 + }, + { + "note": + "Store different ABIs for events with same function signature and different amount of indexed arguments", + "pr": 933 } ], "timestamp": 1534210131 diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts index 58a58dea2..265eb105e 100644 --- a/packages/utils/src/abi_decoder.ts +++ b/packages/utils/src/abi_decoder.ts @@ -20,7 +20,7 @@ import { BigNumber } from './configured_bignumber'; * signature from the ABI and attempts to decode the logs using it. */ export class AbiDecoder { - private readonly _methodIds: { [signatureHash: string]: EventAbi } = {}; + private readonly _methodIds: { [signatureHash: string]: { [numIndexedArgs: number]: EventAbi } } = {}; /** * Instantiate an AbiDecoder * @param abiArrays An array of contract ABI's @@ -36,10 +36,11 @@ export class AbiDecoder { */ 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; @@ -58,7 +59,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 @@ -100,7 +100,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, + }; } }); } diff --git a/packages/utils/src/fetchAsync.ts b/packages/utils/src/fetch_async.ts index b4c85718d..b4c85718d 100644 --- a/packages/utils/src/fetchAsync.ts +++ b/packages/utils/src/fetch_async.ts diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index b8e0b1775..9d01e5bc5 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -8,4 +8,4 @@ export { logUtils } from './log_utils'; export { abiUtils } from './abi_utils'; export { NULL_BYTES } from './constants'; export { errorUtils } from './error_utils'; -export { fetchAsync } from './fetchAsync'; +export { fetchAsync } from './fetch_async'; |