@@ -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" ;
2021 let bridge_descriptor = Descriptor :: from_str ( & s) . unwrap ( ) ;
21- //let bridge_descriptor = Descriptor::<bitcoin::PublicKey>::from_str(&s).expect("parse descriptor string");
22+
2223 assert ! ( bridge_descriptor. sanity_check( ) . is_ok( ) ) ;
2324 println ! (
2425 "Bridge pubkey script: {}" ,
@@ -28,10 +29,6 @@ fn main() {
2829 "Bridge address: {}" ,
2930 bridge_descriptor. address( Network :: Regtest ) . unwrap( )
3031 ) ;
31- println ! (
32- "Weight for witness satisfaction cost {}" ,
33- bridge_descriptor. max_weight_to_satisfy( ) . unwrap( )
34- ) ;
3532
3633 let master_private_key_str = "cQhdvB3McbBJdx78VSSumqoHQiSXs75qwLptqwxSQBNBMDxafvaw" ;
3734 let _master_private_key =
@@ -68,6 +65,7 @@ fn main() {
6865 _backup3_private. public_key( & secp256k1)
6966 ) ;
7067
68+ // Create a spending transaction
7169 let spend_tx = Transaction {
7270 version : 2 ,
7371 lock_time : bitcoin:: absolute:: LockTime :: from_consensus ( 5000 ) ,
@@ -97,12 +95,13 @@ fn main() {
9795
9896 let ( outpoint, witness_utxo) = get_vout ( & depo_tx, & bridge_descriptor. script_pubkey ( ) ) ;
9997
98+ // Defining the Transaction Input
10099 let mut txin = TxIn :: default ( ) ;
101100 txin. previous_output = outpoint;
102-
103101 txin. sequence = Sequence :: from_height ( 26 ) ; //Sequence::MAX; //
104102 psbt. unsigned_tx . input . push ( txin) ;
105103
104+ // Defining the Transaction Output
106105 psbt. unsigned_tx . output . push ( TxOut {
107106 script_pubkey : receiver. script_pubkey ( ) ,
108107 value : amount / 5 - 500 ,
@@ -113,14 +112,27 @@ fn main() {
113112 value : amount * 4 / 5 ,
114113 } ) ;
115114
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+ ) ;
117123
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
118128 let mut input = psbt:: Input :: default ( ) ;
129+ result. unwrap ( ) . update_psbt_input ( & mut input) ;
119130 input
120131 . update_with_descriptor_unchecked ( & bridge_descriptor)
121132 . unwrap ( ) ;
122-
123133 input. witness_utxo = Some ( witness_utxo. clone ( ) ) ;
134+
135+ // Push the PSBT Input and declare an PSBT Output Structure
124136 psbt. inputs . push ( input) ;
125137 psbt. outputs . push ( psbt:: Output :: default ( ) ) ;
126138
0 commit comments