transaction by block number and index

This commit is contained in:
debris
2016-02-10 22:36:59 +01:00
parent df0fa06e8a
commit 93975be5e3
4 changed files with 40 additions and 5 deletions

View File

@@ -37,15 +37,21 @@ use extras::TransactionAddress;
pub use blockchain::TreeRoute;
/// Uniquely identifies block.
#[derive(Debug, PartialEq)]
pub enum BlockId {
/// Block's sha3.
/// Querying by hash is always faster.
Hash(H256),
/// Block number within canon blockchain.
Number(BlockNumber)
Number(BlockNumber),
/// Earliest block (genesis).
Earliest,
/// Latest mined block.
Latest
}
/// Uniquely identifies transaction.
#[derive(Debug, PartialEq)]
pub enum TransactionId {
/// Transaction's sha3.
Hash(H256),
@@ -347,7 +353,9 @@ impl Client {
fn block_hash(&self, id: BlockId) -> Option<H256> {
match id {
BlockId::Hash(hash) => Some(hash),
BlockId::Number(number) => self.chain.read().unwrap().block_hash(number)
BlockId::Number(number) => self.chain.read().unwrap().block_hash(number),
BlockId::Earliest => self.chain.read().unwrap().block_hash(0),
BlockId::Latest => Some(self.chain.read().unwrap().best_block_hash())
}
}
}