mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 19:48:13 +00:00
setting up formatters for eth
This commit is contained in:
parent
99ea9cdc1c
commit
b6b809c3d2
@ -85,29 +85,33 @@ var getBalance = new Method({
|
||||
var getStorageAt = new Method({
|
||||
name: 'getStorageAt',
|
||||
call: 'eth_getStorageAt',
|
||||
params: 3
|
||||
params: 3,
|
||||
inputFormatter: [null, null, formatters.inputBlockNumberFormatter]
|
||||
});
|
||||
|
||||
var getCode = new Method({
|
||||
name: 'getCode',
|
||||
call: 'eth_getCode',
|
||||
params: 2
|
||||
params: 2,
|
||||
inputFormatter: [null, formatters.inputBlockNumberFormatter]
|
||||
});
|
||||
|
||||
var getBlock = new Method({
|
||||
name: 'getBlock',
|
||||
call: blockCall,
|
||||
params: 1,
|
||||
outputFormatter: formatters.outputBlockFormatter,
|
||||
inputFormatter: formatters.inputBlockFormatter
|
||||
params: 2,
|
||||
inputFormatter: [utils.toHex, function (val) { return !!val; }],
|
||||
outputFormatter: formatters.outputBlockFormatter
|
||||
|
||||
});
|
||||
|
||||
var getUncle = new Method({
|
||||
name: 'getUncle',
|
||||
call: uncleCall,
|
||||
params: 1,
|
||||
params: 2,
|
||||
inputFormatter: [utils.toHex, utils.toHex],
|
||||
outputFormatter: formatters.outputBlockFormatter,
|
||||
inputFormatter: formatters.inputUncleFormatter
|
||||
|
||||
});
|
||||
|
||||
var getCompilers = new Method({
|
||||
|
@ -92,19 +92,6 @@ var inputCallFormatter = function (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
|
||||
*
|
||||
@ -125,7 +112,7 @@ var outputBlockFormatter = function(block) {
|
||||
block.difficulty = utils.toBigNumber(block.difficulty);
|
||||
block.totalDifficulty = utils.toBigNumber(block.totalDifficulty);
|
||||
|
||||
if(block.transactions instanceof Array) {
|
||||
if (utils.isArray(block.transactions)) {
|
||||
block.transactions.forEach(function(item){
|
||||
if(!utils.isString(item))
|
||||
return outputTransactionFormatter(item);
|
||||
@ -164,9 +151,9 @@ var inputPostFormatter = function(post){
|
||||
post.ttl = utils.fromDecimal(post.ttl);
|
||||
post.priority = utils.fromDecimal(post.priority);
|
||||
|
||||
if(!(post.topics instanceof Array))
|
||||
if(!utils.isArray(post.topics)) {
|
||||
post.topics = [post.topics];
|
||||
|
||||
}
|
||||
|
||||
// format the following options
|
||||
post.topics = post.topics.map(function(topic){
|
||||
@ -192,10 +179,8 @@ var outputPostFormatter = function(post){
|
||||
post.payloadRaw = post.payload;
|
||||
post.payload = utils.toAscii(post.payload);
|
||||
|
||||
if(post.payload.indexOf('{') === 0 || post.payload.indexOf('[') === 0) {
|
||||
try {
|
||||
post.payload = JSON.parse(post.payload);
|
||||
} catch (e) { }
|
||||
if (utils.isJson(post.payload)) {
|
||||
post.payload = JSON.parse(post.payload);
|
||||
}
|
||||
|
||||
// format the following options
|
||||
@ -211,8 +196,6 @@ module.exports = {
|
||||
inputTransactionFormatter: inputTransactionFormatter,
|
||||
inputCallFormatter: inputCallFormatter,
|
||||
inputPostFormatter: inputPostFormatter,
|
||||
inputBlockFormatter: inputBlockFormatter,
|
||||
inputUncleFormatter: inputUncleFormatter,
|
||||
outputNumberFormatter: outputNumberFormatter,
|
||||
outputTransactionFormatter: outputTransactionFormatter,
|
||||
outputBlockFormatter: outputBlockFormatter,
|
||||
|
Loading…
x
Reference in New Issue
Block a user