From aeb9ffbf5a09f52d8b2c5b75cdd18f541739b1ea Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Sun, 12 Aug 2018 19:32:32 -0500 Subject: Store methodId and number of indexed args in AbiDecoder to differentiate between events with same function signature --- packages/utils/src/abi_decoder.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'packages/utils') 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(log: LogEntry): LogWithDecodedArgs | 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, + }; } }); } -- cgit v1.2.3 From c13f538400e0ef9e06a5ea52e174979a5cc82bdc Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Mon, 13 Aug 2018 14:18:22 -0700 Subject: Update CHANGELOGs --- packages/utils/CHANGELOG.json | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'packages/utils') diff --git a/packages/utils/CHANGELOG.json b/packages/utils/CHANGELOG.json index 3e3e1125b..673c6b39c 100644 --- a/packages/utils/CHANGELOG.json +++ b/packages/utils/CHANGELOG.json @@ -5,6 +5,10 @@ { "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 -- cgit v1.2.3 From 8bce73dc679cb05353835d011b8e1dfcff7f4670 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Wed, 15 Aug 2018 10:55:48 -0700 Subject: Fix typos, run prettier, and allow anyone to call on DummyERC721Token --- packages/utils/CHANGELOG.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages/utils') diff --git a/packages/utils/CHANGELOG.json b/packages/utils/CHANGELOG.json index 673c6b39c..796a99a5a 100644 --- a/packages/utils/CHANGELOG.json +++ b/packages/utils/CHANGELOG.json @@ -7,7 +7,8 @@ "pr": 807 }, { - "note": "Store different ABIs for events with same function signature and different amount of indexed arguments", + "note": + "Store different ABIs for events with same function signature and different amount of indexed arguments", "pr": 933 } ], -- cgit v1.2.3 From 12881e60e34362f066e3cc28ebe4839cc62620f7 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 21 Aug 2018 14:23:06 +0100 Subject: Fix file name from camel to snake case --- packages/utils/src/fetchAsync.ts | 40 --------------------------------------- packages/utils/src/fetch_async.ts | 40 +++++++++++++++++++++++++++++++++++++++ packages/utils/src/index.ts | 2 +- 3 files changed, 41 insertions(+), 41 deletions(-) delete mode 100644 packages/utils/src/fetchAsync.ts create mode 100644 packages/utils/src/fetch_async.ts (limited to 'packages/utils') diff --git a/packages/utils/src/fetchAsync.ts b/packages/utils/src/fetchAsync.ts deleted file mode 100644 index b4c85718d..000000000 --- a/packages/utils/src/fetchAsync.ts +++ /dev/null @@ -1,40 +0,0 @@ -import isNode = require('detect-node'); -import 'isomorphic-fetch'; -// WARNING: This needs to be imported after isomorphic-fetch: https://github.com/mo/abortcontroller-polyfill#using-it-on-browsers-without-fetch -// tslint:disable-next-line:ordered-imports -import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'; - -export const fetchAsync = async ( - endpoint: string, - options: RequestInit = {}, - timeoutMs: number = 20000, -): Promise => { - if (options.signal || (options as any).timeout) { - throw new Error( - 'Cannot call fetchAsync with options.signal or options.timeout. To set a timeout, please use the supplied "timeoutMs" parameter.', - ); - } - let optionsWithAbortParam; - if (!isNode) { - const controller = new AbortController(); - const signal = controller.signal; - setTimeout(() => { - controller.abort(); - }, timeoutMs); - optionsWithAbortParam = { - signal, - ...options, - }; - } else { - // HACK: the `timeout` param only exists in `node-fetch`, and not on the `isomorphic-fetch` - // `RequestInit` type. Since `isomorphic-fetch` conditionally wraps `node-fetch` when the - // execution environment is `Node.js`, we need to cast it to `any` in that scenario. - optionsWithAbortParam = { - timeout: timeoutMs, - ...options, - } as any; - } - - const response = await fetch(endpoint, optionsWithAbortParam); - return response; -}; diff --git a/packages/utils/src/fetch_async.ts b/packages/utils/src/fetch_async.ts new file mode 100644 index 000000000..b4c85718d --- /dev/null +++ b/packages/utils/src/fetch_async.ts @@ -0,0 +1,40 @@ +import isNode = require('detect-node'); +import 'isomorphic-fetch'; +// WARNING: This needs to be imported after isomorphic-fetch: https://github.com/mo/abortcontroller-polyfill#using-it-on-browsers-without-fetch +// tslint:disable-next-line:ordered-imports +import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'; + +export const fetchAsync = async ( + endpoint: string, + options: RequestInit = {}, + timeoutMs: number = 20000, +): Promise => { + if (options.signal || (options as any).timeout) { + throw new Error( + 'Cannot call fetchAsync with options.signal or options.timeout. To set a timeout, please use the supplied "timeoutMs" parameter.', + ); + } + let optionsWithAbortParam; + if (!isNode) { + const controller = new AbortController(); + const signal = controller.signal; + setTimeout(() => { + controller.abort(); + }, timeoutMs); + optionsWithAbortParam = { + signal, + ...options, + }; + } else { + // HACK: the `timeout` param only exists in `node-fetch`, and not on the `isomorphic-fetch` + // `RequestInit` type. Since `isomorphic-fetch` conditionally wraps `node-fetch` when the + // execution environment is `Node.js`, we need to cast it to `any` in that scenario. + optionsWithAbortParam = { + timeout: timeoutMs, + ...options, + } as any; + } + + const response = await fetch(endpoint, optionsWithAbortParam); + return response; +}; 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'; -- cgit v1.2.3