client implementation of transaction receipt

This commit is contained in:
debris 2016-03-20 18:44:57 +01:00
parent 2a3e695f8a
commit 52e9801721
5 changed files with 49 additions and 13 deletions

View File

@ -39,7 +39,7 @@ use blockchain::{BlockChain, BlockProvider, TreeRoute, ImportRoute};
use client::{BlockId, TransactionId, ClientConfig, BlockChainClient};
use env_info::EnvInfo;
use executive::{Executive, Executed};
use receipt::Receipt;
use receipt::LocalizedReceipt;
pub use blockchain::CacheSize as BlockChainCacheSize;
/// General block status
@ -549,8 +549,40 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
self.transaction_address(id).and_then(|address| self.chain.transaction(&address))
}
fn transaction_receipt(&self, id: TransactionId) -> Option<Receipt> {
self.transaction_address(id).and_then(|address| self.chain.transaction_receipt(&address))
fn transaction_receipt(&self, id: TransactionId) -> Option<LocalizedReceipt> {
self.transaction_address(id).and_then(|address| {
let t = self.chain.block(&address.block_hash)
.and_then(|block| BlockView::new(&block).localized_transaction_at(address.index));
match (t, self.chain.transaction_receipt(&address)) {
(Some(tx), Some(receipt)) => {
let block_hash = tx.block_hash.clone();
let block_number = tx.block_number.clone();
let transaction_hash = tx.hash();
let transaction_index = tx.transaction_index;
Some(LocalizedReceipt {
transaction_hash: tx.hash(),
transaction_index: tx.transaction_index,
block_hash: tx.block_hash,
block_number: tx.block_number,
// TODO: to fix this, query all previous transaction receipts and retrieve their gas usage
cumulative_gas_used: receipt.gas_used,
gas_used: receipt.gas_used,
// TODO: to fix this, store created contract address in db
contract_address: None,
logs: receipt.logs.into_iter().enumerate().map(|(i, log)| LocalizedLogEntry {
entry: log,
block_hash: block_hash.clone(),
block_number: block_number,
transaction_hash: transaction_hash.clone(),
transaction_index: transaction_index,
log_index: i
}).collect()
})
},
_ => None
}
})
}
fn tree_route(&self, from: &H256, to: &H256) -> Option<TreeRoute> {
@ -635,7 +667,7 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
.map(|(i, log)| LocalizedLogEntry {
entry: log,
block_hash: hash.clone(),
block_number: number as usize,
block_number: number,
transaction_hash: hashes.get(index).cloned().unwrap_or_else(H256::new),
transaction_index: index,
log_index: log_index + i

View File

@ -39,7 +39,7 @@ use transaction::{LocalizedTransaction, SignedTransaction};
use log_entry::LocalizedLogEntry;
use filter::Filter;
use error::{ImportResult, Error};
use receipt::Receipt;
use receipt::LocalizedReceipt;
/// Blockchain database client. Owns and manages a blockchain and a block queue.
pub trait BlockChainClient : Sync + Send {
@ -78,7 +78,7 @@ pub trait BlockChainClient : Sync + Send {
fn transaction(&self, id: TransactionId) -> Option<LocalizedTransaction>;
/// Get transaction receipt with given hash.
fn transaction_receipt(&self, id: TransactionId) -> Option<Receipt>;
fn transaction_receipt(&self, id: TransactionId) -> Option<LocalizedReceipt>;
/// Get a tree route between `from` and `to`.
/// See `BlockChain::tree_route`.

View File

@ -23,7 +23,7 @@ use client::{BlockChainClient, BlockChainInfo, BlockStatus, BlockId, Transaction
use header::{Header as BlockHeader, BlockNumber};
use filter::Filter;
use log_entry::LocalizedLogEntry;
use receipt::Receipt;
use receipt::{Receipt, LocalizedReceipt};
use extras::BlockReceipts;
use error::{ImportResult};
@ -224,7 +224,7 @@ impl BlockChainClient for TestBlockChainClient {
unimplemented!();
}
fn transaction_receipt(&self, _id: TransactionId) -> Option<Receipt> {
fn transaction_receipt(&self, _id: TransactionId) -> Option<LocalizedReceipt> {
unimplemented!();
}

View File

@ -18,6 +18,7 @@
use util::*;
use basic_types::LogBloom;
use header::BlockNumber;
/// A record of execution for a `LOG` operation.
#[derive(Default, Debug, Clone, PartialEq, Eq)]
@ -84,7 +85,7 @@ pub struct LocalizedLogEntry {
/// Block in which this log was created.
pub block_hash: H256,
/// Block number.
pub block_number: usize,
pub block_number: BlockNumber,
/// Hash of transaction in which this log was created.
pub transaction_hash: H256,
/// Index of transaction within block.

View File

@ -31,7 +31,7 @@ use ethcore::ethereum::Ethash;
use ethcore::ethereum::denominations::shannon;
use ethcore::transaction::Transaction as EthTransaction;
use v1::traits::{Eth, EthFilter};
use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, TransactionRequest, OptionalValue, Index, Filter, Log};
use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, TransactionRequest, OptionalValue, Index, Filter, Log, Receipt};
use v1::helpers::{PollFilter, PollManager, ExternalMinerService, ExternalMiner};
use util::keys::store::AccountProvider;
@ -294,9 +294,12 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
}
fn transaction_receipt(&self, params: Params) -> Result<Value, Error> {
unimplemented!();
//from_params::<(H256,)>(params)
//.and_then(|(hash,)| self.transaction_receipt(TransactionId::Hash(hash)))
from_params::<(H256,)>(params)
.and_then(|(hash,)| {
let client = take_weak!(self.client);
let receipt = client.transaction_receipt(TransactionId::Hash(hash));
to_value(&receipt.map(Receipt::from))
})
}
fn uncle_by_block_hash_and_index(&self, params: Params) -> Result<Value, Error> {