web3.js/lib/eth.js

106 lines
4.8 KiB
JavaScript
Raw Normal View History

2015-02-05 14:37:30 -08:00
/*
This file is part of ethereum.js.
ethereum.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ethereum.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file eth.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* @date 2015
*/
2015-02-23 08:05:53 -08:00
var formatters = require('./formatters');
var blockCall = function (args) {
return typeof args[0] === "string" ? "eth_blockByHash" : "eth_blockByNumber";
};
2015-02-05 14:37:30 -08:00
var transactionCall = function (args) {
return typeof args[0] === "string" ? 'eth_transactionByHash' : 'eth_transactionByNumber';
};
2015-02-05 14:37:30 -08:00
var uncleCall = function (args) {
return typeof args[0] === "string" ? 'eth_uncleByHash' : 'eth_uncleByNumber';
};
2015-02-05 14:37:30 -08:00
var transactionCountCall = function (args) {
return typeof args[0] === "string" ? 'eth_transactionCountByHash' : 'eth_transactionCountByNumber';
};
var uncleCountCall = function (args) {
return typeof args[0] === "string" ? 'eth_uncleCountByHash' : 'eth_uncleCountByNumber';
};
/// @returns an array of objects describing web3.eth api methods
var methods = [
2015-02-23 08:05:53 -08:00
{ name: 'getBalance', call: 'eth_balanceAt', outputFormatter: formatters.convertToBigNumber},
{ name: 'getStorage', call: 'eth_storageAt' },
2015-03-02 07:29:23 -08:00
{ name: 'getStorageAt', call: 'eth_stateAt' },
2015-02-25 02:01:58 -08:00
{ name: 'getData', call: 'eth_codeAt' },
2015-02-25 07:30:23 -08:00
{ name: 'getBlock', call: blockCall, outputFormatter: formatters.outputBlockFormatter},
{ name: 'getUncle', call: uncleCall, outputFormatter: formatters.outputBlockFormatter},
{ name: 'getCompilers', call: 'eth_compilers' },
{ name: 'getBlockTransactionCount', call: transactionCountCall },
{ name: 'getBlockUncleCount', call: uncleCountCall },
{ name: 'getTransaction', call: transactionCall, outputFormatter: formatters.outputTransactionFormatter },
{ name: 'getTransactionCount', call: 'eth_countAt'},
2015-02-24 04:00:24 -08:00
{ name: 'sendTransaction', call: 'eth_transact', inputFormatter: formatters.inputTransactionFormatter },
2015-02-05 14:37:30 -08:00
{ name: 'call', call: 'eth_call' },
{ name: 'compile.solidity', call: 'eth_solidity' },
{ name: 'compile.lll', call: 'eth_lll' },
{ name: 'compile.serpent', call: 'eth_serpent' },
2015-02-25 07:30:23 -08:00
{ name: 'flush', call: 'eth_flush' },
// deprecated methods
2015-03-02 07:29:23 -08:00
{ name: 'balanceAt', call: 'eth_balanceAt', newMethod: 'eth.getBalance' },
{ name: 'stateAt', call: 'eth_stateAt', newMethod: 'eth.getStorageAt' },
{ name: 'storageAt', call: 'eth_storageAt', newMethod: 'eth.getStorage' },
{ name: 'countAt', call: 'eth_countAt', newMethod: 'eth.getTransactionCount' },
{ name: 'codeAt', call: 'eth_codeAt', newMethod: 'eth.getData' },
{ name: 'transact', call: 'eth_transact', newMethod: 'eth.sendTransaction' },
{ name: 'block', call: blockCall, newMethod: 'eth.getBlock' },
{ name: 'transaction', call: transactionCall, newMethod: 'eth.getTransaction' },
{ name: 'uncle', call: uncleCall, newMethod: 'eth.getUncle' },
{ name: 'compilers', call: 'eth_compilers', newMethod: 'eth.getCompilers' },
{ name: 'solidity', call: 'eth_solidity', newMethod: 'eth.compile.solidity' },
{ name: 'lll', call: 'eth_lll', newMethod: 'eth.compile.lll' },
{ name: 'serpent', call: 'eth_serpent', newMethod: 'eth.compile.serpent' },
{ name: 'transactionCount', call: transactionCountCall, newMethod: 'eth.getBlockTransactionCount' },
{ name: 'uncleCount', call: uncleCountCall, newMethod: 'eth.getBlockUncleCount' },
{ name: 'logs', call: 'eth_logs' }
];
2015-02-05 14:37:30 -08:00
/// @returns an array of objects describing web3.eth api properties
var properties = [
2015-02-05 14:37:30 -08:00
{ name: 'coinbase', getter: 'eth_coinbase', setter: 'eth_setCoinbase' },
{ name: 'mining', getter: 'eth_mining', setter: 'eth_setMining' },
2015-02-23 08:05:53 -08:00
{ name: 'gasPrice', getter: 'eth_gasPrice', outputFormatter: formatters.convertToBigNumber},
2015-02-05 14:37:30 -08:00
{ name: 'accounts', getter: 'eth_accounts' },
{ name: 'defaultBlock', getter: 'eth_defaultBlock', setter: 'eth_setDefaultBlock' },
{ name: 'blockNumber', getter: 'eth_number'},
// deprecated properties
2015-03-02 07:29:23 -08:00
{ name: 'listening', getter: 'net_listening', setter: 'eth_setListening', newProperty: 'net.listening'},
{ name: 'peerCount', getter: 'net_peerCount', newProperty: 'net.peerCount'},
{ name: 'number', getter: 'eth_number', newProperty: 'eth.blockNumber'}
];
2015-02-05 14:37:30 -08:00
module.exports = {
methods: methods,
properties: properties
};