diff --git a/lib/web3/allevents.js b/lib/web3/allevents.js index d1525427..6ec60605 100644 --- a/lib/web3/allevents.js +++ b/lib/web3/allevents.js @@ -51,19 +51,14 @@ AllSolidityEvents.prototype.encode = function (options) { AllSolidityEvents.prototype.decode = function (data) { data.data = data.data || ''; - if (!utils.isArray(data.topics) || !utils.isString(data.topics[0])) { - console.warn('cannot find event for log'); - return data; - } - var eventTopic = data.topics[0].slice(2); + var eventTopic = (utils.isArray(data.topics) && utils.isString(data.topics[0])) ? data.topics[0].slice(2) : ''; var match = this._json.filter(function (j) { return eventTopic === sha3(utils.transformToFullName(j)); })[0]; if (!match) { // cannot find matching event? - console.warn('cannot find event for log'); - return data; + return formatters.outputLogFormatter(data); } var event = new SolidityEvent(this._requestManager, match, this._address); diff --git a/lib/web3/event.js b/lib/web3/event.js index 72110c6f..786ac9ee 100644 --- a/lib/web3/event.js +++ b/lib/web3/event.js @@ -142,6 +142,7 @@ SolidityEvent.prototype.decode = function (data) { data.data = data.data || ''; data.topics = data.topics || []; + var argTopics = this._anonymous ? data.topics : data.topics.slice(1); var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join(""); var indexedParams = coder.decodeParams(this.types(true), indexedData); diff --git a/test/allevents.decode.js b/test/allevents.decode.js index fb22d1a9..7012c3a3 100644 --- a/test/allevents.decode.js +++ b/test/allevents.decode.js @@ -9,14 +9,15 @@ var name = 'event1'; var address = '0x1234567890123456789012345678901234567890'; var tests = [{ - abi: { + abi: [{ name: name, + type: 'event', inputs: [{ name: 'a', type: 'int', indexed: false }] - }, + }], data: { logIndex: '0x1', transactionIndex: '0x10', @@ -30,54 +31,56 @@ var tests = [{ topics: undefined, }, expected: { - logIndex: '0x1', - transactionIndex: '0x10', + logIndex: 1, + transactionIndex: 16, transactionHash: '0x1234567890', address: address, blockHash: '0x1234567890', - blockNumber: '0x1', + blockNumber: 1, data: '0x' + '0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000004', topics: undefined, } }, { - abi: { - name: name, - inputs: [{ - name: 'a', - type: 'int', - indexed: false - }] - }, - data: { - logIndex: '0x1', - transactionIndex: '0x10', - transactionHash: '0x1234567890', - address: address, - blockHash: '0x1234567890', - blockNumber: '0x1', - data: '0x' + - '0000000000000000000000000000000000000000000000000000000000000001' + - '0000000000000000000000000000000000000000000000000000000000000004', - topics: [], - }, - expected: { - logIndex: '0x1', - transactionIndex: '0x10', - transactionHash: '0x1234567890', - address: address, - blockHash: '0x1234567890', - blockNumber: '0x1', - data: '0x' + - '0000000000000000000000000000000000000000000000000000000000000001' + - '0000000000000000000000000000000000000000000000000000000000000004', - topics: [], - } -}, { - abi: { + abi: [{ name: name, + type: 'event', anonymous: true, + inputs: [{ + name: 'a', + type: 'int', + indexed: false + }] + }], + data: { + logIndex: '0x1', + transactionIndex: '0x10', + transactionHash: '0x1234567890', + address: address, + blockHash: '0x1234567890', + blockNumber: '0x1', + data: '0x' + + '0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000004', + topics: [], + }, + expected: { + logIndex: 1, + transactionIndex: 16, + transactionHash: '0x1234567890', + address: address, + blockHash: '0x1234567890', + blockNumber: 1, + data: '0x' + + '0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000004', + topics: [], + } +}, { + abi: [{ + name: name, + type: 'event', inputs: [{ name: 'a', type: 'int', @@ -95,7 +98,7 @@ var tests = [{ type: 'int', indexed: true }] - }, + }], data: { logIndex: '0x1', transactionIndex: '0x10', @@ -107,7 +110,7 @@ var tests = [{ '0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000004', topics: [ - '0x000000000000000000000000000000000000000000000000000000000000000a', + '0x0e99121e9409665e680573fa7da0cb6651dbdcf10c95f585b92b2c9b9702cff9', '0x0000000000000000000000000000000000000000000000000000000000000010' ] }, @@ -115,9 +118,9 @@ var tests = [{ event: name, args: { a: new BigNumber(1), - b: new BigNumber(10), + b: new BigNumber(16), c: new BigNumber(4), - d: new BigNumber(16) + d: new BigNumber(0) }, logIndex: 1, transactionIndex: 16,