add new toTopic formatter in filters
This commit is contained in:
parent
f37057e80b
commit
a6ac6ed36a
|
@ -198,9 +198,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);
|
||||
|
||||
|
|
|
@ -28,6 +28,22 @@ var RequestManager = require('./requestmanager');
|
|||
var formatters = require('./formatters');
|
||||
var utils = require('../utils/utils');
|
||||
|
||||
/**
|
||||
* Converts a given topic to a hex string, but also allows null values.
|
||||
*
|
||||
* @param {Mixed} value
|
||||
* @return {String}
|
||||
*/
|
||||
var toTopic = function(value){
|
||||
|
||||
if(value === null || typeof value === 'undefined')
|
||||
return value;
|
||||
else if(value.indexOf('0x') === 0)
|
||||
return value;
|
||||
else
|
||||
return utils.fromAscii(String(value));
|
||||
};
|
||||
|
||||
/// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones
|
||||
/// @param should be string or object
|
||||
/// @returns options string or object
|
||||
|
@ -42,9 +58,9 @@ var getOptions = function (options) {
|
|||
// make sure topics, get converted to hex
|
||||
options.topics = options.topics || [];
|
||||
options.topics = options.topics.map(function(topic){
|
||||
return (utils.isArray(topic))
|
||||
? topic.map(utils.toHex)
|
||||
: utils.toHex(topic);
|
||||
return (utils.isArray(topic))
|
||||
? topic.map(toTopic)
|
||||
: toTopic(topic);
|
||||
});
|
||||
|
||||
// lazy load
|
||||
|
|
|
@ -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'},
|
||||
|
|
Loading…
Reference in New Issue