mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-28 00:29:58 -07:00
brk: first commit
This commit is contained in:
34
_src/structs/txout_index.rs
Normal file
34
_src/structs/txout_index.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use allocative::Allocative;
|
||||
use bincode::{Decode, Encode};
|
||||
use snkrj::{direct_repr, Storable, UnsizedStorable};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Encode, Decode, Allocative)]
|
||||
pub struct TxoutIndex {
|
||||
pub tx_index: u32,
|
||||
pub vout: u16,
|
||||
}
|
||||
direct_repr!(TxoutIndex);
|
||||
|
||||
const SHIFT: u64 = 16;
|
||||
const AND: u64 = (1 << SHIFT) - 1;
|
||||
|
||||
impl TxoutIndex {
|
||||
#[inline(always)]
|
||||
pub fn new(tx_index: u32, vout: u16) -> Self {
|
||||
Self { tx_index, vout }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn as_u64(&self) -> u64 {
|
||||
((self.tx_index as u64) << SHIFT) + self.vout as u64
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for TxoutIndex {
|
||||
fn from(value: u64) -> Self {
|
||||
Self {
|
||||
tx_index: (value >> SHIFT) as u32,
|
||||
vout: (value & AND) as u16,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user