20
20
// limitations under the License.
21
21
22
22
use std:: fs;
23
+ use std:: fs:: File ;
23
24
use std:: path:: PathBuf ;
24
25
use std:: str:: FromStr ;
25
26
26
27
use amplify:: confinement:: U16 ;
27
28
use bp_util:: { Config , Exec } ;
28
29
use bpstd:: { Sats , Txid } ;
29
- use bpwallet :: { Invoice , TxParams } ;
30
- use rgb_rt:: { DescriptorRgb , RgbDescr , RgbKeychain , RuntimeError } ;
30
+ use psbt :: PsbtVer ;
31
+ use rgb_rt:: { DescriptorRgb , RgbDescr , RgbKeychain , RuntimeError , TransferParams } ;
31
32
use rgbstd:: containers:: { Bindle , Transfer , UniversalBindle } ;
32
33
use rgbstd:: contract:: { ContractId , GenesisSeal , GraphSeal , StateType } ;
33
34
use rgbstd:: interface:: { ContractBuilder , FilterExclude , IfaceId , SchemaIfaces } ;
34
35
use rgbstd:: invoice:: { Beneficiary , InvoiceState , RgbInvoice , RgbTransport } ;
35
36
use rgbstd:: persistence:: { Inventory , Stash } ;
36
37
use rgbstd:: schema:: SchemaId ;
37
- use rgbstd:: SealDefinition ;
38
+ use rgbstd:: XSeal ;
38
39
use seals:: txout:: { CloseMethod , ExplicitSeal } ;
39
40
use strict_types:: encoding:: { FieldName , TypeName } ;
40
41
use strict_types:: StrictVal ;
@@ -139,10 +140,19 @@ pub enum Command {
139
140
/// Transfer RGB assets
140
141
#[ display( "transfer" ) ]
141
142
Transfer {
143
+ /// Encode PSBT as V2
144
+ #[ clap( short = '2' ) ]
145
+ v2 : bool ,
146
+
142
147
/// Method for single-use-seals
143
148
#[ clap( long, default_value = "tapret1st" ) ]
144
149
method : CloseMethod ,
145
150
151
+ /// Amount of satoshis which should be paid to the address-based
152
+ /// beneficiary
153
+ #[ clap( long, default_value = "2000" ) ]
154
+ sats : Sats ,
155
+
146
156
/// Invoice data
147
157
invoice : RgbInvoice ,
148
158
@@ -295,7 +305,7 @@ impl Exec for RgbArgs {
295
305
contract,
296
306
file,
297
307
} => {
298
- let mut runtime = self . rgb_runtime ( & config) ?;
308
+ let runtime = self . rgb_runtime ( & config) ?;
299
309
let bindle = runtime
300
310
. export_contract ( * contract)
301
311
. map_err ( |err| err. to_string ( ) ) ?;
@@ -471,7 +481,7 @@ impl Exec for RgbArgs {
471
481
. expect ( "seal must be a string" ) ;
472
482
let seal =
473
483
ExplicitSeal :: < Txid > :: from_str ( seal) . expect ( "invalid seal definition" ) ;
474
- let seal = GenesisSeal :: from ( seal) ;
484
+ let seal = XSeal :: Bitcoin ( GenesisSeal :: from ( seal) ) ;
475
485
476
486
// Workaround for borrow checker:
477
487
let field_name =
@@ -537,15 +547,15 @@ impl Exec for RgbArgs {
537
547
. next ( )
538
548
. expect ( "no addresses left" )
539
549
. addr ;
540
- Beneficiary :: WitnessUtxo ( addr)
550
+ Beneficiary :: WitnessVoutBitcoin ( addr)
541
551
}
542
552
( _, Some ( outpoint) ) => {
543
553
let seal = GraphSeal :: new (
544
554
runtime. wallet ( ) . seal_close_method ( ) ,
545
555
outpoint. txid ,
546
556
outpoint. vout ,
547
557
) ;
548
- runtime. store_seal_secret ( SealDefinition :: Bitcoin ( seal) ) ?;
558
+ runtime. store_seal_secret ( XSeal :: Bitcoin ( seal) ) ?;
549
559
Beneficiary :: BlindedSeal ( seal. to_concealed_seal ( ) )
550
560
}
551
561
} ;
@@ -565,40 +575,36 @@ impl Exec for RgbArgs {
565
575
}
566
576
#[ allow( unused_variables) ]
567
577
Command :: Transfer {
578
+ v2,
568
579
method,
569
580
invoice,
570
581
fee,
571
- psbt : psbt_filename,
582
+ sats,
583
+ psbt : psbt_file,
572
584
consignment : out_file,
573
585
} => {
574
- // 1. BP Wallet: Do coin selection (using Layer2 components)
575
- // 2. BP Wallet: Construct PSBT prototype (no state transitions)
576
- // ... complete PSBT structure updates in multi-party protocols
577
- // 3. RGB Std: Prepare stencil - main state transition and blank state
578
- // transitions
579
- // 4. RGB PSBT: Embed stencil into PSBT
580
- // ... complete PSBT client-side updates in multi-party protocols
581
- // 5. RGB PSBT: Anchorize PSBT, extract disclosure
582
- // 6. RGB Std: Merge disclosure into the stash, cache and index
583
- // 7. RGB Std: Prepare consignment
584
-
585
586
let mut runtime = self . rgb_runtime ( & config) ?;
586
-
587
587
// TODO: Support lock time and RBFs
588
- let params = TxParams :: with ( * fee) ;
588
+ let params = TransferParams :: with ( * fee, * sats ) ;
589
589
590
- eprint ! ( "Constructing PSBT ... " ) ;
591
- let mut psbt = runtime
592
- . wallet_mut ( )
593
- . construct_psbt ( coins, Invoice , params) ?;
594
- eprintln ! ( "success" ) ;
595
-
596
- eprint ! ( "Constructing transfer consignment ... " ) ;
597
- let transfer = runtime
598
- . pay ( invoice, & mut psbt, method)
590
+ let ( psbt, meta, transfer) = runtime
591
+ . pay ( invoice, * method, params)
599
592
. map_err ( |err| err. to_string ( ) ) ?;
593
+
600
594
transfer. save ( & out_file) ?;
601
- eprintln ! ( "success" ) ;
595
+
596
+ let ver = if * v2 { PsbtVer :: V2 } else { PsbtVer :: V0 } ;
597
+ eprintln ! ( "{}" , serde_yaml:: to_string( & psbt) . unwrap( ) ) ;
598
+ match psbt_file {
599
+ Some ( file_name) => {
600
+ let mut psbt_file = File :: create ( file_name) ?;
601
+ psbt. encode ( ver, & mut psbt_file) ?;
602
+ }
603
+ None => match ver {
604
+ PsbtVer :: V0 => println ! ( "{psbt}" ) ,
605
+ PsbtVer :: V2 => println ! ( "{psbt:#}" ) ,
606
+ } ,
607
+ }
602
608
}
603
609
Command :: Inspect { file, format } => {
604
610
let bindle = UniversalBindle :: load_file ( file) ?;
@@ -651,7 +657,11 @@ impl Exec for RgbArgs {
651
657
format ! ( "{root_dir}/stash/geneses/{id}.yaml" ) ,
652
658
serde_yaml:: to_string ( runtime. genesis ( id) ?) ?,
653
659
) ?;
654
- for ( no, suppl) in runtime. contract_suppl ( id) . into_iter ( ) . flatten ( ) . enumerate ( )
660
+ for ( no, suppl) in runtime
661
+ . contract_suppl_all ( id)
662
+ . into_iter ( )
663
+ . flatten ( )
664
+ . enumerate ( )
655
665
{
656
666
fs:: write (
657
667
format ! ( "{root_dir}/stash/geneses/{id}.suppl.{no:03}.yaml" ) ,
@@ -665,7 +675,7 @@ impl Exec for RgbArgs {
665
675
serde_yaml:: to_string ( runtime. bundle ( id) ?) ?,
666
676
) ?;
667
677
}
668
- for id in runtime. anchor_ids ( ) ? {
678
+ for id in runtime. witness_ids ( ) ? {
669
679
fs:: write (
670
680
format ! ( "{root_dir}/stash/anchors/{id}.yaml" ) ,
671
681
serde_yaml:: to_string ( runtime. anchor ( id) ?) ?,
0 commit comments