Skip to content

Commit

Permalink
Merge pull request #157 from HarborWallet/network-config-pauls-vision
Browse files Browse the repository at this point in the history
network folders even for mainnet
  • Loading branch information
benthecarman authored Feb 1, 2025
2 parents 8218e0b + af1db9b commit 3e445c1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
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

0 comments on commit 3e445c1

Please sign in to comment.