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

Function eth_get_code

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

Source from the content-addressed store, hash-verified

164}
165
166pub(crate) fn eth_get_code(module: &mut RpcModule<Context>) -> Result<()> {
167 module.register_async_method("eth_getCode", move |params, blockchain| async move {
168 let mut seq = params.sequence();
169 let address = seq.next::<Account>()?;
170
171 // TODO(ddimaria): lookup code by block number
172 // let _block = seq.next::<BlockNumber>()?;
173 let block = seq.next::<String>()?.clone();
174 let block_number = blockchain
175 .lock()
176 .await
177 .parse_block_number(&block)
178 .map_err(|e| JsonRpseeError::Custom(e.to_string()))?;
179
180 let code_hash = blockchain
181 .lock()
182 .await
183 .accounts
184 .get_account(&address)
185 .map_err(|e| Error::Custom(e.to_string()))?
186 .code_hash
187 .ok_or_else(|| {
188 JsonRpseeError::Custom(format!("missing code hash for block {:?}", block_number))
189 })?;
190
191 Ok(code_hash)
192 })?;
193
194 Ok(())
195}
196
197#[cfg(test)]
198pub mod tests {

Callers 1

serveFunction · 0.85

Calls 2

parse_block_numberMethod · 0.80
get_accountMethod · 0.80

Tested by

no test coverage detected