client implementation of transaction receipt
This commit is contained in:
parent
85fa07728c
commit
04082d1514
@ -39,7 +39,7 @@ use blockchain::{BlockChain, BlockProvider, TreeRoute, ImportRoute};
|
|||||||
use client::{BlockId, TransactionId, ClientConfig, BlockChainClient};
|
use client::{BlockId, TransactionId, ClientConfig, BlockChainClient};
|
||||||
use env_info::EnvInfo;
|
use env_info::EnvInfo;
|
||||||
use executive::{Executive, Executed};
|
use executive::{Executive, Executed};
|
||||||
use receipt::Receipt;
|
use receipt::LocalizedReceipt;
|
||||||
pub use blockchain::CacheSize as BlockChainCacheSize;
|
pub use blockchain::CacheSize as BlockChainCacheSize;
|
||||||
|
|
||||||
/// General block status
|
/// General block status
|
||||||
@ -548,8 +548,40 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
|
|||||||
self.transaction_address(id).and_then(|address| self.chain.transaction(&address))
|
self.transaction_address(id).and_then(|address| self.chain.transaction(&address))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transaction_receipt(&self, id: TransactionId) -> Option<Receipt> {
|
fn transaction_receipt(&self, id: TransactionId) -> Option<LocalizedReceipt> {
|
||||||
self.transaction_address(id).and_then(|address| self.chain.transaction_receipt(&address))
|
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> {
|
fn tree_route(&self, from: &H256, to: &H256) -> Option<TreeRoute> {
|
||||||
@ -634,7 +666,7 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
|
|||||||
.map(|(i, log)| LocalizedLogEntry {
|
.map(|(i, log)| LocalizedLogEntry {
|
||||||
entry: log,
|
entry: log,
|
||||||
block_hash: hash.clone(),
|
block_hash: hash.clone(),
|
||||||
block_number: number as usize,
|
block_number: number,
|
||||||
transaction_hash: hashes.get(index).cloned().unwrap_or_else(H256::new),
|
transaction_hash: hashes.get(index).cloned().unwrap_or_else(H256::new),
|
||||||
transaction_index: index,
|
transaction_index: index,
|
||||||
log_index: log_index + i
|
log_index: log_index + i
|
||||||
|
@ -39,7 +39,7 @@ use transaction::{LocalizedTransaction, SignedTransaction};
|
|||||||
use log_entry::LocalizedLogEntry;
|
use log_entry::LocalizedLogEntry;
|
||||||
use filter::Filter;
|
use filter::Filter;
|
||||||
use error::{ImportResult, Error};
|
use error::{ImportResult, Error};
|
||||||
use receipt::Receipt;
|
use receipt::LocalizedReceipt;
|
||||||
|
|
||||||
/// Blockchain database client. Owns and manages a blockchain and a block queue.
|
/// Blockchain database client. Owns and manages a blockchain and a block queue.
|
||||||
pub trait BlockChainClient : Sync + Send {
|
pub trait BlockChainClient : Sync + Send {
|
||||||
@ -78,7 +78,7 @@ pub trait BlockChainClient : Sync + Send {
|
|||||||
fn transaction(&self, id: TransactionId) -> Option<LocalizedTransaction>;
|
fn transaction(&self, id: TransactionId) -> Option<LocalizedTransaction>;
|
||||||
|
|
||||||
/// Get transaction receipt with given hash.
|
/// 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`.
|
/// Get a tree route between `from` and `to`.
|
||||||
/// See `BlockChain::tree_route`.
|
/// See `BlockChain::tree_route`.
|
||||||
|
@ -23,7 +23,7 @@ use client::{BlockChainClient, BlockChainInfo, BlockStatus, BlockId, Transaction
|
|||||||
use header::{Header as BlockHeader, BlockNumber};
|
use header::{Header as BlockHeader, BlockNumber};
|
||||||
use filter::Filter;
|
use filter::Filter;
|
||||||
use log_entry::LocalizedLogEntry;
|
use log_entry::LocalizedLogEntry;
|
||||||
use receipt::Receipt;
|
use receipt::{Receipt, LocalizedReceipt};
|
||||||
use extras::BlockReceipts;
|
use extras::BlockReceipts;
|
||||||
use error::{ImportResult};
|
use error::{ImportResult};
|
||||||
|
|
||||||
@ -224,7 +224,7 @@ impl BlockChainClient for TestBlockChainClient {
|
|||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transaction_receipt(&self, _id: TransactionId) -> Option<Receipt> {
|
fn transaction_receipt(&self, _id: TransactionId) -> Option<LocalizedReceipt> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use basic_types::LogBloom;
|
use basic_types::LogBloom;
|
||||||
|
use header::BlockNumber;
|
||||||
|
|
||||||
/// A record of execution for a `LOG` operation.
|
/// A record of execution for a `LOG` operation.
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
||||||
@ -84,7 +85,7 @@ pub struct LocalizedLogEntry {
|
|||||||
/// Block in which this log was created.
|
/// Block in which this log was created.
|
||||||
pub block_hash: H256,
|
pub block_hash: H256,
|
||||||
/// Block number.
|
/// Block number.
|
||||||
pub block_number: usize,
|
pub block_number: BlockNumber,
|
||||||
/// Hash of transaction in which this log was created.
|
/// Hash of transaction in which this log was created.
|
||||||
pub transaction_hash: H256,
|
pub transaction_hash: H256,
|
||||||
/// Index of transaction within block.
|
/// Index of transaction within block.
|
||||||
|
@ -31,7 +31,7 @@ use ethcore::ethereum::Ethash;
|
|||||||
use ethcore::ethereum::denominations::shannon;
|
use ethcore::ethereum::denominations::shannon;
|
||||||
use ethcore::transaction::Transaction as EthTransaction;
|
use ethcore::transaction::Transaction as EthTransaction;
|
||||||
use v1::traits::{Eth, EthFilter};
|
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 v1::helpers::{PollFilter, PollManager, ExternalMinerService, ExternalMiner};
|
||||||
use util::keys::store::AccountProvider;
|
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> {
|
fn transaction_receipt(&self, params: Params) -> Result<Value, Error> {
|
||||||
unimplemented!();
|
from_params::<(H256,)>(params)
|
||||||
//from_params::<(H256,)>(params)
|
.and_then(|(hash,)| {
|
||||||
//.and_then(|(hash,)| self.transaction_receipt(TransactionId::Hash(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> {
|
fn uncle_by_block_hash_and_index(&self, params: Params) -> Result<Value, Error> {
|
||||||
|
Loading…
Reference in New Issue
Block a user