proper formatting event options

This commit is contained in:
Marek Kotewicz 2015-04-22 10:12:39 +02:00
parent 93b323f176
commit b5eabd875f
8 changed files with 71 additions and 27 deletions

18
dist/web3-light.js vendored
View File

@ -1334,7 +1334,6 @@ var isJson = function (str) {
module.exports = {
padLeft: padLeft,
findIndex: findIndex,
toHex: toHex,
toDecimal: toDecimal,
fromDecimal: fromDecimal,
@ -2079,10 +2078,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;
@ -2100,9 +2106,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;
};
/**

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

18
dist/web3.js vendored
View File

@ -1334,7 +1334,6 @@ var isJson = function (str) {
module.exports = {
padLeft: padLeft,
findIndex: findIndex,
toHex: toHex,
toDecimal: toDecimal,
fromDecimal: fromDecimal,
@ -2079,10 +2078,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;
@ -2100,9 +2106,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;
};
/**

6
dist/web3.js.map vendored

File diff suppressed because one or more lines are too long

4
dist/web3.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -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;
@ -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;
};
/**

View File

@ -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 () {