fixed filters encoding null

This commit is contained in:
Marek Kotewicz 2015-04-22 09:39:28 +02:00
parent 4482d5bf00
commit 5f2eb3308f
11 changed files with 98 additions and 55 deletions

24
dist/web3-light.js vendored
View File

@ -1110,9 +1110,6 @@ var fromDecimal = function (value) {
var toHex = function (val) {
/*jshint maxcomplexity:7 */
if(val === null || typeof val === 'undefined')
return val;
if (isBoolean(val))
return fromDecimal(+val);
@ -2117,15 +2114,16 @@ SolidityEvent.prototype.encode = function (indexed, options) {
return i.indexed === true;
}).map(function (i) {
var value = indexed[i.name];
if (value !== undefined) {
if (utils.isArray(value)) {
return value.map(function (v) {
return '0x' + coder.encodeParam(i.type, v);
});
}
return '0x' + coder.encodeParam(i.type, value);
if (value === undefined || value === null) {
return null;
}
return null;
if (utils.isArray(value)) {
return value.map(function (v) {
return '0x' + coder.encodeParam(i.type, v);
});
}
return '0x' + coder.encodeParam(i.type, value);
});
options.topics = options.topics.concat(indexedTopics);
@ -2245,9 +2243,9 @@ var getOptions = function (options) {
// make sure topics, get converted to hex
options.topics = options.topics || [];
options.topics = options.topics.map(function(topic) {
if (topic === null) {
if (topic === null || topic === undefined) {
return null;
} else if (utils.isArray) {
} else if (utils.isArray(topic)) {
topic = topic.map(utils.toHex);
}
return utils.toHex(topic);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

24
dist/web3.js vendored
View File

@ -1110,9 +1110,6 @@ var fromDecimal = function (value) {
var toHex = function (val) {
/*jshint maxcomplexity:7 */
if(val === null || typeof val === 'undefined')
return val;
if (isBoolean(val))
return fromDecimal(+val);
@ -2117,15 +2114,16 @@ SolidityEvent.prototype.encode = function (indexed, options) {
return i.indexed === true;
}).map(function (i) {
var value = indexed[i.name];
if (value !== undefined) {
if (utils.isArray(value)) {
return value.map(function (v) {
return '0x' + coder.encodeParam(i.type, v);
});
}
return '0x' + coder.encodeParam(i.type, value);
if (value === undefined || value === null) {
return null;
}
return null;
if (utils.isArray(value)) {
return value.map(function (v) {
return '0x' + coder.encodeParam(i.type, v);
});
}
return '0x' + coder.encodeParam(i.type, value);
});
options.topics = options.topics.concat(indexedTopics);
@ -2245,9 +2243,9 @@ var getOptions = function (options) {
// make sure topics, get converted to hex
options.topics = options.topics || [];
options.topics = options.topics.map(function(topic) {
if (topic === null) {
if (topic === null || topic === undefined) {
return null;
} else if (utils.isArray) {
} else if (utils.isArray(topic)) {
topic = topic.map(utils.toHex);
}
return utils.toHex(topic);

8
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

@ -214,9 +214,6 @@ var fromDecimal = function (value) {
var toHex = function (val) {
/*jshint maxcomplexity:7 */
if(val === null || typeof val === 'undefined')
return val;
if (isBoolean(val))
return fromDecimal(+val);

View File

@ -98,15 +98,16 @@ SolidityEvent.prototype.encode = function (indexed, options) {
return i.indexed === true;
}).map(function (i) {
var value = indexed[i.name];
if (value !== undefined) {
if (utils.isArray(value)) {
return value.map(function (v) {
return '0x' + coder.encodeParam(i.type, v);
});
}
return '0x' + coder.encodeParam(i.type, value);
if (value === undefined || value === null) {
return null;
}
return null;
if (utils.isArray(value)) {
return value.map(function (v) {
return '0x' + coder.encodeParam(i.type, v);
});
}
return '0x' + coder.encodeParam(i.type, value);
});
options.topics = options.topics.concat(indexedTopics);

View File

@ -42,7 +42,7 @@ var getOptions = function (options) {
// make sure topics, get converted to hex
options.topics = options.topics || [];
options.topics = options.topics.map(function(topic) {
if (topic === null) {
if (topic === null || topic === undefined) {
return null;
} else if (utils.isArray(topic)) {
topic = topic.map(utils.toHex);

View File

@ -75,7 +75,56 @@ var tests = [{
null // d
]
}
}, {
abi: {
name: 'event1',
inputs: [{
type: 'int',
name: 'a',
indexed: true
}, {
type: 'int',
name: 'b',
indexed: true
}]
},
address: '0x1234567890123456789012345678901234567890',
signature: 'ffff',
indexed: {
a: [16, 1],
b: 2
},
options: {},
expected: {
address: '0x1234567890123456789012345678901234567890',
topics: [
'0xffff',
['0x0000000000000000000000000000000000000000000000000000000000000010', '0x0000000000000000000000000000000000000000000000000000000000000001'],
'0x0000000000000000000000000000000000000000000000000000000000000002'
]
}
}, {
abi: {
name: 'event1',
inputs: [{
type: 'int',
name: 'a',
indexed: true
}]
},
address: '0x1234567890123456789012345678901234567890',
signature: 'ffff',
indexed: {
a: null
},
options: {},
expected: {
address: '0x1234567890123456789012345678901234567890',
topics: [
'0xffff',
null
]
}
}];
describe('lib/web3/event', function () {

View File

@ -4,7 +4,6 @@ var BigNumber = require('bignumber.js');
var assert = chai.assert;
var tests = [
{ value: null, expected: null },
{ value: 1, expected: '0x1' },
{ value: '1', expected: '0x1' },
{ value: '0x1', expected: '0x1'},