2023-03-01 11:09:08 +01:00
|
|
|
#[allow(unused_macros)]
|
|
|
|
macro_rules! h {
|
|
|
|
($index:literal) => {{
|
|
|
|
bitcoin::hashes::Hash::hash($index.as_bytes())
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2023-04-20 15:29:20 +08:00
|
|
|
#[allow(unused_macros)]
|
|
|
|
macro_rules! local_chain {
|
|
|
|
[ $(($height:expr, $block_hash:expr)), * ] => {{
|
|
|
|
#[allow(unused_mut)]
|
2023-07-19 17:42:52 +08:00
|
|
|
bdk_chain::local_chain::LocalChain::from_blocks([$(($height, $block_hash).into()),*].into_iter().collect())
|
2023-04-20 15:29:20 +08:00
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2023-03-01 11:09:08 +01:00
|
|
|
#[allow(unused_macros)]
|
2023-07-19 17:42:52 +08:00
|
|
|
macro_rules! chain_update {
|
|
|
|
[ $(($height:expr, $hash:expr)), * ] => {{
|
2023-03-01 11:09:08 +01:00
|
|
|
#[allow(unused_mut)]
|
2023-07-19 17:42:52 +08:00
|
|
|
bdk_chain::local_chain::Update {
|
|
|
|
tip: bdk_chain::local_chain::LocalChain::from_blocks([$(($height, $hash).into()),*].into_iter().collect())
|
|
|
|
.tip()
|
|
|
|
.expect("must have tip"),
|
|
|
|
introduce_older_blocks: true,
|
|
|
|
}
|
2023-03-01 11:09:08 +01:00
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(unused_macros)]
|
|
|
|
macro_rules! changeset {
|
|
|
|
(checkpoints: $($tail:tt)*) => { changeset!(index: TxHeight, checkpoints: $($tail)*) };
|
|
|
|
(
|
|
|
|
index: $ind:ty,
|
|
|
|
checkpoints: [ $(( $height:expr, $cp_to:expr )),* ]
|
|
|
|
$(,txids: [ $(( $txid:expr, $tx_to:expr )),* ])?
|
|
|
|
) => {{
|
|
|
|
use bdk_chain::collections::BTreeMap;
|
|
|
|
|
|
|
|
#[allow(unused_mut)]
|
|
|
|
bdk_chain::sparse_chain::ChangeSet::<$ind> {
|
|
|
|
checkpoints: {
|
|
|
|
let mut changes = BTreeMap::default();
|
|
|
|
$(changes.insert($height, $cp_to);)*
|
|
|
|
changes
|
|
|
|
},
|
|
|
|
txids: {
|
|
|
|
let mut changes = BTreeMap::default();
|
|
|
|
$($(changes.insert($txid, $tx_to.map(|h: TxHeight| h.into()));)*)?
|
|
|
|
changes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(unused)]
|
|
|
|
pub fn new_tx(lt: u32) -> bitcoin::Transaction {
|
|
|
|
bitcoin::Transaction {
|
|
|
|
version: 0x00,
|
|
|
|
lock_time: bitcoin::PackedLockTime(lt),
|
|
|
|
input: vec![],
|
|
|
|
output: vec![],
|
|
|
|
}
|
|
|
|
}
|