22
33pub mod proxy;
44
5- use crate :: bitcoin:: hashes:: Hash ;
65use crate :: chain:: transaction:: OutPoint ;
76use crate :: ln:: PaymentHash ;
87use crate :: ln:: chan_utils:: { BuiltCommitmentTransaction , ClosingTransaction , CommitmentTransaction , HTLCOutputInCommitment } ;
@@ -15,10 +14,9 @@ use bitcoin::blockdata::transaction::Transaction;
1514use invoice:: ConsignmentEndpoint ;
1615use psbt:: { Psbt , PsbtVersion } ;
1716
18- use bitcoin:: BlockHash ;
1917use bp:: seals:: txout:: CloseMethod ;
2018use internet2:: addr:: ServiceAddr ;
21- use lnpbp:: chain:: { Chain , GENESIS_HASH_REGTEST } ;
19+ use lnpbp:: chain:: Chain ;
2220use rgb20:: Asset as Rgb20Asset ;
2321use rgb:: prelude:: EndpointValueMap ;
2422use rgb:: psbt:: { RgbExt , RgbInExt } ;
@@ -62,12 +60,30 @@ pub struct RgbPaymentInfo {
6260 pub remote_rgb_amount : u64 ,
6361}
6462
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+
6580pub ( crate ) fn get_rgb_node_client ( ldk_data_dir : & PathBuf ) -> Client {
6681 let port_str = fs:: read_to_string ( ldk_data_dir. join ( "rgb_node_port" ) ) . expect ( "able to read" ) ;
6782 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 ( ) ;
6885 let ip = Ipv4Addr :: new ( 127 , 0 , 0 , 1 ) ;
6986 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" ) ) ;
7187 Client :: with ( rgb_node_endpoint, "rgb-ln-node" . to_string ( ) , rgb_network)
7288 . expect ( "Error initializing client" )
7389}
@@ -409,11 +425,20 @@ pub fn write_rgb_channel_info(path: &PathBuf, rgb_info: &RgbInfo) {
409425 fs:: write ( path, serialized_info) . expect ( "able to write" )
410426}
411427
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) ;
416435 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+ }
417442}
418443
419444/// Handle funding on the receiver side
@@ -437,7 +462,7 @@ pub(crate) fn handle_funding(temporary_channel_id: &[u8; 32], funding_txid: Stri
437462 blinding_factor : 777 ,
438463 outpoint,
439464 close_method : CloseMethod :: OpretFirst ,
440- witness_vout : false ,
465+ witness_vout : true ,
441466 } ) ;
442467
443468 let mut rgb_client = get_rgb_node_client ( & ldk_data_dir) ;
0 commit comments