MCPcopy Create free account
hub / github.com/ddimaria/rust-blockchain-tutorial / eth_get_balance

Function eth_get_balance

chain/src/method.rs:43–64  ·  view source on GitHub ↗
(module: &mut RpcModule<Context>)

Source from the content-addressed store, hash-verified

41}
42
43pub(crate) fn eth_get_balance(module: &mut RpcModule<Context>) -> Result<()> {
44 module.register_async_method("eth_getBalance", move |params, blockchain| async move {
45 let key = params.one::<Account>()?;
46 let block = blockchain
47 .lock()
48 .await
49 .get_current_block()
50 .map_err(|e| JsonRpseeError::Custom(e.to_string()))?
51 .number;
52
53 let balance = blockchain
54 .lock()
55 .await
56 .accounts
57 .get_account_balance_by_block(&key, &BlockNumber(block))
58 .map_err(|e| Error::Custom(e.to_string()))?;
59
60 Ok(to_hex(balance))
61 })?;
62
63 Ok(())
64}
65
66pub(crate) fn eth_get_transaction_count(module: &mut RpcModule<Context>) -> Result<()> {
67 module.register_async_method("eth_getTransactionCount", |params, blockchain| async move {

Callers 2

serveFunction · 0.85
gets_an_account_balanceFunction · 0.85

Calls 4

BlockNumberClass · 0.85
to_hexFunction · 0.85
get_current_blockMethod · 0.80

Tested by

no test coverage detected