Merge commit 'refs/pull/428/head' of github.com:bitcoindevkit/bdk
This commit is contained in:
commit
dd4bd96f79
@ -456,20 +456,21 @@ impl ConfigurableDatabase for MemoryDatabase {
|
|||||||
/// don't have `test` set.
|
/// don't have `test` set.
|
||||||
macro_rules! populate_test_db {
|
macro_rules! populate_test_db {
|
||||||
($db:expr, $tx_meta:expr, $current_height:expr$(,)?) => {{
|
($db:expr, $tx_meta:expr, $current_height:expr$(,)?) => {{
|
||||||
|
use std::str::FromStr;
|
||||||
use $crate::database::BatchOperations;
|
use $crate::database::BatchOperations;
|
||||||
let mut db = $db;
|
let mut db = $db;
|
||||||
let tx_meta = $tx_meta;
|
let tx_meta = $tx_meta;
|
||||||
let current_height: Option<u32> = $current_height;
|
let current_height: Option<u32> = $current_height;
|
||||||
let tx = Transaction {
|
let tx = $crate::bitcoin::Transaction {
|
||||||
version: 1,
|
version: 1,
|
||||||
lock_time: 0,
|
lock_time: 0,
|
||||||
input: vec![],
|
input: vec![],
|
||||||
output: tx_meta
|
output: tx_meta
|
||||||
.output
|
.output
|
||||||
.iter()
|
.iter()
|
||||||
.map(|out_meta| bitcoin::TxOut {
|
.map(|out_meta| $crate::bitcoin::TxOut {
|
||||||
value: out_meta.value,
|
value: out_meta.value,
|
||||||
script_pubkey: bitcoin::Address::from_str(&out_meta.to_address)
|
script_pubkey: $crate::bitcoin::Address::from_str(&out_meta.to_address)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.script_pubkey(),
|
.script_pubkey(),
|
||||||
})
|
})
|
||||||
@ -477,12 +478,14 @@ macro_rules! populate_test_db {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let txid = tx.txid();
|
let txid = tx.txid();
|
||||||
let confirmation_time = tx_meta.min_confirmations.map(|conf| ConfirmationTime {
|
let confirmation_time = tx_meta
|
||||||
height: current_height.unwrap().checked_sub(conf as u32).unwrap(),
|
.min_confirmations
|
||||||
timestamp: 0,
|
.map(|conf| $crate::ConfirmationTime {
|
||||||
});
|
height: current_height.unwrap().checked_sub(conf as u32).unwrap(),
|
||||||
|
timestamp: 0,
|
||||||
|
});
|
||||||
|
|
||||||
let tx_details = TransactionDetails {
|
let tx_details = $crate::TransactionDetails {
|
||||||
transaction: Some(tx.clone()),
|
transaction: Some(tx.clone()),
|
||||||
txid,
|
txid,
|
||||||
fee: Some(0),
|
fee: Some(0),
|
||||||
@ -494,13 +497,13 @@ macro_rules! populate_test_db {
|
|||||||
|
|
||||||
db.set_tx(&tx_details).unwrap();
|
db.set_tx(&tx_details).unwrap();
|
||||||
for (vout, out) in tx.output.iter().enumerate() {
|
for (vout, out) in tx.output.iter().enumerate() {
|
||||||
db.set_utxo(&LocalUtxo {
|
db.set_utxo(&$crate::LocalUtxo {
|
||||||
txout: out.clone(),
|
txout: out.clone(),
|
||||||
outpoint: OutPoint {
|
outpoint: $crate::bitcoin::OutPoint {
|
||||||
txid,
|
txid,
|
||||||
vout: vout as u32,
|
vout: vout as u32,
|
||||||
},
|
},
|
||||||
keychain: KeychainKind::External,
|
keychain: $crate::KeychainKind::External,
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -100,8 +100,8 @@ impl TranslateDescriptor for Descriptor<DescriptorPublicKey> {
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! testutils {
|
macro_rules! testutils {
|
||||||
( @external $descriptors:expr, $child:expr ) => ({
|
( @external $descriptors:expr, $child:expr ) => ({
|
||||||
use bitcoin::secp256k1::Secp256k1;
|
use $crate::bitcoin::secp256k1::Secp256k1;
|
||||||
use miniscript::descriptor::{Descriptor, DescriptorPublicKey, DescriptorTrait};
|
use $crate::miniscript::descriptor::{Descriptor, DescriptorPublicKey, DescriptorTrait};
|
||||||
|
|
||||||
use $crate::testutils::TranslateDescriptor;
|
use $crate::testutils::TranslateDescriptor;
|
||||||
|
|
||||||
@ -111,15 +111,15 @@ macro_rules! testutils {
|
|||||||
parsed.derive_translated(&secp, $child).address(bitcoin::Network::Regtest).expect("No address form")
|
parsed.derive_translated(&secp, $child).address(bitcoin::Network::Regtest).expect("No address form")
|
||||||
});
|
});
|
||||||
( @internal $descriptors:expr, $child:expr ) => ({
|
( @internal $descriptors:expr, $child:expr ) => ({
|
||||||
use bitcoin::secp256k1::Secp256k1;
|
use $crate::bitcoin::secp256k1::Secp256k1;
|
||||||
use miniscript::descriptor::{Descriptor, DescriptorPublicKey, DescriptorTrait};
|
use $crate::miniscript::descriptor::{Descriptor, DescriptorPublicKey, DescriptorTrait};
|
||||||
|
|
||||||
use $crate::testutils::TranslateDescriptor;
|
use $crate::testutils::TranslateDescriptor;
|
||||||
|
|
||||||
let secp = Secp256k1::new();
|
let secp = Secp256k1::new();
|
||||||
|
|
||||||
let parsed = Descriptor::<DescriptorPublicKey>::parse_descriptor(&secp, &$descriptors.1.expect("Missing internal descriptor")).expect("Failed to parse descriptor in `testutils!(@internal)`").0;
|
let parsed = Descriptor::<DescriptorPublicKey>::parse_descriptor(&secp, &$descriptors.1.expect("Missing internal descriptor")).expect("Failed to parse descriptor in `testutils!(@internal)`").0;
|
||||||
parsed.derive_translated(&secp, $child).address(bitcoin::Network::Regtest).expect("No address form")
|
parsed.derive_translated(&secp, $child).address($crate::bitcoin::Network::Regtest).expect("No address form")
|
||||||
});
|
});
|
||||||
( @e $descriptors:expr, $child:expr ) => ({ testutils!(@external $descriptors, $child) });
|
( @e $descriptors:expr, $child:expr ) => ({ testutils!(@external $descriptors, $child) });
|
||||||
( @i $descriptors:expr, $child:expr ) => ({ testutils!(@internal $descriptors, $child) });
|
( @i $descriptors:expr, $child:expr ) => ({ testutils!(@internal $descriptors, $child) });
|
||||||
@ -145,8 +145,8 @@ macro_rules! testutils {
|
|||||||
let mut seed = [0u8; 32];
|
let mut seed = [0u8; 32];
|
||||||
rand::thread_rng().fill(&mut seed[..]);
|
rand::thread_rng().fill(&mut seed[..]);
|
||||||
|
|
||||||
let key = bitcoin::util::bip32::ExtendedPrivKey::new_master(
|
let key = $crate::bitcoin::util::bip32::ExtendedPrivKey::new_master(
|
||||||
bitcoin::Network::Testnet,
|
$crate::bitcoin::Network::Testnet,
|
||||||
&seed,
|
&seed,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -158,13 +158,13 @@ macro_rules! testutils {
|
|||||||
( @generate_wif ) => ({
|
( @generate_wif ) => ({
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
let mut key = [0u8; bitcoin::secp256k1::constants::SECRET_KEY_SIZE];
|
let mut key = [0u8; $crate::bitcoin::secp256k1::constants::SECRET_KEY_SIZE];
|
||||||
rand::thread_rng().fill(&mut key[..]);
|
rand::thread_rng().fill(&mut key[..]);
|
||||||
|
|
||||||
(bitcoin::PrivateKey {
|
($crate::bitcoin::PrivateKey {
|
||||||
compressed: true,
|
compressed: true,
|
||||||
network: bitcoin::Network::Testnet,
|
network: $crate::bitcoin::Network::Testnet,
|
||||||
key: bitcoin::secp256k1::SecretKey::from_slice(&key).unwrap(),
|
key: $crate::bitcoin::secp256k1::SecretKey::from_slice(&key).unwrap(),
|
||||||
}.to_string(), None::<String>, None::<String>)
|
}.to_string(), None::<String>, None::<String>)
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -181,8 +181,8 @@ macro_rules! testutils {
|
|||||||
( @descriptors ( $external_descriptor:expr ) $( ( $internal_descriptor:expr ) )? $( ( @keys $( $keys:tt )* ) )* ) => ({
|
( @descriptors ( $external_descriptor:expr ) $( ( $internal_descriptor:expr ) )? $( ( @keys $( $keys:tt )* ) )* ) => ({
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use miniscript::descriptor::Descriptor;
|
use $crate::miniscript::descriptor::Descriptor;
|
||||||
use miniscript::TranslatePk;
|
use $crate::miniscript::TranslatePk;
|
||||||
|
|
||||||
#[allow(unused_assignments, unused_mut)]
|
#[allow(unused_assignments, unused_mut)]
|
||||||
let mut keys: HashMap<&'static str, (String, Option<String>, Option<String>)> = HashMap::new();
|
let mut keys: HashMap<&'static str, (String, Option<String>, Option<String>)> = HashMap::new();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user