deth
Version:
Ethereum node focused on Developer Experience
165 lines (164 loc) • 5.42 kB
JavaScript
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const t = __importStar(require("io-ts"));
const codecs_1 = require("./codecs");
exports.tag = t.union([t.literal('earliest'), t.literal('latest'), t.literal('pending')]);
exports.quantityOrTag = t.union([codecs_1.quantity, exports.tag]);
// https://github.com/ethereum/wiki/wiki/JSON-RPC#returns-26
const blockInfo = t.type({
number: codecs_1.quantity,
hash: codecs_1.hash,
parentHash: codecs_1.hash,
nonce: codecs_1.hexData,
sha3Uncles: codecs_1.hash,
logsBloom: codecs_1.hexData,
transactionsRoot: codecs_1.hash,
stateRoot: codecs_1.hash,
receiptsRoot: codecs_1.hash,
miner: codecs_1.address,
difficulty: codecs_1.quantity,
totalDifficulty: codecs_1.quantity,
extraData: codecs_1.hexData,
size: codecs_1.quantity,
gasLimit: codecs_1.quantity,
gasUsed: codecs_1.quantity,
timestamp: codecs_1.quantity,
transactions: t.array(codecs_1.hash),
uncles: t.array(codecs_1.hash),
});
// https://github.com/ethereum/wiki/wiki/JSON-RPC#returns-31
const txReceipt = t.type({
transactionHash: codecs_1.hash,
transactionIndex: codecs_1.quantity,
blockHash: codecs_1.hash,
blockNumber: codecs_1.quantity,
from: codecs_1.address,
to: codecs_1.undefinable(codecs_1.address),
cumulativeGasUsed: codecs_1.quantity,
gasUsed: codecs_1.quantity,
contractAddress: codecs_1.undefinable(codecs_1.address),
logs: t.array(codecs_1.hexData),
logsBloom: codecs_1.hexData,
status: codecs_1.quantity,
});
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sendtransaction
// @TODO: additional validation rule: if to === null then data can't be null
const tx = t.type({
from: codecs_1.address,
to: codecs_1.undefinable(codecs_1.address),
gas: codecs_1.undefinable(codecs_1.quantity),
gasPrice: codecs_1.undefinable(codecs_1.quantity),
value: codecs_1.undefinable(codecs_1.quantity),
data: codecs_1.undefinable(codecs_1.hexData),
nonce: codecs_1.undefinable(codecs_1.quantity),
});
// https://github.com/ethereum/wiki/wiki/JSON-RPC#parameters-24
const callTtx = t.type({
from: codecs_1.undefinable(codecs_1.address),
to: codecs_1.undefinable(codecs_1.address),
gas: codecs_1.undefinable(codecs_1.quantity),
gasPrice: codecs_1.undefinable(codecs_1.quantity),
value: codecs_1.undefinable(codecs_1.quantity),
data: codecs_1.undefinable(codecs_1.hexData),
});
exports.rpcCommandsDescription = {
web3_clientVersion: {
parameters: t.undefined,
returns: t.string,
},
net_version: {
parameters: t.undefined,
returns: t.string,
},
// eth related
eth_chainId: {
parameters: t.undefined,
returns: codecs_1.quantity,
},
eth_gasPrice: {
parameters: t.undefined,
returns: codecs_1.quantity,
},
eth_getBalance: {
parameters: t.tuple([codecs_1.address, exports.quantityOrTag]),
returns: codecs_1.quantity,
},
eth_blockNumber: {
parameters: t.undefined,
returns: codecs_1.quantity,
},
eth_getTransactionCount: {
parameters: t.tuple([codecs_1.address, exports.quantityOrTag]),
returns: codecs_1.quantity,
},
eth_getCode: {
parameters: t.tuple([codecs_1.address, exports.quantityOrTag]),
returns: codecs_1.hexData,
},
eth_getBlockByNumber: {
parameters: t.tuple([exports.quantityOrTag, t.boolean]),
returns: blockInfo,
},
eth_sendRawTransaction: {
parameters: t.tuple([codecs_1.hexData]),
returns: codecs_1.hash,
},
eth_getTransactionReceipt: {
parameters: t.tuple([codecs_1.hash]),
returns: codecs_1.undefinable(txReceipt),
},
eth_sendTransaction: {
parameters: t.tuple([tx]),
returns: codecs_1.hash,
},
eth_call: {
parameters: t.tuple([callTtx, exports.quantityOrTag]),
returns: codecs_1.hexData,
},
eth_estimateGas: {
parameters: t.tuple([callTtx]),
returns: codecs_1.quantity,
},
eth_getStorageAt: {
parameters: t.tuple([codecs_1.address, codecs_1.quantity, exports.quantityOrTag]),
returns: codecs_1.hexData,
},
eth_accounts: {
parameters: t.undefined,
returns: t.array(codecs_1.address),
},
// ganache compatibility
// docs: https://github.com/trufflesuite/ganache-cli#custom-methods
// note: ganache uses regular numbers as types
evm_increaseTime: {
parameters: t.tuple([t.number]),
returns: codecs_1.quantity,
},
miner_start: {
parameters: t.undefined,
returns: t.literal(true),
},
miner_stop: {
parameters: t.undefined,
returns: t.literal(true),
},
evm_mine: {
parameters: t.undefined,
returns: codecs_1.quantity,
},
evm_snapshot: {
parameters: t.undefined,
returns: codecs_1.quantity,
},
evm_revert: {
parameters: t.tuple([codecs_1.quantity]),
returns: t.literal(true),
},
};