crate::ix!();
#[derive(Default)]
pub struct BlockHeaderAndShortTxIDs {
pub shorttxidk0: RefCell<u64>,
pub shorttxidk1: RefCell<u64>,
pub nonce: u64,
pub shorttxids: Vec<u64>,
pub prefilledtxn: Vec<PrefilledTransaction>,
pub header: BlockHeader,
}
unsafe impl Send for BlockHeaderAndShortTxIDs {}
unsafe impl Sync for BlockHeaderAndShortTxIDs {}
const SHORTTXIDS_LENGTH: i32 = 6;
lazy_static!{
}
impl BlockHeaderAndShortTxIDs {
pub fn block_tx_count(&self) -> usize {
self.shorttxids.len() + self.prefilledtxn.len()
}
pub fn new(
block: Amo<Block>,
usewtxid: bool) -> Self {
todo!();
}
pub fn fill_short_tx_id_selector(&self) {
let mut stream: DataStream
= DataStream::new(SER_NETWORK, PROTOCOL_VERSION);
stream.stream(&self.header);
stream.stream(&self.nonce);
let mut hasher = Sha256::default();
hasher.write_from_iterator(
stream.begin(),
stream.size()
);
let mut shorttxidhash = u256::default();
hasher.finalize(
unsafe {
std::slice::from_raw_parts(
shorttxidhash.blob.begin(),
SHA256_OUTPUT_SIZE
).try_into().unwrap()
}
);
*self.shorttxidk0.borrow_mut() = shorttxidhash.blob.get_u64(0);
*self.shorttxidk1.borrow_mut() = shorttxidhash.blob.get_u64(1);
}
pub fn get_shortid(&self, txhash: &u256) -> u64 {
const_assert![SHORTTXIDS_LENGTH == 6];
sip_hash_uint256(
*self.shorttxidk0.borrow(),
*self.shorttxidk1.borrow(),
txhash)
& 0xffffffffffff
}
}