- The KeychainTxOutIndex's internal SpkIterator now uses DescriptorId instead of K. The DescriptorId -> K translation is made at the KeychainTxOutIndex level. - The keychain::Changeset is now a struct, which includes a map for last revealed indexes, and one for newly added keychains and their descriptor. API changes in bdk: - Wallet::keychains returns a `impl Iterator` instead of `BTreeMap` - Wallet::load doesn't take descriptors anymore, since they're stored in the db - Wallet::new_or_load checks if the loaded descriptor from db is the same as the provided one API changes in bdk_chain: - `ChangeSet` is now a struct, which includes a map for last revealed indexes, and one for keychains and descriptors. - `KeychainTxOutIndex::inner` returns a `SpkIterator<(DescriptorId, u32)>` - `KeychainTxOutIndex::outpoints` returns a `impl Iterator` instead of `&BTreeSet` - `KeychainTxOutIndex::keychains` returns a `impl Iterator` instead of `&BTreeMap` - `KeychainTxOutIndex::txouts` doesn't return a ExactSizeIterator anymore - `KeychainTxOutIndex::unbounded_spk_iter` returns an `Option` - `KeychainTxOutIndex::next_index` returns an `Option` - `KeychainTxOutIndex::last_revealed_indices` returns a `BTreeMap` instead of `&BTreeMap` - `KeychainTxOutIndex::reveal_to_target` returns an `Option` - `KeychainTxOutIndex::reveal_next_spk` returns an `Option` - `KeychainTxOutIndex::next_unused_spk` returns an `Option` - `KeychainTxOutIndex::add_keychain` has been renamed to `KeychainTxOutIndex::insert_descriptor`, and now it returns a ChangeSet
88 lines
3.2 KiB
Rust
88 lines
3.2 KiB
Rust
mod tx_template;
|
|
#[allow(unused_imports)]
|
|
pub use tx_template::*;
|
|
|
|
#[allow(unused_macros)]
|
|
macro_rules! block_id {
|
|
($height:expr, $hash:literal) => {{
|
|
bdk_chain::BlockId {
|
|
height: $height,
|
|
hash: bitcoin::hashes::Hash::hash($hash.as_bytes()),
|
|
}
|
|
}};
|
|
}
|
|
|
|
#[allow(unused_macros)]
|
|
macro_rules! h {
|
|
($index:literal) => {{
|
|
bitcoin::hashes::Hash::hash($index.as_bytes())
|
|
}};
|
|
}
|
|
|
|
#[allow(unused_macros)]
|
|
macro_rules! local_chain {
|
|
[ $(($height:expr, $block_hash:expr)), * ] => {{
|
|
#[allow(unused_mut)]
|
|
bdk_chain::local_chain::LocalChain::from_blocks([$(($height, $block_hash).into()),*].into_iter().collect())
|
|
.expect("chain must have genesis block")
|
|
}};
|
|
}
|
|
|
|
#[allow(unused_macros)]
|
|
macro_rules! chain_update {
|
|
[ $(($height:expr, $hash:expr)), * ] => {{
|
|
#[allow(unused_mut)]
|
|
bdk_chain::local_chain::LocalChain::from_blocks([$(($height, $hash).into()),*].into_iter().collect())
|
|
.expect("chain must have genesis block")
|
|
.tip()
|
|
}};
|
|
}
|
|
|
|
#[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: bitcoin::transaction::Version::non_standard(0x00),
|
|
lock_time: bitcoin::absolute::LockTime::from_consensus(lt),
|
|
input: vec![],
|
|
output: vec![],
|
|
}
|
|
}
|
|
|
|
#[allow(unused)]
|
|
pub const DESCRIPTORS: [&str; 7] = [
|
|
"tr([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/0/*)",
|
|
"tr([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/1/*)",
|
|
"wpkh([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/1/0/*)",
|
|
"tr(tprv8ZgxMBicQKsPd3krDUsBAmtnRsK3rb8u5yi1zhQgMhF1tR8MW7xfE4rnrbbsrbPR52e7rKapu6ztw1jXveJSCGHEriUGZV7mCe88duLp5pj/86'/1'/0'/0/*)",
|
|
"tr(tprv8ZgxMBicQKsPd3krDUsBAmtnRsK3rb8u5yi1zhQgMhF1tR8MW7xfE4rnrbbsrbPR52e7rKapu6ztw1jXveJSCGHEriUGZV7mCe88duLp5pj/86'/1'/0'/1/*)",
|
|
"wpkh(xprv9s21ZrQH143K4EXURwMHuLS469fFzZyXk7UUpdKfQwhoHcAiYTakpe8pMU2RiEdvrU9McyuE7YDoKcXkoAwEGoK53WBDnKKv2zZbb9BzttX/1/0/*)",
|
|
// non-wildcard
|
|
"wpkh([73c5da0a/86'/0'/0']xprv9xgqHN7yz9MwCkxsBPN5qetuNdQSUttZNKw1dcYTV4mkaAFiBVGQziHs3NRSWMkCzvgjEe3n9xV8oYywvM8at9yRqyaZVz6TYYhX98VjsUk/1/0)",
|
|
];
|