@@ -10,15 +10,16 @@ use miniscript::bitcoin::psbt::PartiallySignedTransaction as Psbt;
10
10
use miniscript:: bitcoin:: {
11
11
self , psbt, secp256k1, Address , Network , OutPoint , Script , Sequence , Transaction , TxIn , TxOut ,
12
12
} ;
13
+ use miniscript:: plan:: Assets ;
13
14
use miniscript:: psbt:: { PsbtExt , PsbtInputExt } ;
14
- use miniscript:: Descriptor ;
15
+ use miniscript:: { Descriptor , DescriptorPublicKey } ;
15
16
16
17
fn main ( ) {
18
+ // Defining the descriptor
17
19
let secp256k1 = secp256k1:: Secp256k1 :: new ( ) ;
18
-
19
20
let s = "wsh(t:or_c(pk(027a3565454fe1b749bccaef22aff72843a9c3efefd7b16ac54537a0c23f0ec0de),v:thresh(1,pkh(032d672a1a91cc39d154d366cd231983661b0785c7f27bc338447565844f4a6813),a:pkh(03417129311ed34c242c012cd0a3e0b9bca0065f742d0dfb63c78083ea6a02d4d9),a:pkh(025a687659658baeabdfc415164528065be7bcaade19342241941e556557f01e28))))#7hut9ukn" ;
20
21
let bridge_descriptor = Descriptor :: from_str ( & s) . unwrap ( ) ;
21
- //let bridge_descriptor = Descriptor::<bitcoin::PublicKey>::from_str(&s).expect("parse descriptor string");
22
+
22
23
assert ! ( bridge_descriptor. sanity_check( ) . is_ok( ) ) ;
23
24
println ! (
24
25
"Bridge pubkey script: {}" ,
@@ -28,10 +29,6 @@ fn main() {
28
29
"Bridge address: {}" ,
29
30
bridge_descriptor. address( Network :: Regtest ) . unwrap( )
30
31
) ;
31
- println ! (
32
- "Weight for witness satisfaction cost {}" ,
33
- bridge_descriptor. max_weight_to_satisfy( ) . unwrap( )
34
- ) ;
35
32
36
33
let master_private_key_str = "cQhdvB3McbBJdx78VSSumqoHQiSXs75qwLptqwxSQBNBMDxafvaw" ;
37
34
let _master_private_key =
@@ -68,6 +65,7 @@ fn main() {
68
65
_backup3_private. public_key( & secp256k1)
69
66
) ;
70
67
68
+ // Create a spending transaction
71
69
let spend_tx = Transaction {
72
70
version : 2 ,
73
71
lock_time : bitcoin:: absolute:: LockTime :: from_consensus ( 5000 ) ,
@@ -97,12 +95,13 @@ fn main() {
97
95
98
96
let ( outpoint, witness_utxo) = get_vout ( & depo_tx, & bridge_descriptor. script_pubkey ( ) ) ;
99
97
98
+ // Defining the Transaction Input
100
99
let mut txin = TxIn :: default ( ) ;
101
100
txin. previous_output = outpoint;
102
-
103
101
txin. sequence = Sequence :: from_height ( 26 ) ; //Sequence::MAX; //
104
102
psbt. unsigned_tx . input . push ( txin) ;
105
103
104
+ // Defining the Transaction Output
106
105
psbt. unsigned_tx . output . push ( TxOut {
107
106
script_pubkey : receiver. script_pubkey ( ) ,
108
107
value : amount / 5 - 500 ,
@@ -113,14 +112,27 @@ fn main() {
113
112
value : amount * 4 / 5 ,
114
113
} ) ;
115
114
116
- // Generating signatures & witness data
115
+ // Plan the Transaction using available assets
116
+ let mut assets = Assets :: new ( ) ;
117
+ assets = assets. add (
118
+ DescriptorPublicKey :: from_str (
119
+ "027a3565454fe1b749bccaef22aff72843a9c3efefd7b16ac54537a0c23f0ec0de" ,
120
+ )
121
+ . unwrap ( ) ,
122
+ ) ;
117
123
124
+ // Obtain the result of the plan based on provided assets
125
+ let result = bridge_descriptor. clone ( ) . get_plan ( & assets) ;
126
+
127
+ // Creating a PSBT Input
118
128
let mut input = psbt:: Input :: default ( ) ;
129
+ result. unwrap ( ) . update_psbt_input ( & mut input) ;
119
130
input
120
131
. update_with_descriptor_unchecked ( & bridge_descriptor)
121
132
. unwrap ( ) ;
122
-
123
133
input. witness_utxo = Some ( witness_utxo. clone ( ) ) ;
134
+
135
+ // Push the PSBT Input and declare an PSBT Output Structure
124
136
psbt. inputs . push ( input) ;
125
137
psbt. outputs . push ( psbt:: Output :: default ( ) ) ;
126
138
0 commit comments