diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-08-18 04:28:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-18 04:28:01 +0800 |
commit | ddf85112d7e4eb1581e0d82ce6eedad429641106 (patch) | |
tree | 3b2806fadf759b53480233665b98024d5221385e /packages/utils | |
parent | 8131a87046e129f6f5a8978e6133fb21abd8db42 (diff) | |
parent | e35788e2c867d5fa2467ca7f7e564b8ff7b17110 (diff) | |
download | dexon-sol-tools-ddf85112d7e4eb1581e0d82ce6eedad429641106.tar dexon-sol-tools-ddf85112d7e4eb1581e0d82ce6eedad429641106.tar.gz dexon-sol-tools-ddf85112d7e4eb1581e0d82ce6eedad429641106.tar.bz2 dexon-sol-tools-ddf85112d7e4eb1581e0d82ce6eedad429641106.tar.lz dexon-sol-tools-ddf85112d7e4eb1581e0d82ce6eedad429641106.tar.xz dexon-sol-tools-ddf85112d7e4eb1581e0d82ce6eedad429641106.tar.zst dexon-sol-tools-ddf85112d7e4eb1581e0d82ce6eedad429641106.zip |
Merge pull request #933 from 0xProject/refactor/contracts/tokens
[contracts] Refactor token implementations
Diffstat (limited to 'packages/utils')
-rw-r--r-- | packages/utils/CHANGELOG.json | 5 | ||||
-rw-r--r-- | packages/utils/src/abi_decoder.ts | 14 |
2 files changed, 14 insertions, 5 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 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, + }; } }); } |