@@ -19,7 +19,7 @@ use bp::Outpoint as RgbOutpoint;
19
19
use bp:: Txid as BpTxid ;
20
20
use bp:: seals:: txout:: CloseMethod ;
21
21
use commit_verify:: mpc:: MerkleBlock ;
22
- use rgb:: Runtime ;
22
+ use rgb:: { BlockchainResolver , Runtime } ;
23
23
use rgb_core:: validation:: Validity ;
24
24
use rgb_core:: { Operation , Assign , Anchor , TransitionBundle } ;
25
25
use seals:: txout:: TxPtr ;
@@ -103,10 +103,15 @@ pub struct TransferInfo {
103
103
pub vout : u32 ,
104
104
}
105
105
106
+ /// Get a blockchain resolver
107
+ pub fn get_resolver ( ldk_data_dir : & Path ) -> BlockchainResolver {
108
+ let electrum_url = fs:: read_to_string ( ldk_data_dir. join ( "electrum_url" ) ) . expect ( "able to read" ) ;
109
+ BlockchainResolver :: with ( & electrum_url) . expect ( "able to get resolver" )
110
+ }
111
+
106
112
/// Get an instance of the RGB runtime
107
113
pub fn get_rgb_runtime ( ldk_data_dir : & Path ) -> Runtime {
108
114
let rgb_network_str = fs:: read_to_string ( ldk_data_dir. join ( "rgb_network" ) ) . expect ( "able to read" ) ;
109
- let electrum_url = fs:: read_to_string ( ldk_data_dir. join ( "electrum_url" ) ) . expect ( "able to read" ) ;
110
115
let lock_file_path = ldk_data_dir. join ( RGB_RUNTIME_LOCK_FILE ) ;
111
116
loop {
112
117
match OpenOptions :: new ( ) . write ( true ) . create_new ( true ) . open ( lock_file_path. clone ( ) ) {
@@ -116,8 +121,7 @@ pub fn get_rgb_runtime(ldk_data_dir: &Path) -> Runtime {
116
121
}
117
122
Runtime :: load (
118
123
ldk_data_dir. to_path_buf ( ) ,
119
- Chain :: from_str ( & rgb_network_str) . unwrap ( ) ,
120
- & electrum_url) . expect ( "RGB runtime should be available" )
124
+ Chain :: from_str ( & rgb_network_str) . unwrap ( ) ) . expect ( "RGB runtime should be available" )
121
125
}
122
126
123
127
/// Drop the lock file for write access to the RGB runtime
@@ -164,9 +168,9 @@ pub(crate) fn color_commitment(channel_id: &[u8; 32], funding_outpoint: &OutPoin
164
168
165
169
let htlc_payment_hash = hex:: encode ( htlc. payment_hash . 0 ) ;
166
170
let htlc_proxy_id = format ! ( "{chan_id}{htlc_payment_hash}" ) ;
167
- let rgb_payment_info_path = ldk_data_dir. clone ( ) . join ( htlc_proxy_id) ;
171
+ let rgb_payment_info_path = ldk_data_dir. join ( htlc_proxy_id) ;
168
172
169
- let rgb_payment_info_hash_path = ldk_data_dir. clone ( ) . join ( htlc_payment_hash) ;
173
+ let rgb_payment_info_hash_path = ldk_data_dir. join ( htlc_payment_hash) ;
170
174
if rgb_payment_info_hash_path. exists ( ) {
171
175
let mut rgb_payment_info = parse_rgb_payment_info ( & rgb_payment_info_hash_path) ;
172
176
rgb_payment_info. local_rgb_amount = rgb_info. local_rgb_amount ;
@@ -277,7 +281,7 @@ pub(crate) fn color_commitment(channel_id: &[u8; 32], funding_outpoint: &OutPoin
277
281
let modified_tx = psbt. extract_tx ( ) ;
278
282
let txid = modified_tx. txid ( ) ;
279
283
commitment_tx. built = BuiltCommitmentTransaction {
280
- transaction : modified_tx. clone ( ) ,
284
+ transaction : modified_tx,
281
285
txid,
282
286
} ;
283
287
@@ -460,7 +464,7 @@ pub(crate) fn color_closing(channel_id: &[u8; 32], funding_outpoint: &OutPoint,
460
464
let psbt = PartiallySignedTransaction :: from_str ( & psbt. to_string ( ) ) . unwrap ( ) ;
461
465
let modified_tx = psbt. extract_tx ( ) ;
462
466
let txid = modified_tx. txid ( ) ;
463
- closing_tx. built = modified_tx. clone ( ) ;
467
+ closing_tx. built = modified_tx;
464
468
465
469
// save RGB transfer data to disk
466
470
let transfer_info = TransferInfo {
@@ -548,18 +552,19 @@ pub(crate) fn handle_funding(temporary_channel_id: &[u8; 32], funding_txid: Stri
548
552
let consignment = consignment_res. expect ( "successful get_consignment proxy call" ) . result . expect ( "result" ) ;
549
553
let consignment_bytes = base64:: decode ( consignment) . expect ( "valid consignment" ) ;
550
554
let consignment_path = ldk_data_dir. join ( format ! ( "consignment_{}" , funding_txid) ) ;
551
- fs:: write ( consignment_path. clone ( ) , consignment_bytes. clone ( ) ) . expect ( "unable to write file" ) ;
555
+ fs:: write ( consignment_path, consignment_bytes. clone ( ) ) . expect ( "unable to write file" ) ;
552
556
let consignment_path = ldk_data_dir. join ( format ! ( "consignment_{}" , hex:: encode( temporary_channel_id) ) ) ;
553
557
fs:: write ( consignment_path. clone ( ) , consignment_bytes) . expect ( "unable to write file" ) ;
554
558
let consignment = Bindle :: < RgbTransfer > :: load ( consignment_path) . expect ( "successful consignment load" ) ;
555
559
let transfer: RgbTransfer = consignment. clone ( ) . unbindle ( ) ;
556
560
557
561
let mut runtime = get_rgb_runtime ( ldk_data_dir) ;
562
+ let mut resolver = get_resolver ( ldk_data_dir) ;
558
563
559
564
let funding_seal = BlindSeal :: with_blinding ( CloseMethod :: OpretFirst , TxPtr :: WitnessTx , 0 , STATIC_BLINDING ) ;
560
565
runtime. store_seal_secret ( funding_seal) . expect ( "valid seal" ) ;
561
566
562
- let validated_transfer = match transfer. clone ( ) . validate ( runtime . resolver ( ) ) {
567
+ let validated_transfer = match transfer. clone ( ) . validate ( & mut resolver) {
563
568
Ok ( consignment) => consignment,
564
569
Err ( consignment) => consignment,
565
570
} ;
@@ -569,15 +574,15 @@ pub(crate) fn handle_funding(temporary_channel_id: &[u8; 32], funding_txid: Stri
569
574
return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Invalid RGB consignment for funding" . to_owned ( ) , * temporary_channel_id) ) ;
570
575
}
571
576
572
- let mut minimal_contract = transfer. clone ( ) . into_contract ( ) ;
577
+ let mut minimal_contract = transfer. into_contract ( ) ;
573
578
minimal_contract. bundles = none ! ( ) ;
574
579
minimal_contract. terminals = none ! ( ) ;
575
- let minimal_contract_validated = match minimal_contract. clone ( ) . validate ( runtime . resolver ( ) ) {
580
+ let minimal_contract_validated = match minimal_contract. validate ( & mut resolver) {
576
581
Ok ( consignment) => consignment,
577
582
Err ( consignment) => consignment,
578
583
} ;
579
584
runtime
580
- . import_contract ( minimal_contract_validated)
585
+ . import_contract ( minimal_contract_validated, & mut resolver )
581
586
. expect ( "failure importing issued contract" ) ;
582
587
583
588
let contract_id = consignment. contract_id ( ) ;
@@ -602,7 +607,7 @@ pub(crate) fn handle_funding(temporary_channel_id: &[u8; 32], funding_txid: Stri
602
607
}
603
608
}
604
609
} ;
605
- let _status = runtime. accept_transfer ( validated_transfer. clone ( ) , true ) . expect ( "valid transfer" ) ;
610
+ let _status = runtime. accept_transfer ( validated_transfer, & mut resolver , true ) . expect ( "valid transfer" ) ;
606
611
607
612
drop ( runtime) ;
608
613
drop_rgb_runtime ( ldk_data_dir) ;
0 commit comments