@@ -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
- let bridge_descriptor = Descriptor :: from_str ( & s) . unwrap ( ) ;
21
- //let bridge_descriptor = Descriptor::<bitcoin::PublicKey>::from_str(&s).expect("parse descriptor string");
21
+ let bridge_descriptor = Descriptor :: 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: {}" ,
@@ -68,6 +69,7 @@ fn main() {
68
69
_backup3_private. public_key( & secp256k1)
69
70
) ;
70
71
72
+ // Create a spending transaction
71
73
let spend_tx = Transaction {
72
74
version : 2 ,
73
75
lock_time : bitcoin:: absolute:: LockTime :: from_consensus ( 5000 ) ,
@@ -97,12 +99,13 @@ fn main() {
97
99
98
100
let ( outpoint, witness_utxo) = get_vout ( & depo_tx, & bridge_descriptor. script_pubkey ( ) ) ;
99
101
102
+ // Defining the Transaction Input
100
103
let mut txin = TxIn :: default ( ) ;
101
104
txin. previous_output = outpoint;
102
-
103
105
txin. sequence = Sequence :: from_height ( 26 ) ; //Sequence::MAX; //
104
106
psbt. unsigned_tx . input . push ( txin) ;
105
107
108
+ // Defining the Transaction Output
106
109
psbt. unsigned_tx . output . push ( TxOut {
107
110
script_pubkey : receiver. script_pubkey ( ) ,
108
111
value : amount / 5 - 500 ,
@@ -113,14 +116,30 @@ fn main() {
113
116
value : amount * 4 / 5 ,
114
117
} ) ;
115
118
116
- // Generating signatures & witness data
119
+ // Plan the Transaction using available assets
120
+ // The descriptor is : or(pk(A),thresh(1,pkh(B),pkh(C),pkh(D)))
121
+ // For the context of planning in this example, We will only provide the key A as an asset
122
+ // This will satisfy the pk(A) and since we have an OR, This should be sufficient to satisfy the given policy.
123
+ let mut assets = Assets :: new ( ) ;
124
+ assets = assets. add (
125
+ DescriptorPublicKey :: from_str (
126
+ "027a3565454fe1b749bccaef22aff72843a9c3efefd7b16ac54537a0c23f0ec0de" ,
127
+ )
128
+ . unwrap ( ) ,
129
+ ) ;
117
130
131
+ // Obtain the result of the plan based on provided assets
132
+ let result = bridge_descriptor. clone ( ) . get_plan ( & assets) ;
133
+
134
+ // Creating a PSBT Input
118
135
let mut input = psbt:: Input :: default ( ) ;
136
+ result. unwrap ( ) . update_psbt_input ( & mut input) ;
119
137
input
120
138
. update_with_descriptor_unchecked ( & bridge_descriptor)
121
139
. unwrap ( ) ;
122
-
123
140
input. witness_utxo = Some ( witness_utxo. clone ( ) ) ;
141
+
142
+ // Push the PSBT Input and declare an PSBT Output Structure
124
143
psbt. inputs . push ( input) ;
125
144
psbt. outputs . push ( psbt:: Output :: default ( ) ) ;
126
145
0 commit comments