diff --git a/packages/web3-eth-contract/src/AbstractContract.js b/packages/web3-eth-contract/src/AbstractContract.js index 234ead39c63..9f8c4ede1a5 100644 --- a/packages/web3-eth-contract/src/AbstractContract.js +++ b/packages/web3-eth-contract/src/AbstractContract.js @@ -157,12 +157,12 @@ export default class AbstractContract extends AbstractWeb3Module { * @callback callback callback(error, result) * @returns {Promise} */ - async getPastEvents(eventName, options, callback) { + getPastEvents(eventName, options, callback) { let method; if (eventName !== 'allEvents') { if (!this.abiModel.hasEvent(eventName)) { - throw new Error(`Event with name "${eventName}" does not exists.`); + return Promise.reject(new Error(`Event with name "${eventName}" does not exists.`)); } method = this.methodFactory.createPastEventLogsMethod(this.abiModel.getEvent(eventName)); @@ -173,9 +173,7 @@ export default class AbstractContract extends AbstractWeb3Module { method.parameters = [options]; method.callback = callback; - const response = await method.execute(this); - - return response; + return method.execute(this); } /** diff --git a/packages/web3-eth-contract/src/encoders/EventFilterEncoder.js b/packages/web3-eth-contract/src/encoders/EventFilterEncoder.js index c93cb5a920c..917a0c1c61e 100644 --- a/packages/web3-eth-contract/src/encoders/EventFilterEncoder.js +++ b/packages/web3-eth-contract/src/encoders/EventFilterEncoder.js @@ -41,16 +41,15 @@ export default class EventFilterEncoder { * @returns {Array} */ encode(abiItemModel, filter) { - const indexedInputs = abiItemModel.getIndexedInputs(); let topics = []; - indexedInputs.forEach((indexedInput) => { - if (filter[indexedInput.name]) { - let filterItem = filter[indexedInput.name]; + abiItemModel.getIndexedInputs().forEach((input) => { + if (filter[input.name]) { + let filterItem = filter[input.name]; if (isArray(filterItem)) { filterItem = filterItem.map((item) => { - return this.abiCoder.encodeParameter(indexedInput.type, item); + return this.abiCoder.encodeParameter(input.type, item); }); topics.push(filterItem); @@ -58,8 +57,12 @@ export default class EventFilterEncoder { return; } - topics.push(this.abiCoder.encodeParameter(indexedInput.type, filterItem)); + topics.push(this.abiCoder.encodeParameter(input.type, filterItem)); + + return; } + + topics.push(null); }); return topics; diff --git a/packages/web3-eth-contract/src/mappers/EventOptionsMapper.js b/packages/web3-eth-contract/src/mappers/EventOptionsMapper.js index 487d622ca25..d8aeae759ac 100644 --- a/packages/web3-eth-contract/src/mappers/EventOptionsMapper.js +++ b/packages/web3-eth-contract/src/mappers/EventOptionsMapper.js @@ -60,14 +60,14 @@ export default class EventOptionsMapper { options.toBlock = this.formatters.inputBlockNumberFormatter(options.toBlock); } - if (!abiItemModel.anonymous) { - options.topics.unshift(abiItemModel.signature); - } - if (typeof options.filter !== 'undefined') { options.topics = options.topics.concat(this.eventFilterEncoder.encode(abiItemModel, options.filter)); } + if (!abiItemModel.anonymous) { + options.topics.unshift(abiItemModel.signature); + } + if (!options.address) { options.address = contract.address; } diff --git a/packages/web3-eth-contract/src/methods/AllPastEventLogsMethod.js b/packages/web3-eth-contract/src/methods/AllPastEventLogsMethod.js index db10af215f3..603cbacd240 100644 --- a/packages/web3-eth-contract/src/methods/AllPastEventLogsMethod.js +++ b/packages/web3-eth-contract/src/methods/AllPastEventLogsMethod.js @@ -26,7 +26,7 @@ export default class AllPastEventLogsMethod extends GetPastLogsMethod { /** * @param {Utils} utils * @param {Object} formatters - * @param {AllEventsLogDecoder} eventLogDecoder + * @param {AllEventsLogDecoder} allEventsLogDecoder * @param {AbiModel} abiModel * @param {AllEventsOptionsMapper} allEventsOptionsMapper * @@ -50,6 +50,10 @@ export default class AllPastEventLogsMethod extends GetPastLogsMethod { super.beforeExecution(moduleInstance); this.parameters[0] = this.allEventsOptionsMapper.map(this.abiModel, moduleInstance, this.parameters[0]); + + if (this.parameters[0].filter) { + delete this.parameters[0].filter; + } } /** diff --git a/packages/web3-eth-contract/src/methods/PastEventLogsMethod.js b/packages/web3-eth-contract/src/methods/PastEventLogsMethod.js index a9da28060ec..3175434f9ae 100644 --- a/packages/web3-eth-contract/src/methods/PastEventLogsMethod.js +++ b/packages/web3-eth-contract/src/methods/PastEventLogsMethod.js @@ -49,7 +49,12 @@ export default class PastEventLogsMethod extends GetPastLogsMethod { beforeExecution(moduleInstance) { super.beforeExecution(moduleInstance); + // TODO: Clean up the event options and topics handling instead of deleting the property here. this.parameters[0] = this.eventOptionsMapper.map(this.abiItemModel, moduleInstance, this.parameters[0]); + + if (this.parameters[0].filter) { + delete this.parameters[0].filter; + } } /**