@parity/api
Version:
The Parity Promise-based API library for interfacing with Ethereum over RPC
287 lines (286 loc) • 11.7 kB
JavaScript
"use strict";
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity 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 General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
var _a = require('../../format/input'), inAddress = _a.inAddress, inBlockNumber = _a.inBlockNumber, inData = _a.inData, inFilter = _a.inFilter, inHash = _a.inHash, inHex = _a.inHex, inNumber16 = _a.inNumber16, inOptions = _a.inOptions;
var _b = require('../../format/output'), outAddress = _b.outAddress, outBlock = _b.outBlock, outLog = _b.outLog, outNumber = _b.outNumber, outReceipt = _b.outReceipt, outSyncing = _b.outSyncing, outTransaction = _b.outTransaction;
var Eth = /** @class */ (function () {
function Eth(provider) {
this._provider = provider;
}
Eth.prototype.accounts = function () {
return this._provider
.send('eth_accounts')
.then(function (accounts) { return (accounts || []).map(outAddress); });
};
Eth.prototype.blockNumber = function () {
return this._provider
.send('eth_blockNumber')
.then(outNumber);
};
Eth.prototype.call = function (options, blockNumber) {
if (blockNumber === void 0) { blockNumber = 'latest'; }
return this._provider
.send('eth_call', inOptions(options), inBlockNumber(blockNumber));
};
Eth.prototype.chainId = function () {
return this._provider
.send('eth_chainId')
.then(outNumber);
};
Eth.prototype.coinbase = function () {
return this._provider
.send('eth_coinbase')
.then(outAddress);
};
Eth.prototype.compileLLL = function (code) {
return this._provider
.send('eth_compileLLL', inData(code));
};
Eth.prototype.compileSerpent = function (code) {
return this._provider
.send('eth_compileSerpent', inData(code));
};
Eth.prototype.compileSolidity = function (code) {
return this._provider
.send('eth_compileSolidity', inData(code));
};
Eth.prototype.estimateGas = function (options) {
return this._provider
.send('eth_estimateGas', inOptions(options))
.then(outNumber);
};
Eth.prototype.fetchQueuedTransactions = function () {
return this._provider
.send('eth_fetchQueuedTransactions');
};
Eth.prototype.flush = function () {
return this._provider
.send('eth_flush');
};
Eth.prototype.gasPrice = function () {
return this._provider
.send('eth_gasPrice')
.then(outNumber);
};
Eth.prototype.getBalance = function (address, blockNumber) {
if (blockNumber === void 0) { blockNumber = 'latest'; }
return this._provider
.send('eth_getBalance', inAddress(address), inBlockNumber(blockNumber))
.then(outNumber);
};
Eth.prototype.getBlockByHash = function (hash, full) {
if (full === void 0) { full = false; }
return this._provider
.send('eth_getBlockByHash', inHex(hash), full)
.then(outBlock);
};
Eth.prototype.getBlockByNumber = function (blockNumber, full) {
if (blockNumber === void 0) { blockNumber = 'latest'; }
if (full === void 0) { full = false; }
return this._provider
.send('eth_getBlockByNumber', inBlockNumber(blockNumber), full)
.then(outBlock);
};
Eth.prototype.getBlockTransactionCountByHash = function (hash) {
return this._provider
.send('eth_getBlockTransactionCountByHash', inHex(hash))
.then(outNumber);
};
Eth.prototype.getBlockTransactionCountByNumber = function (blockNumber) {
if (blockNumber === void 0) { blockNumber = 'latest'; }
return this._provider
.send('eth_getBlockTransactionCountByNumber', inBlockNumber(blockNumber))
.then(outNumber);
};
Eth.prototype.getCode = function (address, blockNumber) {
if (blockNumber === void 0) { blockNumber = 'latest'; }
return this._provider
.send('eth_getCode', inAddress(address), inBlockNumber(blockNumber));
};
Eth.prototype.getCompilers = function () {
return this._provider
.send('eth_getCompilers');
};
Eth.prototype.getFilterChanges = function (filterId) {
return this._provider
.send('eth_getFilterChanges', inNumber16(filterId))
.then(function (logs) { return logs.map(outLog); });
};
Eth.prototype.getFilterChangesEx = function (filterId) {
return this._provider
.send('eth_getFilterChangesEx', inNumber16(filterId));
};
Eth.prototype.getFilterLogs = function (filterId) {
return this._provider
.send('eth_getFilterLogs', inNumber16(filterId))
.then(function (logs) { return logs.map(outLog); });
};
Eth.prototype.getFilterLogsEx = function (filterId) {
return this._provider
.send('eth_getFilterLogsEx', inNumber16(filterId));
};
Eth.prototype.getLogs = function (options) {
return this._provider
.send('eth_getLogs', inFilter(options))
.then(function (logs) { return logs.map(outLog); });
};
Eth.prototype.getLogsEx = function (options) {
return this._provider
.send('eth_getLogsEx', inFilter(options));
};
Eth.prototype.getStorageAt = function (address, index, blockNumber) {
if (index === void 0) { index = 0; }
if (blockNumber === void 0) { blockNumber = 'latest'; }
return this._provider
.send('eth_getStorageAt', inAddress(address), inNumber16(index), inBlockNumber(blockNumber));
};
Eth.prototype.getTransactionByBlockHashAndIndex = function (hash, index) {
if (index === void 0) { index = 0; }
return this._provider
.send('eth_getTransactionByBlockHashAndIndex', inHex(hash), inNumber16(index))
.then(outTransaction);
};
Eth.prototype.getTransactionByBlockNumberAndIndex = function (blockNumber, index) {
if (blockNumber === void 0) { blockNumber = 'latest'; }
if (index === void 0) { index = 0; }
return this._provider
.send('eth_getTransactionByBlockNumberAndIndex', inBlockNumber(blockNumber), inNumber16(index))
.then(outTransaction);
};
Eth.prototype.getTransactionByHash = function (hash) {
return this._provider
.send('eth_getTransactionByHash', inHex(hash))
.then(outTransaction);
};
Eth.prototype.getTransactionCount = function (address, blockNumber) {
if (blockNumber === void 0) { blockNumber = 'latest'; }
return this._provider
.send('eth_getTransactionCount', inAddress(address), inBlockNumber(blockNumber))
.then(outNumber);
};
Eth.prototype.getTransactionReceipt = function (txhash) {
return this._provider
.send('eth_getTransactionReceipt', inHex(txhash))
.then(outReceipt);
};
Eth.prototype.getUncleByBlockHashAndIndex = function (hash, index) {
if (index === void 0) { index = 0; }
return this._provider
.send('eth_getUncleByBlockHashAndIndex', inHex(hash), inNumber16(index));
};
Eth.prototype.getUncleByBlockNumberAndIndex = function (blockNumber, index) {
if (blockNumber === void 0) { blockNumber = 'latest'; }
if (index === void 0) { index = 0; }
return this._provider
.send('eth_getUncleByBlockNumberAndIndex', inBlockNumber(blockNumber), inNumber16(index));
};
Eth.prototype.getUncleCountByBlockHash = function (hash) {
return this._provider
.send('eth_getUncleCountByBlockHash', inHex(hash))
.then(outNumber);
};
Eth.prototype.getUncleCountByBlockNumber = function (blockNumber) {
if (blockNumber === void 0) { blockNumber = 'latest'; }
return this._provider
.send('eth_getUncleCountByBlockNumber', inBlockNumber(blockNumber))
.then(outNumber);
};
Eth.prototype.getWork = function () {
return this._provider
.send('eth_getWork');
};
Eth.prototype.hashrate = function () {
return this._provider
.send('eth_hashrate')
.then(outNumber);
};
Eth.prototype.inspectTransaction = function () {
return this._provider
.send('eth_inspectTransaction');
};
Eth.prototype.mining = function () {
return this._provider
.send('eth_mining');
};
Eth.prototype.newBlockFilter = function () {
return this._provider
.send('eth_newBlockFilter');
};
Eth.prototype.newFilter = function (options) {
return this._provider
.send('eth_newFilter', inFilter(options));
};
Eth.prototype.newFilterEx = function (options) {
return this._provider
.send('eth_newFilterEx', inFilter(options));
};
Eth.prototype.newPendingTransactionFilter = function () {
return this._provider
.send('eth_newPendingTransactionFilter');
};
Eth.prototype.notePassword = function () {
return this._provider
.send('eth_notePassword');
};
Eth.prototype.pendingTransactions = function () {
return this._provider
.send('eth_pendingTransactions');
};
Eth.prototype.protocolVersion = function () {
return this._provider
.send('eth_protocolVersion');
};
Eth.prototype.register = function () {
return this._provider
.send('eth_register');
};
Eth.prototype.sendRawTransaction = function (data) {
return this._provider
.send('eth_sendRawTransaction', inData(data));
};
Eth.prototype.sendTransaction = function (options) {
return this._provider
.send('eth_sendTransaction', inOptions(options));
};
Eth.prototype.sign = function (address, hash) {
return this._provider
.send('eth_sign', inAddress(address), inHash(hash));
};
Eth.prototype.signTransaction = function (options) {
return this._provider
.send('eth_signTransaction', inOptions(options));
};
Eth.prototype.submitHashrate = function (hashrate, clientId) {
return this._provider
.send('eth_submitHashrate', inNumber16(hashrate), clientId);
};
Eth.prototype.submitWork = function (nonce, powHash, mixDigest) {
return this._provider
.send('eth_submitWork', inNumber16(nonce), powHash, mixDigest);
};
Eth.prototype.syncing = function () {
return this._provider
.send('eth_syncing')
.then(outSyncing);
};
Eth.prototype.uninstallFilter = function (filterId) {
return this._provider
.send('eth_uninstallFilter', inHex(filterId));
};
Eth.prototype.unregister = function () {
return this._provider
.send('eth_unregister');
};
return Eth;
}());
module.exports = Eth;