eth_getBlock properly returns transactions
This commit is contained in:
parent
5d05c36791
commit
abcfe9f9e8
@ -22,7 +22,6 @@ use util::uint::*;
|
|||||||
use util::sha3::*;
|
use util::sha3::*;
|
||||||
use ethcore::client::*;
|
use ethcore::client::*;
|
||||||
use ethcore::views::*;
|
use ethcore::views::*;
|
||||||
use ethcore::transaction::Action;
|
|
||||||
use v1::traits::{Eth, EthFilter};
|
use v1::traits::{Eth, EthFilter};
|
||||||
use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, Transaction, OptionalValue};
|
use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, Transaction, OptionalValue};
|
||||||
|
|
||||||
@ -126,9 +125,10 @@ impl Eth for EthClient {
|
|||||||
|
|
||||||
fn block(&self, params: Params) -> Result<Value, Error> {
|
fn block(&self, params: Params) -> Result<Value, Error> {
|
||||||
match from_params::<(H256, bool)>(params) {
|
match from_params::<(H256, bool)>(params) {
|
||||||
Ok((hash, include_txs)) => match (self.client.block_header(&hash), self.client.block_total_difficulty(&hash)) {
|
Ok((hash, include_txs)) => match (self.client.block(&hash), self.client.block_total_difficulty(&hash)) {
|
||||||
(Some(bytes), Some(total_difficulty)) => {
|
(Some(bytes), Some(total_difficulty)) => {
|
||||||
let view = HeaderView::new(&bytes);
|
let block_view = BlockView::new(&bytes);
|
||||||
|
let view = block_view.header_view();
|
||||||
let block = Block {
|
let block = Block {
|
||||||
hash: OptionalValue::Value(view.sha3()),
|
hash: OptionalValue::Value(view.sha3()),
|
||||||
parent_hash: view.parent_hash(),
|
parent_hash: view.parent_hash(),
|
||||||
@ -148,9 +148,9 @@ impl Eth for EthClient {
|
|||||||
uncles: vec![],
|
uncles: vec![],
|
||||||
transactions: {
|
transactions: {
|
||||||
if include_txs {
|
if include_txs {
|
||||||
BlockTransactions::Hashes(vec![])
|
BlockTransactions::Full(block_view.localized_transactions().into_iter().map(From::from).collect())
|
||||||
} else {
|
} else {
|
||||||
BlockTransactions::Full(vec![])
|
BlockTransactions::Hashes(block_view.transaction_hashes())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
extra_data: Bytes::default()
|
extra_data: Bytes::default()
|
||||||
@ -166,22 +166,7 @@ impl Eth for EthClient {
|
|||||||
fn transaction_at(&self, params: Params) -> Result<Value, Error> {
|
fn transaction_at(&self, params: Params) -> Result<Value, Error> {
|
||||||
match from_params::<(H256,)>(params) {
|
match from_params::<(H256,)>(params) {
|
||||||
Ok((hash,)) => match self.client.transaction(&hash) {
|
Ok((hash,)) => match self.client.transaction(&hash) {
|
||||||
Some(t) => to_value(&Transaction {
|
Some(t) => to_value(&Transaction::from(t)),
|
||||||
hash: t.hash(),
|
|
||||||
nonce: t.nonce,
|
|
||||||
block_hash: OptionalValue::Value(t.block_hash.clone()),
|
|
||||||
block_number: OptionalValue::Value(U256::from(t.block_number)),
|
|
||||||
transaction_index: OptionalValue::Value(U256::from(t.transaction_index)),
|
|
||||||
from: t.sender().unwrap(),
|
|
||||||
to: match t.action {
|
|
||||||
Action::Create => OptionalValue::Null,
|
|
||||||
Action::Call(ref address) => OptionalValue::Value(address.clone())
|
|
||||||
},
|
|
||||||
value: t.value,
|
|
||||||
gas_price: t.gas_price,
|
|
||||||
gas: t.gas,
|
|
||||||
input: Bytes::new(t.data.clone())
|
|
||||||
}),
|
|
||||||
None => Ok(Value::Null)
|
None => Ok(Value::Null)
|
||||||
},
|
},
|
||||||
Err(err) => Err(err)
|
Err(err) => Err(err)
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
use util::hash::*;
|
use util::hash::*;
|
||||||
use util::uint::*;
|
use util::uint::*;
|
||||||
|
use ethcore::transaction::{LocalizedTransaction, Action};
|
||||||
use v1::types::{Bytes, OptionalValue};
|
use v1::types::{Bytes, OptionalValue};
|
||||||
|
|
||||||
#[derive(Debug, Default, Serialize)]
|
#[derive(Debug, Default, Serialize)]
|
||||||
@ -37,6 +38,27 @@ pub struct Transaction {
|
|||||||
pub input: Bytes
|
pub input: Bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<LocalizedTransaction> for Transaction {
|
||||||
|
fn from(t: LocalizedTransaction) -> Transaction {
|
||||||
|
Transaction {
|
||||||
|
hash: t.hash(),
|
||||||
|
nonce: t.nonce,
|
||||||
|
block_hash: OptionalValue::Value(t.block_hash.clone()),
|
||||||
|
block_number: OptionalValue::Value(U256::from(t.block_number)),
|
||||||
|
transaction_index: OptionalValue::Value(U256::from(t.transaction_index)),
|
||||||
|
from: t.sender().unwrap(),
|
||||||
|
to: match t.action {
|
||||||
|
Action::Create => OptionalValue::Null,
|
||||||
|
Action::Call(ref address) => OptionalValue::Value(address.clone())
|
||||||
|
},
|
||||||
|
value: t.value,
|
||||||
|
gas_price: t.gas_price,
|
||||||
|
gas: t.gas,
|
||||||
|
input: Bytes::new(t.data.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
Loading…
Reference in New Issue
Block a user