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

Function eth_get_balance_by_block

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

Source from the content-addressed store, hash-verified

81}
82
83pub(crate) fn eth_get_balance_by_block(module: &mut RpcModule<Context>) -> Result<()> {
84 module.register_async_method(
85 "eth_getBalanceByBlock",
86 move |params, blockchain| async move {
87 let mut seq = params.sequence();
88 let account = seq.next::<Account>()?;
89 let block = seq.next::<String>()?.clone();
90 let block_number = blockchain
91 .lock()
92 .await
93 .parse_block_number(&block)
94 .map_err(|e| JsonRpseeError::Custom(e.to_string()))?;
95
96 let balance = blockchain
97 .lock()
98 .await
99 .accounts
100 .get_account_balance_by_block(&account, &block_number)
101 .map_err(|e| Error::Custom(e.to_string()))?;
102
103 Ok(to_hex(balance))
104 },
105 )?;
106
107 Ok(())
108}
109
110pub(crate) fn eth_send_transaction(module: &mut RpcModule<Context>) -> Result<()> {
111 module.register_async_method(

Callers 1

serveFunction · 0.85

Calls 3

to_hexFunction · 0.85
parse_block_numberMethod · 0.80

Tested by

no test coverage detected