2
2
3
3
pub mod proxy;
4
4
5
- use crate :: bitcoin:: hashes:: Hash ;
6
5
use crate :: chain:: transaction:: OutPoint ;
7
6
use crate :: ln:: PaymentHash ;
8
7
use crate :: ln:: chan_utils:: { BuiltCommitmentTransaction , ClosingTransaction , CommitmentTransaction , HTLCOutputInCommitment } ;
@@ -15,10 +14,9 @@ use bitcoin::blockdata::transaction::Transaction;
15
14
use invoice:: ConsignmentEndpoint ;
16
15
use psbt:: { Psbt , PsbtVersion } ;
17
16
18
- use bitcoin:: BlockHash ;
19
17
use bp:: seals:: txout:: CloseMethod ;
20
18
use internet2:: addr:: ServiceAddr ;
21
- use lnpbp:: chain:: { Chain , GENESIS_HASH_REGTEST } ;
19
+ use lnpbp:: chain:: Chain ;
22
20
use rgb20:: Asset as Rgb20Asset ;
23
21
use rgb:: prelude:: EndpointValueMap ;
24
22
use rgb:: psbt:: { RgbExt , RgbInExt } ;
@@ -62,12 +60,30 @@ pub struct RgbPaymentInfo {
62
60
pub remote_rgb_amount : u64 ,
63
61
}
64
62
63
+ /// RGB UTXO
64
+ #[ derive( Debug , Serialize , Deserialize ) ]
65
+ pub struct RgbUtxo {
66
+ /// Outpoint
67
+ pub outpoint : BtcOutPoint ,
68
+ /// Whether the UTXO is colored
69
+ pub colored : bool ,
70
+ }
71
+
72
+ /// RGB UTXO list
73
+ #[ derive( Debug , Serialize , Deserialize ) ]
74
+ pub struct RgbUtxos {
75
+ /// The list of RGB UTXOs
76
+ pub utxos : Vec < RgbUtxo > ,
77
+ }
78
+
79
+
65
80
pub ( crate ) fn get_rgb_node_client ( ldk_data_dir : & PathBuf ) -> Client {
66
81
let port_str = fs:: read_to_string ( ldk_data_dir. join ( "rgb_node_port" ) ) . expect ( "able to read" ) ;
67
82
let port = port_str. parse :: < u16 > ( ) . unwrap ( ) ;
83
+ let rgb_network_str = fs:: read_to_string ( ldk_data_dir. join ( "rgb_node_network" ) ) . expect ( "able to read" ) ;
84
+ let rgb_network = Chain :: from_str ( & rgb_network_str) . unwrap ( ) ;
68
85
let ip = Ipv4Addr :: new ( 127 , 0 , 0 , 1 ) ;
69
86
let rgb_node_endpoint = ServiceAddr :: Tcp ( SocketAddr :: V4 ( SocketAddrV4 :: new ( ip, port) ) ) ;
70
- let rgb_network = Chain :: Regtest ( BlockHash :: from_slice ( GENESIS_HASH_REGTEST ) . expect ( "valid bloch hash" ) ) ;
71
87
Client :: with ( rgb_node_endpoint, "rgb-ln-node" . to_string ( ) , rgb_network)
72
88
. expect ( "Error initializing client" )
73
89
}
@@ -409,11 +425,20 @@ pub fn write_rgb_channel_info(path: &PathBuf, rgb_info: &RgbInfo) {
409
425
fs:: write ( path, serialized_info) . expect ( "able to write" )
410
426
}
411
427
412
- /// Rename RgbInfo file to channel_id
413
- pub ( crate ) fn rename_rgbinfo_file ( channel_id : & [ u8 ; 32 ] , temporary_channel_id : & [ u8 ; 32 ] , ldk_data_dir : & PathBuf ) {
414
- let temporary_channel_id_path = ldk_data_dir. join ( hex:: encode ( temporary_channel_id) ) ;
415
- let channel_id_path = ldk_data_dir. join ( hex:: encode ( channel_id) ) ;
428
+ /// Rename RGB files from temporary to final channel ID
429
+ pub ( crate ) fn rename_rgb_files ( channel_id : & [ u8 ; 32 ] , temporary_channel_id : & [ u8 ; 32 ] , ldk_data_dir : & PathBuf ) {
430
+ let temp_chan_id = hex:: encode ( temporary_channel_id) ;
431
+ let chan_id = hex:: encode ( channel_id) ;
432
+
433
+ let temporary_channel_id_path = ldk_data_dir. join ( & temp_chan_id) ;
434
+ let channel_id_path = ldk_data_dir. join ( & chan_id) ;
416
435
fs:: rename ( temporary_channel_id_path, channel_id_path) . expect ( "rename ok" ) ;
436
+
437
+ let funding_consignment_tmp = ldk_data_dir. join ( format ! ( "consignment_{}" , temp_chan_id) ) ;
438
+ if funding_consignment_tmp. exists ( ) {
439
+ let funding_consignment = ldk_data_dir. join ( format ! ( "consignment_{}" , chan_id) ) ;
440
+ fs:: rename ( funding_consignment_tmp, funding_consignment) . expect ( "rename ok" ) ;
441
+ }
417
442
}
418
443
419
444
/// Handle funding on the receiver side
@@ -437,7 +462,7 @@ pub(crate) fn handle_funding(temporary_channel_id: &[u8; 32], funding_txid: Stri
437
462
blinding_factor : 777 ,
438
463
outpoint,
439
464
close_method : CloseMethod :: OpretFirst ,
440
- witness_vout : false ,
465
+ witness_vout : true ,
441
466
} ) ;
442
467
443
468
let mut rgb_client = get_rgb_node_client ( & ldk_data_dir) ;
0 commit comments