setting up formatters for eth

This commit is contained in:
Marek Kotewicz 2015-03-23 15:08:09 +01:00
parent 99ea9cdc1c
commit b6b809c3d2
2 changed files with 16 additions and 29 deletions

View File

@ -85,29 +85,33 @@ var getBalance = new Method({
var getStorageAt = new Method({ var getStorageAt = new Method({
name: 'getStorageAt', name: 'getStorageAt',
call: 'eth_getStorageAt', call: 'eth_getStorageAt',
params: 3 params: 3,
inputFormatter: [null, null, formatters.inputBlockNumberFormatter]
}); });
var getCode = new Method({ var getCode = new Method({
name: 'getCode', name: 'getCode',
call: 'eth_getCode', call: 'eth_getCode',
params: 2 params: 2,
inputFormatter: [null, formatters.inputBlockNumberFormatter]
}); });
var getBlock = new Method({ var getBlock = new Method({
name: 'getBlock', name: 'getBlock',
call: blockCall, call: blockCall,
params: 1, params: 2,
outputFormatter: formatters.outputBlockFormatter, inputFormatter: [utils.toHex, function (val) { return !!val; }],
inputFormatter: formatters.inputBlockFormatter outputFormatter: formatters.outputBlockFormatter
}); });
var getUncle = new Method({ var getUncle = new Method({
name: 'getUncle', name: 'getUncle',
call: uncleCall, call: uncleCall,
params: 1, params: 2,
inputFormatter: [utils.toHex, utils.toHex],
outputFormatter: formatters.outputBlockFormatter, outputFormatter: formatters.outputBlockFormatter,
inputFormatter: formatters.inputUncleFormatter
}); });
var getCompilers = new Method({ var getCompilers = new Method({

View File

@ -92,19 +92,6 @@ var inputCallFormatter = function (options){
return options; return options;
}; };
var inputBlockFormatter = function (args) {
args[0] = utils.toHex(args[0]);
args[1] = !!args[1];
return args;
};
var inputUncleFormatter = function (args) {
args[0] = utils.toHex(args[0]);
args[1] = utils.toHex(args[1]);
args[2] = !!args[2];
return args;
};
/** /**
* Formats the output of a block to its proper values * Formats the output of a block to its proper values
* *
@ -125,7 +112,7 @@ var outputBlockFormatter = function(block) {
block.difficulty = utils.toBigNumber(block.difficulty); block.difficulty = utils.toBigNumber(block.difficulty);
block.totalDifficulty = utils.toBigNumber(block.totalDifficulty); block.totalDifficulty = utils.toBigNumber(block.totalDifficulty);
if(block.transactions instanceof Array) { if (utils.isArray(block.transactions)) {
block.transactions.forEach(function(item){ block.transactions.forEach(function(item){
if(!utils.isString(item)) if(!utils.isString(item))
return outputTransactionFormatter(item); return outputTransactionFormatter(item);
@ -164,9 +151,9 @@ var inputPostFormatter = function(post){
post.ttl = utils.fromDecimal(post.ttl); post.ttl = utils.fromDecimal(post.ttl);
post.priority = utils.fromDecimal(post.priority); post.priority = utils.fromDecimal(post.priority);
if(!(post.topics instanceof Array)) if(!utils.isArray(post.topics)) {
post.topics = [post.topics]; post.topics = [post.topics];
}
// format the following options // format the following options
post.topics = post.topics.map(function(topic){ post.topics = post.topics.map(function(topic){
@ -192,10 +179,8 @@ var outputPostFormatter = function(post){
post.payloadRaw = post.payload; post.payloadRaw = post.payload;
post.payload = utils.toAscii(post.payload); post.payload = utils.toAscii(post.payload);
if(post.payload.indexOf('{') === 0 || post.payload.indexOf('[') === 0) { if (utils.isJson(post.payload)) {
try { post.payload = JSON.parse(post.payload);
post.payload = JSON.parse(post.payload);
} catch (e) { }
} }
// format the following options // format the following options
@ -211,8 +196,6 @@ module.exports = {
inputTransactionFormatter: inputTransactionFormatter, inputTransactionFormatter: inputTransactionFormatter,
inputCallFormatter: inputCallFormatter, inputCallFormatter: inputCallFormatter,
inputPostFormatter: inputPostFormatter, inputPostFormatter: inputPostFormatter,
inputBlockFormatter: inputBlockFormatter,
inputUncleFormatter: inputUncleFormatter,
outputNumberFormatter: outputNumberFormatter, outputNumberFormatter: outputNumberFormatter,
outputTransactionFormatter: outputTransactionFormatter, outputTransactionFormatter: outputTransactionFormatter,
outputBlockFormatter: outputBlockFormatter, outputBlockFormatter: outputBlockFormatter,