/home/darosior/projects/bdk/crates/wallet/tests/common.rs
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | #![allow(unused)]  | 
2  |  | use bdk_chain::{tx_graph, BlockId, ConfirmationBlockTime, ConfirmationTime, TxGraph}; | 
3  |  | use bdk_wallet::{CreateParams, KeychainKind, LocalOutput, Update, Wallet}; | 
4  |  | use bitcoin::{ | 
5  |  |     hashes::Hash, transaction, Address, Amount, BlockHash, FeeRate, Network, OutPoint, Transaction,  | 
6  |  |     TxIn, TxOut, Txid,  | 
7  |  | };  | 
8  |  | use std::str::FromStr;  | 
9  |  |  | 
10  |  | /// Return a fake wallet that appears to be funded for testing.  | 
11  |  | ///  | 
12  |  | /// The funded wallet contains a tx with a 76_000 sats input and two outputs, one spending 25_000  | 
13  |  | /// to a foreign address and one returning 50_000 back to the wallet. The remaining 1000  | 
14  |  | /// sats are the transaction fee.  | 
15  | 131  | pub fn get_funded_wallet_with_change(descriptor: &str, change: &str) -> (Wallet, bitcoin::Txid) { | 
16  | 131  |     let mut wallet = Wallet::create(descriptor.to_string(), change.to_string())  | 
17  | 131  |         .network(Network::Regtest)  | 
18  | 131  |         .create_wallet_no_persist()  | 
19  | 131  |         .expect("descriptors must be valid"); | 
20  | 131  |  | 
21  | 131  |     let receive_address = wallet.peek_address(KeychainKind::External, 0).address;  | 
22  | 131  |     let sendto_address = Address::from_str("bcrt1q3qtze4ys45tgdvguj66zrk4fu6hq3a3v9pfly5") | 
23  | 131  |         .expect("address") | 
24  | 131  |         .require_network(Network::Regtest)  | 
25  | 131  |         .unwrap();  | 
26  | 131  |  | 
27  | 131  |     let tx0 = Transaction { | 
28  | 131  |         version: transaction::Version::ONE,  | 
29  | 131  |         lock_time: bitcoin::absolute::LockTime::ZERO,  | 
30  | 131  |         input: vec![TxIn { | 
31  | 131  |             previous_output: OutPoint { | 
32  | 131  |                 txid: Txid::all_zeros(),  | 
33  | 131  |                 vout: 0,  | 
34  | 131  |             },  | 
35  | 131  |             script_sig: Default::default(),  | 
36  | 131  |             sequence: Default::default(),  | 
37  | 131  |             witness: Default::default(),  | 
38  | 131  |         }],  | 
39  | 131  |         output: vec![TxOut { | 
40  | 131  |             value: Amount::from_sat(76_000),  | 
41  | 131  |             script_pubkey: receive_address.script_pubkey(),  | 
42  | 131  |         }],  | 
43  | 131  |     };  | 
44  | 131  |  | 
45  | 131  |     let tx1 = Transaction { | 
46  | 131  |         version: transaction::Version::ONE,  | 
47  | 131  |         lock_time: bitcoin::absolute::LockTime::ZERO,  | 
48  | 131  |         input: vec![TxIn { | 
49  | 131  |             previous_output: OutPoint { | 
50  | 131  |                 txid: tx0.compute_txid(),  | 
51  | 131  |                 vout: 0,  | 
52  | 131  |             },  | 
53  | 131  |             script_sig: Default::default(),  | 
54  | 131  |             sequence: Default::default(),  | 
55  | 131  |             witness: Default::default(),  | 
56  | 131  |         }],  | 
57  | 131  |         output: vec![  | 
58  | 131  |             TxOut { | 
59  | 131  |                 value: Amount::from_sat(50_000),  | 
60  | 131  |                 script_pubkey: receive_address.script_pubkey(),  | 
61  | 131  |             },  | 
62  | 131  |             TxOut { | 
63  | 131  |                 value: Amount::from_sat(25_000),  | 
64  | 131  |                 script_pubkey: sendto_address.script_pubkey(),  | 
65  | 131  |             },  | 
66  | 131  |         ],  | 
67  | 131  |     };  | 
68  | 131  |  | 
69  | 131  |     wallet  | 
70  | 131  |         .insert_checkpoint(BlockId { | 
71  | 131  |             height: 42,  | 
72  | 131  |             hash: BlockHash::all_zeros(),  | 
73  | 131  |         })  | 
74  | 131  |         .unwrap();  | 
75  | 131  |     wallet  | 
76  | 131  |         .insert_checkpoint(BlockId { | 
77  | 131  |             height: 1_000,  | 
78  | 131  |             hash: BlockHash::all_zeros(),  | 
79  | 131  |         })  | 
80  | 131  |         .unwrap();  | 
81  | 131  |     wallet  | 
82  | 131  |         .insert_checkpoint(BlockId { | 
83  | 131  |             height: 2_000,  | 
84  | 131  |             hash: BlockHash::all_zeros(),  | 
85  | 131  |         })  | 
86  | 131  |         .unwrap();  | 
87  | 131  |  | 
88  | 131  |     wallet.insert_tx(tx0.clone());  | 
89  | 131  |     insert_anchor_from_conf(  | 
90  | 131  |         &mut wallet,  | 
91  | 131  |         tx0.compute_txid(),  | 
92  | 131  |         ConfirmationTime::Confirmed { | 
93  | 131  |             height: 1_000,  | 
94  | 131  |             time: 100,  | 
95  | 131  |         },  | 
96  | 131  |     );  | 
97  | 131  |  | 
98  | 131  |     wallet.insert_tx(tx1.clone());  | 
99  | 131  |     insert_anchor_from_conf(  | 
100  | 131  |         &mut wallet,  | 
101  | 131  |         tx1.compute_txid(),  | 
102  | 131  |         ConfirmationTime::Confirmed { | 
103  | 131  |             height: 2_000,  | 
104  | 131  |             time: 200,  | 
105  | 131  |         },  | 
106  | 131  |     );  | 
107  | 131  |  | 
108  | 131  |     (wallet, tx1.compute_txid())  | 
109  | 131  | } Unexecuted instantiation: common::get_funded_wallet_with_change psbt::common::get_funded_wallet_with_change Line  | Count  | Source  |  15  | 9  | pub fn get_funded_wallet_with_change(descriptor: &str, change: &str) -> (Wallet, bitcoin::Txid) { |  16  | 9  |     let mut wallet = Wallet::create(descriptor.to_string(), change.to_string())  |  17  | 9  |         .network(Network::Regtest)  |  18  | 9  |         .create_wallet_no_persist()  |  19  | 9  |         .expect("descriptors must be valid"); |  20  | 9  |  |  21  | 9  |     let receive_address = wallet.peek_address(KeychainKind::External, 0).address;  |  22  | 9  |     let sendto_address = Address::from_str("bcrt1q3qtze4ys45tgdvguj66zrk4fu6hq3a3v9pfly5") |  23  | 9  |         .expect("address") |  24  | 9  |         .require_network(Network::Regtest)  |  25  | 9  |         .unwrap();  |  26  | 9  |  |  27  | 9  |     let tx0 = Transaction { |  28  | 9  |         version: transaction::Version::ONE,  |  29  | 9  |         lock_time: bitcoin::absolute::LockTime::ZERO,  |  30  | 9  |         input: vec![TxIn { |  31  | 9  |             previous_output: OutPoint { |  32  | 9  |                 txid: Txid::all_zeros(),  |  33  | 9  |                 vout: 0,  |  34  | 9  |             },  |  35  | 9  |             script_sig: Default::default(),  |  36  | 9  |             sequence: Default::default(),  |  37  | 9  |             witness: Default::default(),  |  38  | 9  |         }],  |  39  | 9  |         output: vec![TxOut { |  40  | 9  |             value: Amount::from_sat(76_000),  |  41  | 9  |             script_pubkey: receive_address.script_pubkey(),  |  42  | 9  |         }],  |  43  | 9  |     };  |  44  | 9  |  |  45  | 9  |     let tx1 = Transaction { |  46  | 9  |         version: transaction::Version::ONE,  |  47  | 9  |         lock_time: bitcoin::absolute::LockTime::ZERO,  |  48  | 9  |         input: vec![TxIn { |  49  | 9  |             previous_output: OutPoint { |  50  | 9  |                 txid: tx0.compute_txid(),  |  51  | 9  |                 vout: 0,  |  52  | 9  |             },  |  53  | 9  |             script_sig: Default::default(),  |  54  | 9  |             sequence: Default::default(),  |  55  | 9  |             witness: Default::default(),  |  56  | 9  |         }],  |  57  | 9  |         output: vec![  |  58  | 9  |             TxOut { |  59  | 9  |                 value: Amount::from_sat(50_000),  |  60  | 9  |                 script_pubkey: receive_address.script_pubkey(),  |  61  | 9  |             },  |  62  | 9  |             TxOut { |  63  | 9  |                 value: Amount::from_sat(25_000),  |  64  | 9  |                 script_pubkey: sendto_address.script_pubkey(),  |  65  | 9  |             },  |  66  | 9  |         ],  |  67  | 9  |     };  |  68  | 9  |  |  69  | 9  |     wallet  |  70  | 9  |         .insert_checkpoint(BlockId { |  71  | 9  |             height: 42,  |  72  | 9  |             hash: BlockHash::all_zeros(),  |  73  | 9  |         })  |  74  | 9  |         .unwrap();  |  75  | 9  |     wallet  |  76  | 9  |         .insert_checkpoint(BlockId { |  77  | 9  |             height: 1_000,  |  78  | 9  |             hash: BlockHash::all_zeros(),  |  79  | 9  |         })  |  80  | 9  |         .unwrap();  |  81  | 9  |     wallet  |  82  | 9  |         .insert_checkpoint(BlockId { |  83  | 9  |             height: 2_000,  |  84  | 9  |             hash: BlockHash::all_zeros(),  |  85  | 9  |         })  |  86  | 9  |         .unwrap();  |  87  | 9  |  |  88  | 9  |     wallet.insert_tx(tx0.clone());  |  89  | 9  |     insert_anchor_from_conf(  |  90  | 9  |         &mut wallet,  |  91  | 9  |         tx0.compute_txid(),  |  92  | 9  |         ConfirmationTime::Confirmed { |  93  | 9  |             height: 1_000,  |  94  | 9  |             time: 100,  |  95  | 9  |         },  |  96  | 9  |     );  |  97  | 9  |  |  98  | 9  |     wallet.insert_tx(tx1.clone());  |  99  | 9  |     insert_anchor_from_conf(  |  100  | 9  |         &mut wallet,  |  101  | 9  |         tx1.compute_txid(),  |  102  | 9  |         ConfirmationTime::Confirmed { |  103  | 9  |             height: 2_000,  |  104  | 9  |             time: 200,  |  105  | 9  |         },  |  106  | 9  |     );  |  107  | 9  |  |  108  | 9  |     (wallet, tx1.compute_txid())  |  109  | 9  | }  |  
 wallet::common::get_funded_wallet_with_change Line  | Count  | Source  |  15  | 122  | pub fn get_funded_wallet_with_change(descriptor: &str, change: &str) -> (Wallet, bitcoin::Txid) { |  16  | 122  |     let mut wallet = Wallet::create(descriptor.to_string(), change.to_string())  |  17  | 122  |         .network(Network::Regtest)  |  18  | 122  |         .create_wallet_no_persist()  |  19  | 122  |         .expect("descriptors must be valid"); |  20  | 122  |  |  21  | 122  |     let receive_address = wallet.peek_address(KeychainKind::External, 0).address;  |  22  | 122  |     let sendto_address = Address::from_str("bcrt1q3qtze4ys45tgdvguj66zrk4fu6hq3a3v9pfly5") |  23  | 122  |         .expect("address") |  24  | 122  |         .require_network(Network::Regtest)  |  25  | 122  |         .unwrap();  |  26  | 122  |  |  27  | 122  |     let tx0 = Transaction { |  28  | 122  |         version: transaction::Version::ONE,  |  29  | 122  |         lock_time: bitcoin::absolute::LockTime::ZERO,  |  30  | 122  |         input: vec![TxIn { |  31  | 122  |             previous_output: OutPoint { |  32  | 122  |                 txid: Txid::all_zeros(),  |  33  | 122  |                 vout: 0,  |  34  | 122  |             },  |  35  | 122  |             script_sig: Default::default(),  |  36  | 122  |             sequence: Default::default(),  |  37  | 122  |             witness: Default::default(),  |  38  | 122  |         }],  |  39  | 122  |         output: vec![TxOut { |  40  | 122  |             value: Amount::from_sat(76_000),  |  41  | 122  |             script_pubkey: receive_address.script_pubkey(),  |  42  | 122  |         }],  |  43  | 122  |     };  |  44  | 122  |  |  45  | 122  |     let tx1 = Transaction { |  46  | 122  |         version: transaction::Version::ONE,  |  47  | 122  |         lock_time: bitcoin::absolute::LockTime::ZERO,  |  48  | 122  |         input: vec![TxIn { |  49  | 122  |             previous_output: OutPoint { |  50  | 122  |                 txid: tx0.compute_txid(),  |  51  | 122  |                 vout: 0,  |  52  | 122  |             },  |  53  | 122  |             script_sig: Default::default(),  |  54  | 122  |             sequence: Default::default(),  |  55  | 122  |             witness: Default::default(),  |  56  | 122  |         }],  |  57  | 122  |         output: vec![  |  58  | 122  |             TxOut { |  59  | 122  |                 value: Amount::from_sat(50_000),  |  60  | 122  |                 script_pubkey: receive_address.script_pubkey(),  |  61  | 122  |             },  |  62  | 122  |             TxOut { |  63  | 122  |                 value: Amount::from_sat(25_000),  |  64  | 122  |                 script_pubkey: sendto_address.script_pubkey(),  |  65  | 122  |             },  |  66  | 122  |         ],  |  67  | 122  |     };  |  68  | 122  |  |  69  | 122  |     wallet  |  70  | 122  |         .insert_checkpoint(BlockId { |  71  | 122  |             height: 42,  |  72  | 122  |             hash: BlockHash::all_zeros(),  |  73  | 122  |         })  |  74  | 122  |         .unwrap();  |  75  | 122  |     wallet  |  76  | 122  |         .insert_checkpoint(BlockId { |  77  | 122  |             height: 1_000,  |  78  | 122  |             hash: BlockHash::all_zeros(),  |  79  | 122  |         })  |  80  | 122  |         .unwrap();  |  81  | 122  |     wallet  |  82  | 122  |         .insert_checkpoint(BlockId { |  83  | 122  |             height: 2_000,  |  84  | 122  |             hash: BlockHash::all_zeros(),  |  85  | 122  |         })  |  86  | 122  |         .unwrap();  |  87  | 122  |  |  88  | 122  |     wallet.insert_tx(tx0.clone());  |  89  | 122  |     insert_anchor_from_conf(  |  90  | 122  |         &mut wallet,  |  91  | 122  |         tx0.compute_txid(),  |  92  | 122  |         ConfirmationTime::Confirmed { |  93  | 122  |             height: 1_000,  |  94  | 122  |             time: 100,  |  95  | 122  |         },  |  96  | 122  |     );  |  97  | 122  |  |  98  | 122  |     wallet.insert_tx(tx1.clone());  |  99  | 122  |     insert_anchor_from_conf(  |  100  | 122  |         &mut wallet,  |  101  | 122  |         tx1.compute_txid(),  |  102  | 122  |         ConfirmationTime::Confirmed { |  103  | 122  |             height: 2_000,  |  104  | 122  |             time: 200,  |  105  | 122  |         },  |  106  | 122  |     );  |  107  | 122  |  |  108  | 122  |     (wallet, tx1.compute_txid())  |  109  | 122  | }  |  
  | 
110  |  |  | 
111  |  | /// Return a fake wallet that appears to be funded for testing.  | 
112  |  | ///  | 
113  |  | /// The funded wallet contains a tx with a 76_000 sats input and two outputs, one spending 25_000  | 
114  |  | /// to a foreign address and one returning 50_000 back to the wallet. The remaining 1000  | 
115  |  | /// sats are the transaction fee.  | 
116  |  | ///  | 
117  |  | /// Note: the change descriptor will have script type `p2wpkh`. If passing some other script type  | 
118  |  | /// as argument, make sure you're ok with getting a wallet where the keychains have potentially  | 
119  |  | /// different script types. Otherwise, use `get_funded_wallet_with_change`.  | 
120  | 62  | pub fn get_funded_wallet(descriptor: &str) -> (Wallet, bitcoin::Txid) { | 
121  | 62  |     let change = get_test_wpkh_change();  | 
122  | 62  |     get_funded_wallet_with_change(descriptor, change)  | 
123  | 62  | } Unexecuted instantiation: common::get_funded_wallet psbt::common::get_funded_wallet Line  | Count  | Source  |  120  | 7  | pub fn get_funded_wallet(descriptor: &str) -> (Wallet, bitcoin::Txid) { |  121  | 7  |     let change = get_test_wpkh_change();  |  122  | 7  |     get_funded_wallet_with_change(descriptor, change)  |  123  | 7  | }  |  
 wallet::common::get_funded_wallet Line  | Count  | Source  |  120  | 55  | pub fn get_funded_wallet(descriptor: &str) -> (Wallet, bitcoin::Txid) { |  121  | 55  |     let change = get_test_wpkh_change();  |  122  | 55  |     get_funded_wallet_with_change(descriptor, change)  |  123  | 55  | }  |  
  | 
124  |  |  | 
125  | 62  | pub fn get_funded_wallet_wpkh() -> (Wallet, bitcoin::Txid) { | 
126  | 62  |     get_funded_wallet_with_change(get_test_wpkh(), get_test_wpkh_change())  | 
127  | 62  | } Unexecuted instantiation: common::get_funded_wallet_wpkh Unexecuted instantiation: psbt::common::get_funded_wallet_wpkh wallet::common::get_funded_wallet_wpkh Line  | Count  | Source  |  125  | 62  | pub fn get_funded_wallet_wpkh() -> (Wallet, bitcoin::Txid) { |  126  | 62  |     get_funded_wallet_with_change(get_test_wpkh(), get_test_wpkh_change())  |  127  | 62  | }  |  
  | 
128  |  |  | 
129  | 75  | pub fn get_test_wpkh() -> &'static str { | 
130  | 75  |     "wpkh(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)"  | 
131  | 75  | } Unexecuted instantiation: common::get_test_wpkh psbt::common::get_test_wpkh Line  | Count  | Source  |  129  | 4  | pub fn get_test_wpkh() -> &'static str { |  130  | 4  |     "wpkh(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)"  |  131  | 4  | }  |  
 wallet::common::get_test_wpkh Line  | Count  | Source  |  129  | 71  | pub fn get_test_wpkh() -> &'static str { |  130  | 71  |     "wpkh(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)"  |  131  | 71  | }  |  
  | 
132  |  |  | 
133  | 2  | pub fn get_test_wpkh_with_change_desc() -> (&'static str, &'static str) { | 
134  | 2  |     (  | 
135  | 2  |         "wpkh(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)",  | 
136  | 2  |         get_test_wpkh_change(),  | 
137  | 2  |     )  | 
138  | 2  | } Unexecuted instantiation: common::get_test_wpkh_with_change_desc Unexecuted instantiation: psbt::common::get_test_wpkh_with_change_desc wallet::common::get_test_wpkh_with_change_desc Line  | Count  | Source  |  133  | 2  | pub fn get_test_wpkh_with_change_desc() -> (&'static str, &'static str) { |  134  | 2  |     (  |  135  | 2  |         "wpkh(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)",  |  136  | 2  |         get_test_wpkh_change(),  |  137  | 2  |     )  |  138  | 2  | }  |  
  | 
139  |  |  | 
140  | 126  | fn get_test_wpkh_change() -> &'static str { | 
141  | 126  |     "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/1/0)"  | 
142  | 126  | } Unexecuted instantiation: common::get_test_wpkh_change psbt::common::get_test_wpkh_change Line  | Count  | Source  |  140  | 7  | fn get_test_wpkh_change() -> &'static str { |  141  | 7  |     "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/1/0)"  |  142  | 7  | }  |  
 wallet::common::get_test_wpkh_change Line  | Count  | Source  |  140  | 119  | fn get_test_wpkh_change() -> &'static str { |  141  | 119  |     "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/1/0)"  |  142  | 119  | }  |  
  | 
143  |  |  | 
144  | 4  | pub fn get_test_single_sig_csv() -> &'static str { | 
145  | 4  |     // and(pk(Alice),older(6))  | 
146  | 4  |     "wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),older(6)))"  | 
147  | 4  | } Unexecuted instantiation: common::get_test_single_sig_csv Unexecuted instantiation: psbt::common::get_test_single_sig_csv wallet::common::get_test_single_sig_csv Line  | Count  | Source  |  144  | 4  | pub fn get_test_single_sig_csv() -> &'static str { |  145  | 4  |     // and(pk(Alice),older(6))  |  146  | 4  |     "wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),older(6)))"  |  147  | 4  | }  |  
  | 
148  |  |  | 
149  | 2  | pub fn get_test_a_or_b_plus_csv() -> &'static str { | 
150  | 2  |     // or(pk(Alice),and(pk(Bob),older(144)))  | 
151  | 2  |     "wsh(or_d(pk(cRjo6jqfVNP33HhSS76UhXETZsGTZYx8FMFvR9kpbtCSV1PmdZdu),and_v(v:pk(cMnkdebixpXMPfkcNEjjGin7s94hiehAH4mLbYkZoh9KSiNNmqC8),older(144))))"  | 
152  | 2  | } Unexecuted instantiation: common::get_test_a_or_b_plus_csv Unexecuted instantiation: psbt::common::get_test_a_or_b_plus_csv wallet::common::get_test_a_or_b_plus_csv Line  | Count  | Source  |  149  | 2  | pub fn get_test_a_or_b_plus_csv() -> &'static str { |  150  | 2  |     // or(pk(Alice),and(pk(Bob),older(144)))  |  151  | 2  |     "wsh(or_d(pk(cRjo6jqfVNP33HhSS76UhXETZsGTZYx8FMFvR9kpbtCSV1PmdZdu),and_v(v:pk(cMnkdebixpXMPfkcNEjjGin7s94hiehAH4mLbYkZoh9KSiNNmqC8),older(144))))"  |  152  | 2  | }  |  
  | 
153  |  |  | 
154  | 5  | pub fn get_test_single_sig_cltv() -> &'static str { | 
155  | 5  |     // and(pk(Alice),after(100000))  | 
156  | 5  |     "wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(100000)))"  | 
157  | 5  | } Unexecuted instantiation: common::get_test_single_sig_cltv Unexecuted instantiation: psbt::common::get_test_single_sig_cltv wallet::common::get_test_single_sig_cltv Line  | Count  | Source  |  154  | 5  | pub fn get_test_single_sig_cltv() -> &'static str { |  155  | 5  |     // and(pk(Alice),after(100000))  |  156  | 5  |     "wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(100000)))"  |  157  | 5  | }  |  
  | 
158  |  |  | 
159  | 7  | pub fn get_test_tr_single_sig() -> &'static str { | 
160  | 7  |     "tr(cNJmN3fH9DDbDt131fQNkVakkpzawJBSeybCUNmP1BovpmGQ45xG)"  | 
161  | 7  | } Unexecuted instantiation: common::get_test_tr_single_sig Unexecuted instantiation: psbt::common::get_test_tr_single_sig wallet::common::get_test_tr_single_sig Line  | Count  | Source  |  159  | 7  | pub fn get_test_tr_single_sig() -> &'static str { |  160  | 7  |     "tr(cNJmN3fH9DDbDt131fQNkVakkpzawJBSeybCUNmP1BovpmGQ45xG)"  |  161  | 7  | }  |  
  | 
162  |  |  | 
163  | 3  | pub fn get_test_tr_with_taptree() -> &'static str { | 
164  | 3  |     "tr(b511bd5771e47ee27558b1765e87b541668304ec567721c7b880edc0a010da55,{pk(cPZzKuNmpuUjD1e8jUU4PVzy2b5LngbSip8mBsxf4e7rSFZVb4Uh),pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642)})" | 
165  | 3  | } Unexecuted instantiation: common::get_test_tr_with_taptree Unexecuted instantiation: psbt::common::get_test_tr_with_taptree wallet::common::get_test_tr_with_taptree Line  | Count  | Source  |  163  | 3  | pub fn get_test_tr_with_taptree() -> &'static str { |  164  | 3  |     "tr(b511bd5771e47ee27558b1765e87b541668304ec567721c7b880edc0a010da55,{pk(cPZzKuNmpuUjD1e8jUU4PVzy2b5LngbSip8mBsxf4e7rSFZVb4Uh),pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642)})" |  165  | 3  | }  |  
  | 
166  |  |  | 
167  | 5  | pub fn get_test_tr_with_taptree_both_priv() -> &'static str { | 
168  | 5  |     "tr(b511bd5771e47ee27558b1765e87b541668304ec567721c7b880edc0a010da55,{pk(cPZzKuNmpuUjD1e8jUU4PVzy2b5LngbSip8mBsxf4e7rSFZVb4Uh),pk(cNaQCDwmmh4dS9LzCgVtyy1e1xjCJ21GUDHe9K98nzb689JvinGV)})" | 
169  | 5  | } Unexecuted instantiation: common::get_test_tr_with_taptree_both_priv Unexecuted instantiation: psbt::common::get_test_tr_with_taptree_both_priv wallet::common::get_test_tr_with_taptree_both_priv Line  | Count  | Source  |  167  | 5  | pub fn get_test_tr_with_taptree_both_priv() -> &'static str { |  168  | 5  |     "tr(b511bd5771e47ee27558b1765e87b541668304ec567721c7b880edc0a010da55,{pk(cPZzKuNmpuUjD1e8jUU4PVzy2b5LngbSip8mBsxf4e7rSFZVb4Uh),pk(cNaQCDwmmh4dS9LzCgVtyy1e1xjCJ21GUDHe9K98nzb689JvinGV)})" |  169  | 5  | }  |  
  | 
170  |  |  | 
171  | 1  | pub fn get_test_tr_repeated_key() -> &'static str { | 
172  | 1  |     "tr(b511bd5771e47ee27558b1765e87b541668304ec567721c7b880edc0a010da55,{and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(100)),and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(200))})" | 
173  | 1  | } Unexecuted instantiation: common::get_test_tr_repeated_key Unexecuted instantiation: psbt::common::get_test_tr_repeated_key wallet::common::get_test_tr_repeated_key Line  | Count  | Source  |  171  | 1  | pub fn get_test_tr_repeated_key() -> &'static str { |  172  | 1  |     "tr(b511bd5771e47ee27558b1765e87b541668304ec567721c7b880edc0a010da55,{and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(100)),and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(200))})" |  173  | 1  | }  |  
  | 
174  |  |  | 
175  | 6  | pub fn get_test_tr_single_sig_xprv() -> &'static str { | 
176  | 6  |     "tr(tprv8ZgxMBicQKsPdDArR4xSAECuVxeX1jwwSXR4ApKbkYgZiziDc4LdBy2WvJeGDfUSE4UT4hHhbgEwbdq8ajjUHiKDegkwrNU6V55CxcxonVN/*)"  | 
177  | 6  | } Unexecuted instantiation: common::get_test_tr_single_sig_xprv Unexecuted instantiation: psbt::common::get_test_tr_single_sig_xprv wallet::common::get_test_tr_single_sig_xprv Line  | Count  | Source  |  175  | 6  | pub fn get_test_tr_single_sig_xprv() -> &'static str { |  176  | 6  |     "tr(tprv8ZgxMBicQKsPdDArR4xSAECuVxeX1jwwSXR4ApKbkYgZiziDc4LdBy2WvJeGDfUSE4UT4hHhbgEwbdq8ajjUHiKDegkwrNU6V55CxcxonVN/*)"  |  177  | 6  | }  |  
  | 
178  |  |  | 
179  | 6  | pub fn get_test_tr_single_sig_xprv_with_change_desc() -> (&'static str, &'static str) { | 
180  | 6  |     ("tr(tprv8ZgxMBicQKsPdDArR4xSAECuVxeX1jwwSXR4ApKbkYgZiziDc4LdBy2WvJeGDfUSE4UT4hHhbgEwbdq8ajjUHiKDegkwrNU6V55CxcxonVN/0/*)", | 
181  | 6  |     "tr(tprv8ZgxMBicQKsPdDArR4xSAECuVxeX1jwwSXR4ApKbkYgZiziDc4LdBy2WvJeGDfUSE4UT4hHhbgEwbdq8ajjUHiKDegkwrNU6V55CxcxonVN/1/*)")  | 
182  | 6  | } Unexecuted instantiation: common::get_test_tr_single_sig_xprv_with_change_desc Unexecuted instantiation: psbt::common::get_test_tr_single_sig_xprv_with_change_desc wallet::common::get_test_tr_single_sig_xprv_with_change_desc Line  | Count  | Source  |  179  | 6  | pub fn get_test_tr_single_sig_xprv_with_change_desc() -> (&'static str, &'static str) { |  180  | 6  |     ("tr(tprv8ZgxMBicQKsPdDArR4xSAECuVxeX1jwwSXR4ApKbkYgZiziDc4LdBy2WvJeGDfUSE4UT4hHhbgEwbdq8ajjUHiKDegkwrNU6V55CxcxonVN/0/*)", |  181  | 6  |     "tr(tprv8ZgxMBicQKsPdDArR4xSAECuVxeX1jwwSXR4ApKbkYgZiziDc4LdBy2WvJeGDfUSE4UT4hHhbgEwbdq8ajjUHiKDegkwrNU6V55CxcxonVN/1/*)")  |  182  | 6  | }  |  
  | 
183  |  |  | 
184  | 1  | pub fn get_test_tr_with_taptree_xprv() -> &'static str { | 
185  | 1  |     "tr(cNJmN3fH9DDbDt131fQNkVakkpzawJBSeybCUNmP1BovpmGQ45xG,{pk(tprv8ZgxMBicQKsPdDArR4xSAECuVxeX1jwwSXR4ApKbkYgZiziDc4LdBy2WvJeGDfUSE4UT4hHhbgEwbdq8ajjUHiKDegkwrNU6V55CxcxonVN/*),pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642)})" | 
186  | 1  | } Unexecuted instantiation: common::get_test_tr_with_taptree_xprv Unexecuted instantiation: psbt::common::get_test_tr_with_taptree_xprv wallet::common::get_test_tr_with_taptree_xprv Line  | Count  | Source  |  184  | 1  | pub fn get_test_tr_with_taptree_xprv() -> &'static str { |  185  | 1  |     "tr(cNJmN3fH9DDbDt131fQNkVakkpzawJBSeybCUNmP1BovpmGQ45xG,{pk(tprv8ZgxMBicQKsPdDArR4xSAECuVxeX1jwwSXR4ApKbkYgZiziDc4LdBy2WvJeGDfUSE4UT4hHhbgEwbdq8ajjUHiKDegkwrNU6V55CxcxonVN/*),pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642)})" |  186  | 1  | }  |  
  | 
187  |  |  | 
188  | 1  | pub fn get_test_tr_dup_keys() -> &'static str { | 
189  | 1  |     "tr(cNJmN3fH9DDbDt131fQNkVakkpzawJBSeybCUNmP1BovpmGQ45xG,{pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642),pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642)})" | 
190  | 1  | } Unexecuted instantiation: common::get_test_tr_dup_keys Unexecuted instantiation: psbt::common::get_test_tr_dup_keys wallet::common::get_test_tr_dup_keys Line  | Count  | Source  |  188  | 1  | pub fn get_test_tr_dup_keys() -> &'static str { |  189  | 1  |     "tr(cNJmN3fH9DDbDt131fQNkVakkpzawJBSeybCUNmP1BovpmGQ45xG,{pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642),pk(8aee2b8120a5f157f1223f72b5e62b825831a27a9fdf427db7cc697494d4a642)})" |  190  | 1  | }  |  
  | 
191  |  |  | 
192  |  | /// Construct a new [`FeeRate`] from the given raw `sat_vb` feerate. This is  | 
193  |  | /// useful in cases where we want to create a feerate from a `f64`, as the  | 
194  |  | /// traditional [`FeeRate::from_sat_per_vb`] method will only accept an integer.  | 
195  |  | ///  | 
196  |  | /// **Note** this 'quick and dirty' conversion should only be used when the input  | 
197  |  | /// parameter has units of `satoshis/vbyte` **AND** is not expected to overflow,  | 
198  |  | /// or else the resulting value will be inaccurate.  | 
199  | 0  | pub fn feerate_unchecked(sat_vb: f64) -> FeeRate { | 
200  | 0  |     // 1 sat_vb / 4wu_vb * 1000kwu_wu = 250 sat_kwu  | 
201  | 0  |     let sat_kwu = (sat_vb * 250.0).ceil() as u64;  | 
202  | 0  |     FeeRate::from_sat_per_kwu(sat_kwu)  | 
203  | 0  | } Unexecuted instantiation: common::feerate_unchecked Unexecuted instantiation: psbt::common::feerate_unchecked Unexecuted instantiation: wallet::common::feerate_unchecked  | 
204  |  |  | 
205  |  | /// Simulates confirming a tx with `txid` at the specified `position` by inserting an anchor  | 
206  |  | /// at the lowest height in local chain that is greater or equal to `position`'s height,  | 
207  |  | /// assuming the confirmation time matches `ConfirmationTime::Confirmed`.  | 
208  | 273  | pub fn insert_anchor_from_conf(wallet: &mut Wallet, txid: Txid, position: ConfirmationTime) { | 
209  | 273  |     if let ConfirmationTime::Confirmed { height, time } = position { | 
210  | 273  |         // anchor tx to checkpoint with lowest height that is >= position's height  | 
211  | 273  |         let anchor = wallet  | 
212  | 273  |             .local_chain()  | 
213  | 273  |             .range(height..)  | 
214  | 273  |             .last()  | 
215  | 273  |             .map(|anchor_cp| ConfirmationBlockTime { | 
216  | 273  |                 block_id: anchor_cp.block_id(),  | 
217  | 273  |                 confirmation_time: time,  | 
218  | 273  |             }) Unexecuted instantiation: common::insert_anchor_from_conf::{closure#0}psbt::common::insert_anchor_from_conf::{closure#0}Line  | Count  | Source  |  215  | 18  |             .map(|anchor_cp| ConfirmationBlockTime { |  216  | 18  |                 block_id: anchor_cp.block_id(),  |  217  | 18  |                 confirmation_time: time,  |  218  | 18  |             })  |  
 wallet::common::insert_anchor_from_conf::{closure#0}Line  | Count  | Source  |  215  | 255  |             .map(|anchor_cp| ConfirmationBlockTime { |  216  | 255  |                 block_id: anchor_cp.block_id(),  |  217  | 255  |                 confirmation_time: time,  |  218  | 255  |             })  |  
  | 
219  | 273  |             .expect("confirmation height cannot be greater than tip"); | 
220  | 273  |  | 
221  | 273  |         wallet  | 
222  | 273  |             .apply_update(Update { | 
223  | 273  |                 tx_update: tx_graph::TxUpdate { | 
224  | 273  |                     anchors: [(anchor, txid)].into(),  | 
225  | 273  |                     ..Default::default()  | 
226  | 273  |                 },  | 
227  | 273  |                 ..Default::default()  | 
228  | 273  |             })  | 
229  | 273  |             .unwrap();  | 
230  | 273  |     }0   | 
231  | 273  | } Unexecuted instantiation: common::insert_anchor_from_conf psbt::common::insert_anchor_from_conf Line  | Count  | Source  |  208  | 18  | pub fn insert_anchor_from_conf(wallet: &mut Wallet, txid: Txid, position: ConfirmationTime) { |  209  | 18  |     if let ConfirmationTime::Confirmed { height, time } = position { |  210  | 18  |         // anchor tx to checkpoint with lowest height that is >= position's height  |  211  | 18  |         let anchor = wallet  |  212  | 18  |             .local_chain()  |  213  | 18  |             .range(height..)  |  214  | 18  |             .last()  |  215  | 18  |             .map(|anchor_cp| ConfirmationBlockTime { |  216  |  |                 block_id: anchor_cp.block_id(),  |  217  |  |                 confirmation_time: time,  |  218  | 18  |             })  |  219  | 18  |             .expect("confirmation height cannot be greater than tip"); |  220  | 18  |  |  221  | 18  |         wallet  |  222  | 18  |             .apply_update(Update { |  223  | 18  |                 tx_update: tx_graph::TxUpdate { |  224  | 18  |                     anchors: [(anchor, txid)].into(),  |  225  | 18  |                     ..Default::default()  |  226  | 18  |                 },  |  227  | 18  |                 ..Default::default()  |  228  | 18  |             })  |  229  | 18  |             .unwrap();  |  230  | 18  |     }0   |  231  | 18  | }  |  
 wallet::common::insert_anchor_from_conf Line  | Count  | Source  |  208  | 255  | pub fn insert_anchor_from_conf(wallet: &mut Wallet, txid: Txid, position: ConfirmationTime) { |  209  | 255  |     if let ConfirmationTime::Confirmed { height, time } = position { |  210  | 255  |         // anchor tx to checkpoint with lowest height that is >= position's height  |  211  | 255  |         let anchor = wallet  |  212  | 255  |             .local_chain()  |  213  | 255  |             .range(height..)  |  214  | 255  |             .last()  |  215  | 255  |             .map(|anchor_cp| ConfirmationBlockTime { |  216  |  |                 block_id: anchor_cp.block_id(),  |  217  |  |                 confirmation_time: time,  |  218  | 255  |             })  |  219  | 255  |             .expect("confirmation height cannot be greater than tip"); |  220  | 255  |  |  221  | 255  |         wallet  |  222  | 255  |             .apply_update(Update { |  223  | 255  |                 tx_update: tx_graph::TxUpdate { |  224  | 255  |                     anchors: [(anchor, txid)].into(),  |  225  | 255  |                     ..Default::default()  |  226  | 255  |                 },  |  227  | 255  |                 ..Default::default()  |  228  | 255  |             })  |  229  | 255  |             .unwrap();  |  230  | 255  |     }0   |  231  | 255  | }  |  
  |