Merge rust-bitcoin/rust-bitcoin#515: Add Inventory::network_hash() method
3d524e06e4
Add Inventory::network_hash() method (Steven Roose) Pull request description: I'm not positive we won't ever had inv items that are not `sha256d::Hash`, though. I would expect them to stay like that, but we never know. Would accept that as a reasonable objection against this helper. ACKs for top commit: apoelstra: ACK3d524e06e4
tcharding: ACK3d524e06e4
Tree-SHA512: 97d64b08ff99dbec2d907bdb98aa41ede4a15b988551ad8dd87a10ac5c9750ae4d516bb558c1e4f2171612777355c2baf1ffbe671cb92320a1af64d73bd150dd
This commit is contained in:
commit
3795f60fa8
|
@ -42,6 +42,24 @@ pub enum Inventory {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Inventory {
|
||||||
|
/// Return the item value represented as a SHA256-d hash.
|
||||||
|
///
|
||||||
|
/// Returns [None] only for [Inventory::Error].
|
||||||
|
pub fn network_hash(&self) -> Option<[u8; 32]> {
|
||||||
|
match self {
|
||||||
|
Inventory::Error => None,
|
||||||
|
Inventory::Transaction(t) => Some(t.to_byte_array()),
|
||||||
|
Inventory::Block(b) => Some(b.to_byte_array()),
|
||||||
|
Inventory::CompactBlock(b) => Some(b.to_byte_array()),
|
||||||
|
Inventory::WTx(t) => Some(t.to_byte_array()),
|
||||||
|
Inventory::WitnessTransaction(t) => Some(t.to_byte_array()),
|
||||||
|
Inventory::WitnessBlock(b) => Some(b.to_byte_array()),
|
||||||
|
Inventory::Unknown { hash, .. } => Some(*hash),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Encodable for Inventory {
|
impl Encodable for Inventory {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn consensus_encode<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
|
fn consensus_encode<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
|
||||||
|
|
Loading…
Reference in New Issue