Add a Block::coinbase_height() method.
This commit is contained in:
parent
56d7391f6d
commit
c4d72177c2
|
@ -18,6 +18,7 @@ use crate::note_commitment_tree::SaplingNoteTreeRootHash;
|
||||||
use crate::serialization::{ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize};
|
use crate::serialization::{ReadZcashExt, SerializationError, ZcashDeserialize, ZcashSerialize};
|
||||||
use crate::sha256d_writer::Sha256dWriter;
|
use crate::sha256d_writer::Sha256dWriter;
|
||||||
use crate::transaction::Transaction;
|
use crate::transaction::Transaction;
|
||||||
|
use crate::types::BlockHeight;
|
||||||
|
|
||||||
/// A SHA-256d hash of a BlockHeader.
|
/// A SHA-256d hash of a BlockHeader.
|
||||||
///
|
///
|
||||||
|
@ -163,6 +164,20 @@ pub struct Block {
|
||||||
pub transactions: Vec<Transaction>,
|
pub transactions: Vec<Transaction>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Block {
|
||||||
|
/// Return the block height reported in the coinbase transaction, if any.
|
||||||
|
pub fn coinbase_height(&self) -> Option<BlockHeight> {
|
||||||
|
use crate::transaction::TransparentInput;
|
||||||
|
self.transactions
|
||||||
|
.get(0)
|
||||||
|
.and_then(|tx| tx.inputs().next())
|
||||||
|
.and_then(|input| match input {
|
||||||
|
TransparentInput::Coinbase { ref height, .. } => Some(*height),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a Block> for BlockHeaderHash {
|
impl<'a> From<&'a Block> for BlockHeaderHash {
|
||||||
fn from(block: &'a Block) -> BlockHeaderHash {
|
fn from(block: &'a Block) -> BlockHeaderHash {
|
||||||
(&block.header).into()
|
(&block.header).into()
|
||||||
|
|
Loading…
Reference in New Issue