2018-06-20 17:27:32 +00:00
|
|
|
# Nimbus
|
2024-01-09 02:05:52 +00:00
|
|
|
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
2018-06-20 17:27:32 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
# at your option.
|
|
|
|
# This file may not be copied, modified, or distributed except according to
|
|
|
|
# those terms.
|
2018-10-05 00:20:12 +00:00
|
|
|
|
2023-02-14 20:27:17 +00:00
|
|
|
{.push raises: [].}
|
|
|
|
|
2018-07-31 17:18:43 +00:00
|
|
|
import
|
2024-05-15 03:07:59 +00:00
|
|
|
std/[sequtils, times, tables, typetraits],
|
2024-06-29 05:43:17 +00:00
|
|
|
json_rpc/rpcserver,
|
|
|
|
stint,
|
|
|
|
stew/byteutils,
|
|
|
|
json_serialization,
|
|
|
|
web3/conversions,
|
|
|
|
json_serialization/stew/results,
|
2022-01-24 13:08:33 +00:00
|
|
|
eth/common/eth_types_json_serialization,
|
2022-12-02 04:39:12 +00:00
|
|
|
eth/[keys, rlp, p2p],
|
2024-06-17 07:56:39 +00:00
|
|
|
".."/[transaction, evm/state, constants],
|
2024-06-16 03:21:02 +00:00
|
|
|
../db/ledger,
|
2024-04-16 01:02:42 +00:00
|
|
|
./rpc_types, ./rpc_utils, ./oracle,
|
2022-01-23 11:39:43 +00:00
|
|
|
../transaction/call_evm,
|
2022-12-02 04:39:12 +00:00
|
|
|
../core/tx_pool,
|
2024-04-04 00:25:56 +00:00
|
|
|
../core/eip4844,
|
2022-12-02 04:39:12 +00:00
|
|
|
../common/[common, context],
|
|
|
|
../utils/utils,
|
2023-12-08 09:35:50 +00:00
|
|
|
../beacon/web3_eth_conv,
|
2024-06-07 08:24:32 +00:00
|
|
|
../evm/evm_errors,
|
2022-06-29 15:44:08 +00:00
|
|
|
./filters
|
2018-08-14 17:22:31 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
type
|
|
|
|
BlockHeader = eth_types.BlockHeader
|
|
|
|
Hash256 = eth_types.Hash256
|
|
|
|
|
2024-01-22 09:11:37 +00:00
|
|
|
proc getProof*(
|
2024-06-16 03:21:02 +00:00
|
|
|
accDB: LedgerRef,
|
2024-01-22 09:11:37 +00:00
|
|
|
address: EthAddress,
|
2024-06-16 03:21:02 +00:00
|
|
|
slots: seq[UInt256]): ProofResponse =
|
2024-01-22 09:11:37 +00:00
|
|
|
let
|
2024-06-16 03:21:02 +00:00
|
|
|
acc = accDB.getEthAccount(address)
|
2024-01-22 09:11:37 +00:00
|
|
|
accExists = accDB.accountExists(address)
|
|
|
|
accountProof = accDB.getAccountProof(address)
|
|
|
|
slotProofs = accDB.getStorageProof(address, slots)
|
|
|
|
|
|
|
|
var storage = newSeqOfCap[StorageProof](slots.len)
|
|
|
|
|
|
|
|
for i, slotKey in slots:
|
2024-06-16 03:21:02 +00:00
|
|
|
let slotValue = accDB.getStorage(address, slotKey)
|
2024-01-22 09:11:37 +00:00
|
|
|
storage.add(StorageProof(
|
2024-06-14 07:31:08 +00:00
|
|
|
key: slotKey,
|
2024-01-22 09:11:37 +00:00
|
|
|
value: slotValue,
|
|
|
|
proof: seq[RlpEncodedBytes](slotProofs[i])))
|
|
|
|
|
|
|
|
if accExists:
|
|
|
|
ProofResponse(
|
|
|
|
address: w3Addr(address),
|
|
|
|
accountProof: seq[RlpEncodedBytes](accountProof),
|
|
|
|
balance: acc.balance,
|
|
|
|
nonce: w3Qty(acc.nonce),
|
|
|
|
codeHash: w3Hash(acc.codeHash),
|
2024-06-16 03:21:02 +00:00
|
|
|
storageHash: w3Hash(acc.storageRoot),
|
2024-01-22 09:11:37 +00:00
|
|
|
storageProof: storage)
|
|
|
|
else:
|
|
|
|
ProofResponse(
|
|
|
|
address: w3Addr(address),
|
|
|
|
accountProof: seq[RlpEncodedBytes](accountProof),
|
|
|
|
storageProof: storage)
|
|
|
|
|
2022-09-10 13:05:32 +00:00
|
|
|
proc setupEthRpc*(
|
2022-12-02 04:39:12 +00:00
|
|
|
node: EthereumNode, ctx: EthContext, com: CommonRef,
|
2024-04-16 01:02:42 +00:00
|
|
|
txPool: TxPoolRef, oracle: Oracle, server: RpcServer) =
|
2018-10-05 00:20:12 +00:00
|
|
|
|
2022-12-02 04:39:12 +00:00
|
|
|
let chainDB = com.db
|
2024-06-16 03:21:02 +00:00
|
|
|
proc getStateDB(header: BlockHeader): LedgerRef =
|
2018-08-29 17:12:39 +00:00
|
|
|
## Retrieves the account db from canonical head
|
2020-07-22 16:51:26 +00:00
|
|
|
# we don't use accounst_cache here because it's only read operations
|
2024-06-16 03:21:02 +00:00
|
|
|
LedgerRef.init(chainDB, header.stateRoot)
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2024-06-16 03:21:02 +00:00
|
|
|
proc stateDBFromTag(quantityTag: BlockTag, readOnly = true): LedgerRef
|
2023-01-31 01:32:17 +00:00
|
|
|
{.gcsafe, raises: [CatchableError].} =
|
2024-10-02 03:56:39 +00:00
|
|
|
getStateDB(chainDB.headerFromTag(quantityTag))
|
2018-08-29 17:12:39 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
server.rpc("eth_chainId") do() -> Web3Quantity:
|
|
|
|
return w3Qty(distinctBase(com.chainId))
|
2022-09-10 13:05:32 +00:00
|
|
|
|
2024-01-13 01:41:57 +00:00
|
|
|
server.rpc("eth_syncing") do() -> SyncingStatus:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns SyncObject or false when not syncing.
|
2024-09-12 16:42:38 +00:00
|
|
|
if com.syncState != Waiting:
|
|
|
|
let sync = SyncObject(
|
2023-12-08 09:35:50 +00:00
|
|
|
startingBlock: w3Qty com.syncStart,
|
|
|
|
currentBlock : w3Qty com.syncCurrent,
|
|
|
|
highestBlock : w3Qty com.syncHighest
|
2020-07-22 16:51:26 +00:00
|
|
|
)
|
2024-09-12 16:42:38 +00:00
|
|
|
return SyncingStatus(syncing: true, syncObject: sync)
|
2018-08-13 18:29:38 +00:00
|
|
|
else:
|
2024-09-12 16:42:38 +00:00
|
|
|
return SyncingStatus(syncing: false)
|
2018-10-05 00:20:12 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
server.rpc("eth_gasPrice") do() -> Web3Quantity:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns an integer of the current gas price in wei.
|
2024-10-02 03:56:39 +00:00
|
|
|
w3Qty(calculateMedianGasPrice(chainDB).uint64)
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
server.rpc("eth_accounts") do() -> seq[Web3Address]:
|
2021-09-11 14:58:01 +00:00
|
|
|
## Returns a list of addresses owned by client.
|
2023-12-08 09:35:50 +00:00
|
|
|
result = newSeqOfCap[Web3Address](ctx.am.numAccounts)
|
2021-09-07 12:30:12 +00:00
|
|
|
for k in ctx.am.addresses:
|
2023-12-08 09:35:50 +00:00
|
|
|
result.add w3Addr(k)
|
2018-07-31 17:18:43 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
server.rpc("eth_blockNumber") do() -> Web3Quantity:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns integer of the current block number the client is on.
|
2024-10-02 03:56:39 +00:00
|
|
|
w3Qty(chainDB.getCanonicalHead().number)
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2023-12-27 00:48:53 +00:00
|
|
|
server.rpc("eth_getBalance") do(data: Web3Address, quantityTag: BlockTag) -> UInt256:
|
2018-07-31 17:18:43 +00:00
|
|
|
## Returns the balance of the account of given address.
|
|
|
|
##
|
|
|
|
## data: address to check for balance.
|
|
|
|
## quantityTag: integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.
|
|
|
|
## Returns integer of the current balance in wei.
|
|
|
|
let
|
2021-10-28 09:42:39 +00:00
|
|
|
accDB = stateDBFromTag(quantityTag)
|
2023-12-08 09:35:50 +00:00
|
|
|
address = data.ethAddr
|
2024-10-02 03:56:39 +00:00
|
|
|
accDB.getBalance(address)
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2024-09-29 12:37:09 +00:00
|
|
|
server.rpc("eth_getStorageAt") do(data: Web3Address, slot: UInt256, quantityTag: BlockTag) -> Web3FixedBytes[32]:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns the value from a storage position at a given address.
|
|
|
|
##
|
|
|
|
## data: address of the storage.
|
2022-06-27 09:49:51 +00:00
|
|
|
## slot: integer of the position in the storage.
|
2018-08-13 18:29:38 +00:00
|
|
|
## quantityTag: integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.
|
|
|
|
## Returns: the value at this storage position.
|
|
|
|
let
|
2021-10-28 09:42:39 +00:00
|
|
|
accDB = stateDBFromTag(quantityTag)
|
2023-12-08 09:35:50 +00:00
|
|
|
address = data.ethAddr
|
2024-06-16 03:21:02 +00:00
|
|
|
data = accDB.getStorage(address, slot)
|
2024-10-02 03:56:39 +00:00
|
|
|
data.w3FixedBytes
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2023-12-27 00:48:53 +00:00
|
|
|
server.rpc("eth_getTransactionCount") do(data: Web3Address, quantityTag: BlockTag) -> Web3Quantity:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns the number of transactions sent from an address.
|
|
|
|
##
|
|
|
|
## data: address.
|
|
|
|
## quantityTag: integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.
|
|
|
|
## Returns integer of the number of transactions send from this address.
|
2018-08-14 15:52:30 +00:00
|
|
|
let
|
2023-12-08 09:35:50 +00:00
|
|
|
address = data.ethAddr
|
2021-10-28 09:42:39 +00:00
|
|
|
accDB = stateDBFromTag(quantityTag)
|
2024-10-02 03:56:39 +00:00
|
|
|
w3Qty(accDB.getNonce(address))
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
server.rpc("eth_getBlockTransactionCountByHash") do(data: Web3Hash) -> Web3Quantity:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns the number of transactions in a block from a block matching the given block hash.
|
|
|
|
##
|
|
|
|
## data: hash of a block
|
|
|
|
## Returns integer of the number of transactions in this block.
|
2020-07-22 16:51:26 +00:00
|
|
|
let
|
2023-12-08 09:35:50 +00:00
|
|
|
blockHash = data.ethHash
|
2022-12-02 04:39:12 +00:00
|
|
|
header = chainDB.getBlockHeader(blockHash)
|
|
|
|
txCount = chainDB.getTransactionCount(header.txRoot)
|
2024-10-02 03:56:39 +00:00
|
|
|
Web3Quantity(txCount)
|
2020-07-23 07:54:32 +00:00
|
|
|
|
2023-12-27 00:48:53 +00:00
|
|
|
server.rpc("eth_getBlockTransactionCountByNumber") do(quantityTag: BlockTag) -> Web3Quantity:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns the number of transactions in a block matching the given block number.
|
|
|
|
##
|
|
|
|
## data: integer of a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.
|
|
|
|
## Returns integer of the number of transactions in this block.
|
2020-07-23 07:54:32 +00:00
|
|
|
let
|
2022-12-02 04:39:12 +00:00
|
|
|
header = chainDB.headerFromTag(quantityTag)
|
|
|
|
txCount = chainDB.getTransactionCount(header.txRoot)
|
2024-10-02 03:56:39 +00:00
|
|
|
Web3Quantity(txCount)
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
server.rpc("eth_getUncleCountByBlockHash") do(data: Web3Hash) -> Web3Quantity:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns the number of uncles in a block from a block matching the given block hash.
|
|
|
|
##
|
|
|
|
## data: hash of a block.
|
|
|
|
## Returns integer of the number of uncles in this block.
|
2020-07-23 07:54:32 +00:00
|
|
|
let
|
2023-12-08 09:35:50 +00:00
|
|
|
blockHash = data.ethHash
|
2022-12-02 04:39:12 +00:00
|
|
|
header = chainDB.getBlockHeader(blockHash)
|
|
|
|
unclesCount = chainDB.getUnclesCount(header.ommersHash)
|
2024-10-02 03:56:39 +00:00
|
|
|
Web3Quantity(unclesCount)
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2023-12-27 00:48:53 +00:00
|
|
|
server.rpc("eth_getUncleCountByBlockNumber") do(quantityTag: BlockTag) -> Web3Quantity:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns the number of uncles in a block from a block matching the given block number.
|
|
|
|
##
|
|
|
|
## quantityTag: integer of a block number, or the string "latest", "earliest" or "pending", see the default block parameter.
|
|
|
|
## Returns integer of uncles in this block.
|
2020-07-23 07:54:32 +00:00
|
|
|
let
|
2022-12-02 04:39:12 +00:00
|
|
|
header = chainDB.headerFromTag(quantityTag)
|
|
|
|
unclesCount = chainDB.getUnclesCount(header.ommersHash)
|
2024-10-02 03:56:39 +00:00
|
|
|
Web3Quantity(unclesCount)
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2023-12-27 00:48:53 +00:00
|
|
|
server.rpc("eth_getCode") do(data: Web3Address, quantityTag: BlockTag) -> seq[byte]:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns code at a given address.
|
|
|
|
##
|
|
|
|
## data: address
|
|
|
|
## quantityTag: integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.
|
|
|
|
## Returns the code from the given address.
|
2018-08-14 17:22:31 +00:00
|
|
|
let
|
2021-10-28 09:42:39 +00:00
|
|
|
accDB = stateDBFromTag(quantityTag)
|
2023-12-08 09:35:50 +00:00
|
|
|
address = data.ethAddr
|
2024-10-02 03:56:39 +00:00
|
|
|
accDB.getCode(address).bytes()
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
template sign(privateKey: PrivateKey, message: string): seq[byte] =
|
2020-07-23 07:54:32 +00:00
|
|
|
# message length encoded as ASCII representation of decimal
|
2018-08-22 21:15:26 +00:00
|
|
|
let msgData = "\x19Ethereum Signed Message:\n" & $message.len & message
|
2023-12-08 09:35:50 +00:00
|
|
|
@(sign(privateKey, msgData.toBytes()).toRaw())
|
2018-08-22 21:15:26 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
server.rpc("eth_sign") do(data: Web3Address, message: seq[byte]) -> seq[byte]:
|
2018-08-13 18:29:38 +00:00
|
|
|
## The sign method calculates an Ethereum specific signature with: sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))).
|
|
|
|
## By adding a prefix to the message makes the calculated signature recognisable as an Ethereum specific signature.
|
|
|
|
## This prevents misuse where a malicious DApp can sign arbitrary data (e.g. transaction) and use the signature to impersonate the victim.
|
|
|
|
## Note the address to sign with must be unlocked.
|
|
|
|
##
|
|
|
|
## data: address.
|
|
|
|
## message: message to sign.
|
|
|
|
## Returns signature.
|
2020-07-23 07:54:32 +00:00
|
|
|
let
|
2023-12-08 09:35:50 +00:00
|
|
|
address = data.ethAddr
|
2021-09-07 12:30:12 +00:00
|
|
|
acc = ctx.am.getAccount(address).tryGet()
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2020-07-23 07:54:32 +00:00
|
|
|
if not acc.unlocked:
|
|
|
|
raise newException(ValueError, "Account locked, please unlock it first")
|
2024-10-02 03:56:39 +00:00
|
|
|
sign(acc.privateKey, cast[string](message))
|
2020-07-23 15:30:42 +00:00
|
|
|
|
2024-03-21 01:05:22 +00:00
|
|
|
server.rpc("eth_signTransaction") do(data: TransactionArgs) -> seq[byte]:
|
2020-07-24 12:44:36 +00:00
|
|
|
## Signs a transaction that can be submitted to the network at a later time using with
|
|
|
|
## eth_sendRawTransaction
|
2020-07-23 15:30:42 +00:00
|
|
|
let
|
2024-03-21 01:05:22 +00:00
|
|
|
address = data.`from`.get(w3Address()).ethAddr
|
2021-09-07 12:30:12 +00:00
|
|
|
acc = ctx.am.getAccount(address).tryGet()
|
2020-07-23 15:30:42 +00:00
|
|
|
|
|
|
|
if not acc.unlocked:
|
|
|
|
raise newException(ValueError, "Account locked, please unlock it first")
|
|
|
|
|
|
|
|
let
|
2023-12-27 00:48:53 +00:00
|
|
|
accDB = stateDBFromTag(blockId("latest"))
|
2024-10-04 14:34:31 +00:00
|
|
|
tx = unsignedTx(data, chainDB, accDB.getNonce(address) + 1, com.chainId)
|
2022-12-02 04:39:12 +00:00
|
|
|
eip155 = com.isEIP155(com.syncCurrent)
|
2024-10-04 14:34:31 +00:00
|
|
|
signedTx = signTransaction(tx, acc.privateKey, eip155)
|
2023-12-08 09:35:50 +00:00
|
|
|
result = rlp.encode(signedTx)
|
2020-07-24 12:44:36 +00:00
|
|
|
|
2024-03-21 01:05:22 +00:00
|
|
|
server.rpc("eth_sendTransaction") do(data: TransactionArgs) -> Web3Hash:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Creates new message call transaction or a contract creation, if the data field contains code.
|
|
|
|
##
|
|
|
|
## obj: the transaction object.
|
|
|
|
## Returns the transaction hash, or the zero hash if the transaction is not yet available.
|
|
|
|
## Note: Use eth_getTransactionReceipt to get the contract address, after the transaction was mined, when you created a contract.
|
2020-07-24 12:44:36 +00:00
|
|
|
let
|
2024-03-21 01:05:22 +00:00
|
|
|
address = data.`from`.get(w3Address()).ethAddr
|
2021-09-07 12:30:12 +00:00
|
|
|
acc = ctx.am.getAccount(address).tryGet()
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2020-07-24 12:44:36 +00:00
|
|
|
if not acc.unlocked:
|
|
|
|
raise newException(ValueError, "Account locked, please unlock it first")
|
|
|
|
|
|
|
|
let
|
2023-12-27 00:48:53 +00:00
|
|
|
accDB = stateDBFromTag(blockId("latest"))
|
2024-10-04 14:34:31 +00:00
|
|
|
tx = unsignedTx(data, chainDB, accDB.getNonce(address) + 1, com.chainId)
|
2022-12-02 04:39:12 +00:00
|
|
|
eip155 = com.isEIP155(com.syncCurrent)
|
2024-10-04 14:34:31 +00:00
|
|
|
signedTx = signTransaction(tx, acc.privateKey, eip155)
|
2024-05-15 03:07:59 +00:00
|
|
|
networkPayload =
|
|
|
|
if signedTx.txType == TxEip4844:
|
|
|
|
if data.blobs.isNone or data.commitments.isNone or data.proofs.isNone:
|
|
|
|
raise newException(ValueError, "EIP-4844 transaction needs blobs")
|
|
|
|
if data.blobs.get.len != signedTx.versionedHashes.len:
|
|
|
|
raise newException(ValueError, "Incorrect number of blobs")
|
|
|
|
if data.commitments.get.len != signedTx.versionedHashes.len:
|
|
|
|
raise newException(ValueError, "Incorrect number of commitments")
|
|
|
|
if data.proofs.get.len != signedTx.versionedHashes.len:
|
|
|
|
raise newException(ValueError, "Incorrect number of proofs")
|
|
|
|
NetworkPayload(
|
|
|
|
blobs: data.blobs.get.mapIt it.NetworkBlob,
|
|
|
|
commitments: data.commitments.get.mapIt eth_types.KzgCommitment(it),
|
|
|
|
proofs: data.proofs.get.mapIt eth_types.KzgProof(it))
|
|
|
|
else:
|
|
|
|
if data.blobs.isSome or data.commitments.isSome or data.proofs.isSome:
|
|
|
|
raise newException(ValueError, "Blobs require EIP-4844 transaction")
|
|
|
|
nil
|
|
|
|
pooledTx = PooledTransaction(tx: signedTx, networkPayload: networkPayload)
|
|
|
|
|
|
|
|
txPool.add(pooledTx)
|
2024-10-02 03:56:39 +00:00
|
|
|
rlpHash(signedTx).w3Hash
|
2020-07-24 12:44:36 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
server.rpc("eth_sendRawTransaction") do(txBytes: seq[byte]) -> Web3Hash:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Creates new message call transaction or a contract creation for signed transactions.
|
|
|
|
##
|
|
|
|
## data: the signed transaction data.
|
|
|
|
## Returns the transaction hash, or the zero hash if the transaction is not yet available.
|
|
|
|
## Note: Use eth_getTransactionReceipt to get the contract address, after the transaction was mined, when you created a contract.
|
2022-04-03 06:36:27 +00:00
|
|
|
let
|
2024-05-15 03:07:59 +00:00
|
|
|
pooledTx = decodePooledTx(txBytes)
|
|
|
|
txHash = rlpHash(pooledTx)
|
2022-04-03 06:36:27 +00:00
|
|
|
|
2024-05-15 03:07:59 +00:00
|
|
|
txPool.add(pooledTx)
|
2023-10-20 08:30:05 +00:00
|
|
|
let res = txPool.inPoolAndReason(txHash)
|
|
|
|
if res.isErr:
|
|
|
|
raise newException(ValueError, res.error)
|
2024-10-02 03:56:39 +00:00
|
|
|
txHash.w3Hash
|
2018-11-20 17:31:17 +00:00
|
|
|
|
2024-04-16 12:52:07 +00:00
|
|
|
server.rpc("eth_call") do(args: TransactionArgs, quantityTag: BlockTag) -> seq[byte]:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Executes a new message call immediately without creating a transaction on the block chain.
|
|
|
|
##
|
|
|
|
## call: the transaction call object.
|
|
|
|
## quantityTag: integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.
|
|
|
|
## Returns the return value of executed contract.
|
2020-07-29 05:42:32 +00:00
|
|
|
let
|
2022-12-02 04:39:12 +00:00
|
|
|
header = headerFromTag(chainDB, quantityTag)
|
2024-06-07 08:24:32 +00:00
|
|
|
res = rpcCallEvm(args, header, com).valueOr:
|
|
|
|
raise newException(ValueError, "rpcCallEvm error: " & $error.code)
|
2024-10-02 03:56:39 +00:00
|
|
|
res.output
|
2019-01-06 19:19:48 +00:00
|
|
|
|
2024-04-16 12:52:07 +00:00
|
|
|
server.rpc("eth_estimateGas") do(args: TransactionArgs) -> Web3Quantity:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Generates and returns an estimate of how much gas is necessary to allow the transaction to complete.
|
|
|
|
## The transaction will not be added to the blockchain. Note that the estimate may be significantly more than
|
|
|
|
## the amount of gas actually used by the transaction, for a variety of reasons including EVM mechanics and node performance.
|
2018-10-05 00:20:12 +00:00
|
|
|
##
|
2024-04-16 12:52:07 +00:00
|
|
|
## args: the transaction call object.
|
2018-08-13 18:29:38 +00:00
|
|
|
## quantityTag: integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.
|
|
|
|
## Returns the amount of gas used.
|
2018-11-27 18:21:28 +00:00
|
|
|
let
|
2024-01-13 01:41:57 +00:00
|
|
|
header = chainDB.headerFromTag(blockId("latest"))
|
2021-10-26 15:18:08 +00:00
|
|
|
# TODO: DEFAULT_RPC_GAS_CAP should configurable
|
2024-06-07 08:24:32 +00:00
|
|
|
gasUsed = rpcEstimateGas(args, header, com, DEFAULT_RPC_GAS_CAP).valueOr:
|
|
|
|
raise newException(ValueError, "rpcEstimateGas error: " & $error.code)
|
2024-10-02 03:56:39 +00:00
|
|
|
w3Qty(gasUsed)
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
server.rpc("eth_getBlockByHash") do(data: Web3Hash, fullTransactions: bool) -> BlockObject:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns information about a block by hash.
|
|
|
|
##
|
|
|
|
## data: Hash of a block.
|
|
|
|
## fullTransactions: If true it returns the full transaction objects, if false only the hashes of the transactions.
|
|
|
|
## Returns BlockObject or nil when no block was found.
|
2020-07-30 07:21:11 +00:00
|
|
|
var
|
|
|
|
header: BlockHeader
|
2023-12-08 09:35:50 +00:00
|
|
|
hash = data.ethHash
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2022-12-02 04:39:12 +00:00
|
|
|
if chainDB.getBlockHeader(hash, header):
|
2024-10-02 03:56:39 +00:00
|
|
|
populateBlockObject(header, chainDB, fullTransactions)
|
2022-01-24 13:08:33 +00:00
|
|
|
else:
|
2024-10-02 03:56:39 +00:00
|
|
|
nil
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2023-12-27 00:48:53 +00:00
|
|
|
server.rpc("eth_getBlockByNumber") do(quantityTag: BlockTag, fullTransactions: bool) -> BlockObject:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns information about a block by block number.
|
|
|
|
##
|
|
|
|
## quantityTag: integer of a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.
|
|
|
|
## fullTransactions: If true it returns the full transaction objects, if false only the hashes of the transactions.
|
|
|
|
## Returns BlockObject or nil when no block was found.
|
2020-07-30 07:21:11 +00:00
|
|
|
try:
|
2022-12-02 04:39:12 +00:00
|
|
|
let header = chainDB.headerFromTag(quantityTag)
|
2024-10-02 03:56:39 +00:00
|
|
|
populateBlockObject(header, chainDB, fullTransactions)
|
2023-02-14 20:27:17 +00:00
|
|
|
except CatchableError:
|
2024-10-02 03:56:39 +00:00
|
|
|
nil
|
2019-02-26 07:04:12 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
server.rpc("eth_getTransactionByHash") do(data: Web3Hash) -> TransactionObject:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns the information about a transaction requested by transaction hash.
|
|
|
|
##
|
|
|
|
## data: hash of a transaction.
|
|
|
|
## Returns requested transaction information.
|
2023-12-08 09:35:50 +00:00
|
|
|
let txHash = data.ethHash()
|
2023-10-20 08:30:05 +00:00
|
|
|
let res = txPool.getItem(txHash)
|
|
|
|
if res.isOk:
|
2023-12-08 09:35:50 +00:00
|
|
|
return populateTransactionObject(res.get().tx)
|
2023-10-20 08:30:05 +00:00
|
|
|
|
|
|
|
let txDetails = chainDB.getTransactionKey(txHash)
|
2020-07-30 07:21:11 +00:00
|
|
|
if txDetails.index < 0:
|
2023-12-08 09:35:50 +00:00
|
|
|
return nil
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2022-12-02 04:39:12 +00:00
|
|
|
let header = chainDB.getBlockHeader(txDetails.blockNumber)
|
2020-07-30 07:21:11 +00:00
|
|
|
var tx: Transaction
|
2024-06-29 05:43:17 +00:00
|
|
|
if chainDB.getTransactionByIndex(header.txRoot, uint16(txDetails.index), tx):
|
2024-06-14 07:31:08 +00:00
|
|
|
result = populateTransactionObject(tx, Opt.some(header), Opt.some(txDetails.index))
|
2018-07-31 17:18:43 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
server.rpc("eth_getTransactionByBlockHashAndIndex") do(data: Web3Hash, quantity: Web3Quantity) -> TransactionObject:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns information about a transaction by block hash and transaction index position.
|
|
|
|
##
|
|
|
|
## data: hash of a block.
|
|
|
|
## quantity: integer of the transaction index position.
|
|
|
|
## Returns requested transaction information.
|
2024-06-14 07:31:08 +00:00
|
|
|
let index = uint64(quantity)
|
2020-07-30 07:21:11 +00:00
|
|
|
var header: BlockHeader
|
2023-12-08 09:35:50 +00:00
|
|
|
if not chainDB.getBlockHeader(data.ethHash(), header):
|
|
|
|
return nil
|
2020-07-30 07:21:11 +00:00
|
|
|
|
|
|
|
var tx: Transaction
|
2024-06-29 05:43:17 +00:00
|
|
|
if chainDB.getTransactionByIndex(header.txRoot, uint16(index), tx):
|
2024-10-02 03:56:39 +00:00
|
|
|
populateTransactionObject(tx, Opt.some(header), Opt.some(index))
|
2023-12-08 09:35:50 +00:00
|
|
|
else:
|
2024-10-02 03:56:39 +00:00
|
|
|
nil
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2023-12-27 00:48:53 +00:00
|
|
|
server.rpc("eth_getTransactionByBlockNumberAndIndex") do(quantityTag: BlockTag, quantity: Web3Quantity) -> TransactionObject:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns information about a transaction by block number and transaction index position.
|
|
|
|
##
|
|
|
|
## quantityTag: a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.
|
|
|
|
## quantity: the transaction index position.
|
2018-08-17 19:06:43 +00:00
|
|
|
let
|
2022-12-02 04:39:12 +00:00
|
|
|
header = chainDB.headerFromTag(quantityTag)
|
2024-06-14 07:31:08 +00:00
|
|
|
index = uint64(quantity)
|
2018-12-10 16:27:12 +00:00
|
|
|
|
2020-07-30 07:21:11 +00:00
|
|
|
var tx: Transaction
|
2024-06-29 05:43:17 +00:00
|
|
|
if chainDB.getTransactionByIndex(header.txRoot, uint16(index), tx):
|
2024-10-02 03:56:39 +00:00
|
|
|
populateTransactionObject(tx, Opt.some(header), Opt.some(index))
|
2023-12-08 09:35:50 +00:00
|
|
|
else:
|
2024-10-02 03:56:39 +00:00
|
|
|
nil
|
2018-08-20 19:42:40 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
server.rpc("eth_getTransactionReceipt") do(data: Web3Hash) -> ReceiptObject:
|
2018-08-13 18:29:38 +00:00
|
|
|
## Returns the receipt of a transaction by transaction hash.
|
|
|
|
##
|
|
|
|
## data: hash of a transaction.
|
|
|
|
## Returns transaction receipt.
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
let txDetails = chainDB.getTransactionKey(data.ethHash())
|
2020-07-30 07:21:11 +00:00
|
|
|
if txDetails.index < 0:
|
2023-12-08 09:35:50 +00:00
|
|
|
return nil
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2022-12-02 04:39:12 +00:00
|
|
|
let header = chainDB.getBlockHeader(txDetails.blockNumber)
|
2020-07-30 07:21:11 +00:00
|
|
|
var tx: Transaction
|
2024-06-29 05:43:17 +00:00
|
|
|
if not chainDB.getTransactionByIndex(header.txRoot, uint16(txDetails.index), tx):
|
2023-12-08 09:35:50 +00:00
|
|
|
return nil
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2018-08-22 17:45:31 +00:00
|
|
|
var
|
2024-06-14 07:31:08 +00:00
|
|
|
idx = 0'u64
|
2018-11-28 15:04:57 +00:00
|
|
|
prevGasUsed = GasInt(0)
|
2018-12-31 03:27:02 +00:00
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
for receipt in chainDB.getReceipts(header.receiptsRoot):
|
2018-11-28 15:04:57 +00:00
|
|
|
let gasUsed = receipt.cumulativeGasUsed - prevGasUsed
|
|
|
|
prevGasUsed = receipt.cumulativeGasUsed
|
2018-08-20 19:42:40 +00:00
|
|
|
if idx == txDetails.index:
|
2023-12-08 09:35:50 +00:00
|
|
|
return populateReceipt(receipt, gasUsed, tx, txDetails.index, header)
|
2018-08-20 19:42:40 +00:00
|
|
|
idx.inc
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
server.rpc("eth_getUncleByBlockHashAndIndex") do(data: Web3Hash, quantity: Web3Quantity) -> BlockObject:
|
2018-10-05 00:20:12 +00:00
|
|
|
## Returns information about a uncle of a block by hash and uncle index position.
|
2018-08-13 18:29:38 +00:00
|
|
|
##
|
2018-08-20 19:52:09 +00:00
|
|
|
## data: hash of block.
|
2018-08-13 18:29:38 +00:00
|
|
|
## quantity: the uncle's index position.
|
|
|
|
## Returns BlockObject or nil when no block was found.
|
2024-06-14 07:31:08 +00:00
|
|
|
let index = uint64(quantity)
|
2020-07-30 07:21:11 +00:00
|
|
|
var header: BlockHeader
|
2023-12-08 09:35:50 +00:00
|
|
|
if not chainDB.getBlockHeader(data.ethHash(), header):
|
|
|
|
return nil
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2022-12-02 04:39:12 +00:00
|
|
|
let uncles = chainDB.getUncles(header.ommersHash)
|
2024-06-14 07:31:08 +00:00
|
|
|
if index < 0 or index >= uncles.len.uint64:
|
2023-12-08 09:35:50 +00:00
|
|
|
return nil
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
result = populateBlockObject(uncles[index], chainDB, false, true)
|
2024-06-14 05:10:00 +00:00
|
|
|
result.totalDifficulty = chainDB.getScore(header.blockHash).valueOr(0.u256)
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2023-12-27 00:48:53 +00:00
|
|
|
server.rpc("eth_getUncleByBlockNumberAndIndex") do(quantityTag: BlockTag, quantity: Web3Quantity) -> BlockObject:
|
2018-08-13 18:29:38 +00:00
|
|
|
# Returns information about a uncle of a block by number and uncle index position.
|
|
|
|
##
|
|
|
|
## quantityTag: a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.
|
|
|
|
## quantity: the uncle's index position.
|
|
|
|
## Returns BlockObject or nil when no block was found.
|
2018-08-20 20:06:26 +00:00
|
|
|
let
|
2024-06-14 07:31:08 +00:00
|
|
|
index = uint64(quantity)
|
2022-12-02 04:39:12 +00:00
|
|
|
header = chainDB.headerFromTag(quantityTag)
|
|
|
|
uncles = chainDB.getUncles(header.ommersHash)
|
2018-08-13 18:29:38 +00:00
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
if index < 0 or index >= uncles.len.uint64:
|
2023-12-08 09:35:50 +00:00
|
|
|
return nil
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2023-12-08 09:35:50 +00:00
|
|
|
result = populateBlockObject(uncles[index], chainDB, false, true)
|
2024-06-14 05:10:00 +00:00
|
|
|
result.totalDifficulty = chainDB.getScore(header.blockHash).valueOr(0.u256)
|
2020-07-30 07:21:11 +00:00
|
|
|
|
2022-06-29 15:44:08 +00:00
|
|
|
proc getLogsForBlock(
|
2023-08-04 11:10:09 +00:00
|
|
|
chain: CoreDbRef,
|
2022-06-29 15:44:08 +00:00
|
|
|
hash: Hash256,
|
|
|
|
header: BlockHeader,
|
2023-01-31 01:32:17 +00:00
|
|
|
opts: FilterOptions): seq[FilterLog]
|
2024-07-26 05:32:01 +00:00
|
|
|
{.gcsafe, raises: [RlpError,BlockNotFound].} =
|
2022-06-29 15:44:08 +00:00
|
|
|
if headerBloomFilter(header, opts.address, opts.topics):
|
|
|
|
let blockBody = chain.getBlockBody(hash)
|
2024-06-14 07:31:08 +00:00
|
|
|
let receipts = chain.getReceipts(header.receiptsRoot)
|
2022-06-29 15:44:08 +00:00
|
|
|
# Note: this will hit assertion error if number of block transactions
|
|
|
|
# do not match block receipts.
|
|
|
|
# Although this is fine as number of receipts should always match number
|
|
|
|
# of transactions
|
|
|
|
let logs = deriveLogs(header, blockBody.transactions, receipts)
|
|
|
|
let filteredLogs = filterLogs(logs, opts.address, opts.topics)
|
|
|
|
return filteredLogs
|
|
|
|
else:
|
|
|
|
return @[]
|
|
|
|
|
|
|
|
proc getLogsForRange(
|
2023-08-04 11:10:09 +00:00
|
|
|
chain: CoreDbRef,
|
2024-06-14 07:31:08 +00:00
|
|
|
start: common.BlockNumber,
|
|
|
|
finish: common.BlockNumber,
|
2023-01-31 01:32:17 +00:00
|
|
|
opts: FilterOptions): seq[FilterLog]
|
2024-07-26 05:32:01 +00:00
|
|
|
{.gcsafe, raises: [RlpError,BlockNotFound].} =
|
2022-06-29 15:44:08 +00:00
|
|
|
var logs = newSeq[FilterLog]()
|
|
|
|
var i = start
|
|
|
|
while i <= finish:
|
|
|
|
let res = chain.getBlockHeaderWithHash(i)
|
|
|
|
if res.isSome():
|
|
|
|
let (hash, header)= res.unsafeGet()
|
|
|
|
let filtered = chain.getLogsForBlock(header, hash, opts)
|
|
|
|
logs.add(filtered)
|
|
|
|
else:
|
|
|
|
#
|
|
|
|
return logs
|
|
|
|
i = i + 1
|
|
|
|
return logs
|
|
|
|
|
|
|
|
server.rpc("eth_getLogs") do(filterOptions: FilterOptions) -> seq[FilterLog]:
|
|
|
|
## filterOptions: settings for this filter.
|
|
|
|
## Returns a list of all logs matching a given filter object.
|
|
|
|
## TODO: Current implementation is pretty naive and not efficient
|
|
|
|
## as it requires to fetch all transactions and all receipts from database.
|
|
|
|
## Other clients (Geth):
|
|
|
|
## - Store logs related data in receipts.
|
|
|
|
## - Have separate indexes for Logs in given block
|
|
|
|
## Both of those changes require improvements to the way how we keep our data
|
|
|
|
## in Nimbus.
|
|
|
|
if filterOptions.blockHash.isSome():
|
2023-12-08 09:35:50 +00:00
|
|
|
let hash = ethHash filterOptions.blockHash.unsafeGet()
|
2022-12-02 04:39:12 +00:00
|
|
|
let header = chainDB.getBlockHeader(hash)
|
|
|
|
return getLogsForBlock(chainDB, hash, header, filterOptions)
|
2022-06-29 15:44:08 +00:00
|
|
|
else:
|
|
|
|
# TODO: do something smarter with tags. It would be the best if
|
|
|
|
# tag would be an enum (Earliest, Latest, Pending, Number), and all operations
|
|
|
|
# would operate on this enum instead of raw strings. This change would need
|
|
|
|
# to be done on every endpoint to be consistent.
|
2022-12-02 04:39:12 +00:00
|
|
|
let fromHeader = chainDB.headerFromTag(filterOptions.fromBlock)
|
2024-01-13 01:41:57 +00:00
|
|
|
let toHeader = chainDB.headerFromTag(filterOptions.toBlock)
|
2022-06-29 15:44:08 +00:00
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
# Note: if fromHeader.number > toHeader.number, no logs will be
|
2022-06-29 15:44:08 +00:00
|
|
|
# returned. This is consistent with, what other ethereum clients return
|
2022-12-02 04:39:12 +00:00
|
|
|
let logs = chainDB.getLogsForRange(
|
2024-06-14 07:31:08 +00:00
|
|
|
fromHeader.number,
|
|
|
|
toHeader.number,
|
2022-06-29 15:44:08 +00:00
|
|
|
filterOptions
|
|
|
|
)
|
|
|
|
return logs
|
|
|
|
|
2024-01-09 02:05:52 +00:00
|
|
|
server.rpc("eth_getProof") do(data: Web3Address, slots: seq[UInt256], quantityTag: BlockTag) -> ProofResponse:
|
|
|
|
## Returns information about an account and storage slots (if the account is a contract
|
|
|
|
## and the slots are requested) along with account and storage proofs which prove the
|
|
|
|
## existence of the values in the state.
|
|
|
|
## See spec here: https://eips.ethereum.org/EIPS/eip-1186
|
|
|
|
##
|
|
|
|
## data: address of the account.
|
|
|
|
## slots: integers of the positions in the storage to return with storage proofs.
|
|
|
|
## quantityTag: integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.
|
|
|
|
## Returns: the proof response containing the account, account proof and storage proof
|
|
|
|
|
|
|
|
let
|
|
|
|
accDB = stateDBFromTag(quantityTag)
|
|
|
|
address = data.ethAddr
|
2024-01-22 09:11:37 +00:00
|
|
|
|
|
|
|
getProof(accDB, address, slots)
|
2024-01-09 02:05:52 +00:00
|
|
|
|
2024-02-15 02:57:05 +00:00
|
|
|
server.rpc("eth_getBlockReceipts") do(quantityTag: BlockTag) -> Opt[seq[ReceiptObject]]:
|
2024-04-04 00:25:56 +00:00
|
|
|
## Returns the receipts of a block.
|
2024-01-24 11:04:59 +00:00
|
|
|
try:
|
|
|
|
let header = chainDB.headerFromTag(quantityTag)
|
|
|
|
var
|
|
|
|
prevGasUsed = GasInt(0)
|
|
|
|
recs: seq[ReceiptObject]
|
|
|
|
txs: seq[Transaction]
|
2024-06-14 07:31:08 +00:00
|
|
|
index = 0'u64
|
2024-01-24 11:04:59 +00:00
|
|
|
|
|
|
|
for tx in chainDB.getBlockTransactions(header):
|
|
|
|
txs.add tx
|
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
for receipt in chainDB.getReceipts(header.receiptsRoot):
|
2024-01-24 11:04:59 +00:00
|
|
|
let gasUsed = receipt.cumulativeGasUsed - prevGasUsed
|
|
|
|
prevGasUsed = receipt.cumulativeGasUsed
|
|
|
|
recs.add populateReceipt(receipt, gasUsed, txs[index], index, header)
|
|
|
|
inc index
|
|
|
|
|
2024-02-15 02:57:05 +00:00
|
|
|
return Opt.some(recs)
|
2024-01-24 11:04:59 +00:00
|
|
|
except CatchableError:
|
2024-02-15 02:57:05 +00:00
|
|
|
return Opt.none(seq[ReceiptObject])
|
2024-03-21 11:24:32 +00:00
|
|
|
|
|
|
|
server.rpc("eth_createAccessList") do(args: TransactionArgs, quantityTag: BlockTag) -> AccessListResult:
|
2024-04-04 00:25:56 +00:00
|
|
|
## Generates an access list for a transaction.
|
2024-03-21 11:24:32 +00:00
|
|
|
try:
|
|
|
|
let
|
|
|
|
header = chainDB.headerFromTag(quantityTag)
|
|
|
|
return createAccessList(header, com, args)
|
|
|
|
except CatchableError as exc:
|
|
|
|
return AccessListResult(
|
2024-06-14 07:31:08 +00:00
|
|
|
error: Opt.some("createAccessList error: " & exc.msg),
|
2024-03-21 11:24:32 +00:00
|
|
|
)
|
|
|
|
|
2024-04-04 00:25:56 +00:00
|
|
|
server.rpc("eth_blobBaseFee") do() -> Web3Quantity:
|
|
|
|
## Returns the base fee per blob gas in wei.
|
|
|
|
let header = chainDB.headerFromTag(blockId("latest"))
|
|
|
|
if header.blobGasUsed.isNone:
|
|
|
|
raise newException(ValueError, "blobGasUsed missing from latest header")
|
|
|
|
if header.excessBlobGas.isNone:
|
|
|
|
raise newException(ValueError, "excessBlobGas missing from latest header")
|
|
|
|
let blobBaseFee = getBlobBaseFee(header.excessBlobGas.get) * header.blobGasUsed.get.u256
|
|
|
|
if blobBaseFee > high(uint64).u256:
|
|
|
|
raise newException(ValueError, "blobBaseFee is bigger than uint64.max")
|
|
|
|
return w3Qty blobBaseFee.truncate(uint64)
|
|
|
|
|
2024-04-16 01:02:42 +00:00
|
|
|
server.rpc("eth_feeHistory") do(blockCount: Quantity,
|
|
|
|
newestBlock: BlockTag,
|
2024-06-14 07:31:08 +00:00
|
|
|
rewardPercentiles: Opt[seq[float64]]) -> FeeHistoryResult:
|
2024-04-16 01:02:42 +00:00
|
|
|
let
|
|
|
|
blocks = blockCount.uint64
|
|
|
|
percentiles = rewardPercentiles.get(newSeq[float64]())
|
|
|
|
res = feeHistory(oracle, blocks, newestBlock, percentiles)
|
|
|
|
if res.isErr:
|
|
|
|
raise newException(ValueError, res.error)
|
|
|
|
return res.get
|