@@ -10,15 +10,16 @@ use miniscript::bitcoin::psbt::PartiallySignedTransaction as Psbt;
1010use miniscript:: bitcoin:: {
1111 self , psbt, secp256k1, Address , Network , OutPoint , Script , Sequence , Transaction , TxIn , TxOut ,
1212} ;
13+ use miniscript:: plan:: Assets ;
1314use miniscript:: psbt:: { PsbtExt , PsbtInputExt } ;
14- use miniscript:: Descriptor ;
15+ use miniscript:: { Descriptor , DescriptorPublicKey } ;
1516
1617fn main ( ) {
18+ // Defining the descriptor
1719 let secp256k1 = secp256k1:: Secp256k1 :: new ( ) ;
18-
1920 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+
2223 assert ! ( bridge_descriptor. sanity_check( ) . is_ok( ) ) ;
2324 println ! (
2425 "Bridge pubkey script: {}" ,
@@ -68,6 +69,7 @@ fn main() {
6869 _backup3_private. public_key( & secp256k1)
6970 ) ;
7071
72+ // Create a spending transaction
7173 let spend_tx = Transaction {
7274 version : 2 ,
7375 lock_time : bitcoin:: absolute:: LockTime :: from_consensus ( 5000 ) ,
@@ -97,12 +99,13 @@ fn main() {
9799
98100 let ( outpoint, witness_utxo) = get_vout ( & depo_tx, & bridge_descriptor. script_pubkey ( ) ) ;
99101
102+ // Defining the Transaction Input
100103 let mut txin = TxIn :: default ( ) ;
101104 txin. previous_output = outpoint;
102-
103105 txin. sequence = Sequence :: from_height ( 26 ) ; //Sequence::MAX; //
104106 psbt. unsigned_tx . input . push ( txin) ;
105107
108+ // Defining the Transaction Output
106109 psbt. unsigned_tx . output . push ( TxOut {
107110 script_pubkey : receiver. script_pubkey ( ) ,
108111 value : amount / 5 - 500 ,
@@ -113,14 +116,30 @@ fn main() {
113116 value : amount * 4 / 5 ,
114117 } ) ;
115118
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+ ) ;
117130
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
118135 let mut input = psbt:: Input :: default ( ) ;
136+ result. unwrap ( ) . update_psbt_input ( & mut input) ;
119137 input
120138 . update_with_descriptor_unchecked ( & bridge_descriptor)
121139 . unwrap ( ) ;
122-
123140 input. witness_utxo = Some ( witness_utxo. clone ( ) ) ;
141+
142+ // Push the PSBT Input and declare an PSBT Output Structure
124143 psbt. inputs . push ( input) ;
125144 psbt. outputs . push ( psbt:: Output :: default ( ) ) ;
126145
0 commit comments