Skip to content

Commit

Permalink
proper formatting event options
Browse files Browse the repository at this point in the history
  • Loading branch information
debris committed Apr 22, 2015
1 parent 93b323f commit b5eabd8
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 27 deletions.
18 changes: 12 additions & 6 deletions dist/web3-light.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/web3-light.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/web3-light.min.js

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions dist/web3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/web3.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/web3.min.js

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions lib/web3/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,17 @@ SolidityEvent.prototype.signature = function () {
SolidityEvent.prototype.encode = function (indexed, options) {
indexed = indexed || {};
options = options || {};
var result = {};

options.address = this._address;
options.topics = options.topics || [];
options.topics.push('0x' + this.signature());
['fromBlock', 'toBlock'].filter(function (f) {
return options[f] !== undefined;
}).forEach(function (f) {
result[f] = utils.toHex(options[f]);
});

result.address = this._address;
result.topics = [];
result.topics.push('0x' + this.signature());

var indexedTopics = this._params.filter(function (i) {
return i.indexed === true;
Expand All @@ -110,9 +117,9 @@ SolidityEvent.prototype.encode = function (indexed, options) {
return '0x' + coder.encodeParam(i.type, value);
});

options.topics = options.topics.concat(indexedTopics);
result.topics = result.topics.concat(indexedTopics);

return options;
return result;
};

/**
Expand Down
25 changes: 25 additions & 0 deletions test/event.encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,31 @@ var tests = [{
null
]
}
}, {
abi: {
name: 'event1',
inputs: [{
type: 'int',
name: 'a',
indexed: true
}]
},
indexed: {
a: 1
},
options: {
fromBlock: 4,
toBlock: 10
},
expected: {
address: address,
fromBlock: '0x4',
toBlock: '0xa',
topics: [
signature,
'0x0000000000000000000000000000000000000000000000000000000000000001'
]
}
}];

describe('lib/web3/event', function () {
Expand Down

0 comments on commit b5eabd8

Please sign in to comment.