Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network folders even for mainnet #157

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions harbor-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@ use tokio::sync::RwLock;
use uuid::Uuid;

/// The directory where all application data is stored
/// Defaults to ~/.harbor, if we're on a test network
/// Otherwise defaults to ~/.harbor/<network>
pub fn data_dir(network: Network) -> PathBuf {
/// Defaults to ~/.harbor as the root directory
/// Network-specific data goes in ~/.harbor/<network>
pub fn data_dir(network: Option<Network>) -> PathBuf {
let home = home::home_dir().expect("Could not find home directory");
let default = home.join(".harbor");
match network {
Network::Bitcoin => default,
Network::Testnet => default.join("testnet3"),
Network::Testnet4 => default.join("testnet4"),
Network::Regtest => default.join("regtest"),
Network::Signet => default.join("signet"),
_ => panic!("Invalid network"),
let root = home.join(".harbor");
if let Some(network) = network {
match network {
Network::Bitcoin => root.join("bitcoin"),
Network::Testnet => root.join("testnet3"),
Network::Testnet4 => root.join("testnet4"),
Network::Regtest => root.join("regtest"),
Network::Signet => root.join("signet"),
_ => panic!("Invalid network"),
}
} else {
root
}
}

Expand Down Expand Up @@ -305,11 +309,12 @@ impl HarborCore {
let lightning_module = client
.get_first_module::<LightningClientModule>()
.expect("must have ln module");
log::info!("Lightning module: {:?}", lightning_module.id);

let gateway = select_gateway(&client)
.await
.ok_or(anyhow!("Internal error: No gateway found for federation"))?;

log::info!("Gateway: {gateway:?}");
let desc = Description::new(String::new()).expect("empty string is valid");
let (op_id, invoice, preimage) = lightning_module
.create_bolt11_invoice(
Expand Down
4 changes: 2 additions & 2 deletions harbor-ui/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ pub fn run_core() -> impl Stream<Item = Message> {
.await
.expect("should send");

// Create the datadir if it doesn't exist
let path = PathBuf::from(&data_dir(network));
// Create the network-specific datadir if it doesn't exist
let path = PathBuf::from(&data_dir(Some(network)));
std::fs::create_dir_all(&path).expect("Could not create datadir");
log::info!("Using datadir: {path:?}");

Expand Down
4 changes: 2 additions & 2 deletions harbor-ui/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Default for Config {

pub fn read_config() -> anyhow::Result<Config> {
// Create the datadir if it doesn't exist
let root = PathBuf::from(&data_dir(Network::Bitcoin));
let root = PathBuf::from(&data_dir(None));
std::fs::create_dir_all(&root).expect("Could not create datadir");

let config_path = root.join("harbor.config.json");
Expand All @@ -42,7 +42,7 @@ pub fn read_config() -> anyhow::Result<Config> {
}

pub fn write_config(config: &Config) -> anyhow::Result<()> {
let root = PathBuf::from(&data_dir(Network::Bitcoin));
let root = PathBuf::from(&data_dir(None));
let config_path = root.join("harbor.config.json");

std::fs::create_dir_all(&root).expect("Could not create datadir");
Expand Down
12 changes: 12 additions & 0 deletions harbor-ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,18 @@ impl HarborWallet {

write_config(&new_config).expect("Failed to write config");

// Relaunch the app
use std::env;
use std::process::Command;

let args: Vec<String> = env::args().collect();
let executable = &args[0];

Command::new(executable)
.args(&args[1..])
.spawn()
.expect("Failed to relaunch");

std::process::exit(0);
}
Message::Batch(messages) => {
Expand Down
2 changes: 1 addition & 1 deletion harbor-ui/src/routes/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn settings(harbor: &HarborWallet) -> Element<Message> {
Message::SetConfirmModal(Some(crate::components::ConfirmModalState {
title: "Are you sure?".to_string(),
description: format!(
"Changing network requires a restart, are you sure you want to change to {net}"
"Changing network requires a restart, are you sure you want to change to {net}?"
),
confirm_action: Box::new(Message::ChangeNetwork(net)),
cancel_action: Box::new(Message::SetConfirmModal(None)),
Expand Down
Loading