Skip to content

Commit dc3a738

Browse files
committed
add testnet support
1 parent 2c4fbbf commit dc3a738

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

lightning/src/ln/channel.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use crate::chain::chaininterface::{FeeEstimator, ConfirmationTarget, LowerBounde
3838
use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, LATENCY_GRACE_PERIOD_BLOCKS};
3939
use crate::chain::transaction::{OutPoint, TransactionData};
4040
use crate::chain::keysinterface::{Sign, KeysInterface, BaseSign};
41-
use crate::rgb_utils::{color_closing, color_commitment, color_htlc, get_rgb_channel_info, rename_rgbinfo_file, update_rgb_channel_amount};
41+
use crate::rgb_utils::{color_closing, color_commitment, color_htlc, get_rgb_channel_info, rename_rgb_files, update_rgb_channel_amount};
4242
use crate::util::events::ClosureReason;
4343
use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer, VecWriter};
4444
use crate::util::logger::Logger;
@@ -2315,7 +2315,7 @@ impl<Signer: Sign> Channel<Signer> {
23152315
self.channel_state = ChannelState::FundingSent as u32;
23162316
let temporary_channel_id = self.channel_id;
23172317
self.channel_id = funding_txo.to_channel_id();
2318-
rename_rgbinfo_file(&self.channel_id, &temporary_channel_id, &ldk_data_dir);
2318+
rename_rgb_files(&self.channel_id, &temporary_channel_id, &ldk_data_dir);
23192319
self.cur_counterparty_commitment_transaction_number -= 1;
23202320
self.cur_holder_commitment_transaction_number -= 1;
23212321

@@ -5364,7 +5364,7 @@ impl<Signer: Sign> Channel<Signer> {
53645364

53655365
self.channel_state = ChannelState::FundingCreated as u32;
53665366
self.channel_id = funding_txo.to_channel_id();
5367-
rename_rgbinfo_file(&self.channel_id, &temporary_channel_id, &ldk_data_dir);
5367+
rename_rgb_files(&self.channel_id, &temporary_channel_id, &ldk_data_dir);
53685368
self.funding_transaction = Some(funding_transaction);
53695369

53705370
Ok(msgs::FundingCreated {

lightning/src/rgb_utils/mod.rs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
pub mod proxy;
44

5-
use crate::bitcoin::hashes::Hash;
65
use crate::chain::transaction::OutPoint;
76
use crate::ln::PaymentHash;
87
use crate::ln::chan_utils::{BuiltCommitmentTransaction, ClosingTransaction, CommitmentTransaction, HTLCOutputInCommitment};
@@ -15,10 +14,9 @@ use bitcoin::blockdata::transaction::Transaction;
1514
use invoice::ConsignmentEndpoint;
1615
use psbt::{Psbt, PsbtVersion};
1716

18-
use bitcoin::BlockHash;
1917
use bp::seals::txout::CloseMethod;
2018
use internet2::addr::ServiceAddr;
21-
use lnpbp::chain::{Chain, GENESIS_HASH_REGTEST};
19+
use lnpbp::chain::Chain;
2220
use rgb20::Asset as Rgb20Asset;
2321
use rgb::prelude::EndpointValueMap;
2422
use 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+
6580
pub(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

Comments
 (0)