jsonrpc eth_getCode method

This commit is contained in:
debris
2016-02-08 10:58:08 +01:00
parent 4116bdd8fd
commit 3adfebdc20
7 changed files with 127 additions and 2 deletions

View File

@@ -23,7 +23,7 @@ use util::sha3::*;
use ethcore::client::*;
use ethcore::views::*;
use v1::traits::{Eth, EthFilter};
use v1::types::{Block, SyncStatus};
use v1::types::{Block, BlockNumber, Bytes, SyncStatus};
/// Eth rpc implementation.
pub struct EthClient {
@@ -115,6 +115,14 @@ impl Eth for EthClient {
}
}
// TODO: do not ignore block number param
fn code_at(&self, params: Params) -> Result<Value, Error> {
match from_params::<(Address, BlockNumber)>(params) {
Ok((address, _block_number)) => to_value(&Bytes::new(self.client.code(&address).unwrap_or_else(|| vec![]))),
Err(err) => Err(err)
}
}
fn block(&self, params: Params) -> Result<Value, Error> {
match from_params::<(H256, bool)>(params) {
Ok((hash, _include_txs)) => match (self.client.block_header(&hash), self.client.block_total_difficulty(&hash)) {