(module: &mut RpcModule<Context>)
| 164 | } |
| 165 | |
| 166 | pub(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)] |
| 198 | pub mod tests { |
no test coverage detected