Skip to content

Commit

Permalink
Use exe config instead of exe path in context
Browse files Browse the repository at this point in the history
  • Loading branch information
jp1ac4 committed Aug 16, 2023
1 parent 00daeba commit 2d94902
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
5 changes: 3 additions & 2 deletions gui/src/installer/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::time::Duration;

use crate::{
app::{
config::InternalBitcoindExeConfig,
settings::{KeySetting, Settings, WalletSetting},
wallet::DEFAULT_WALLET_NAME,
},
Expand Down Expand Up @@ -33,7 +34,7 @@ pub struct Context {
// we dont want to override the generated signer with it.
pub recovered_signer: Option<Arc<Signer>>,
pub internal_bitcoind_config: Option<InternalBitcoindConfig>,
pub internal_bitcoind_exe_path: Option<PathBuf>,
pub internal_bitcoind_exe_config: Option<InternalBitcoindExeConfig>,
}

impl Context {
Expand All @@ -51,7 +52,7 @@ impl Context {
hw_is_used: false,
recovered_signer: None,
internal_bitcoind_config: None,
internal_bitcoind_exe_path: None,
internal_bitcoind_exe_config: None,
}
}

Expand Down
13 changes: 1 addition & 12 deletions gui/src/installer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,25 +322,14 @@ pub async fn install(ctx: Context, signer: Arc<Mutex<Signer>>) -> Result<PathBuf
}

// create liana GUI configuration file
let exe_config = if let Some(exe_path) = ctx.internal_bitcoind_exe_path.clone() {
let data_dir = internal_bitcoind_datadir(&ctx.data_dir)
.canonicalize()
.map_err(|e| {
Error::Unexpected(format!("Failed to canonicalize bitcoind data dir: {}", e))
})?;
Some(InternalBitcoindExeConfig { exe_path, data_dir })
} else {
None
};

let gui_config_path = create_and_write_file(
network_datadir_path.clone(),
gui_config::DEFAULT_FILE_NAME,
toml::to_string(&gui_config::Config::new(
daemon_config_path.canonicalize().map_err(|e| {
Error::Unexpected(format!("Failed to canonicalize daemon config path: {}", e))
})?,
exe_config,
ctx.internal_bitcoind_exe_config.clone(),
))
.map_err(|e| Error::Unexpected(format!("Failed to serialize gui config: {}", e)))?
.as_bytes(),
Expand Down
19 changes: 8 additions & 11 deletions gui/src/installer/step/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub struct StartInternalBitcoindStep {
exe_path: Option<PathBuf>,
rpc_port: Option<u16>,
bitcoind_config: Option<BitcoindConfig>,
exe_config: Option<InternalBitcoindExeConfig>,
}

#[derive(PartialEq, Eq, Debug, Clone)]
Expand Down Expand Up @@ -453,7 +454,7 @@ impl Step for SelectBitcoindTypeStep {
}
}
ctx.internal_bitcoind_config = None;
ctx.internal_bitcoind_exe_path = None;
ctx.internal_bitcoind_exe_config = None;
}
self.error = None;
true
Expand Down Expand Up @@ -601,15 +602,16 @@ impl StartInternalBitcoindStep {
exe_path: None,
rpc_port: None,
bitcoind_config: None,
exe_config: None,
}
}
}

impl Step for StartInternalBitcoindStep {
fn load_context(&mut self, ctx: &Context) {
if self.exe_path.is_none() {
self.exe_path = if ctx.internal_bitcoind_exe_path.is_some() {
ctx.internal_bitcoind_exe_path.clone()
self.exe_path = if let Some(exe_config) = ctx.internal_bitcoind_exe_config.clone() {
Some(exe_config.exe_path)
} else {
bitcoind_exe_path()
};
Expand Down Expand Up @@ -652,7 +654,7 @@ impl Step for StartInternalBitcoindStep {
exe_path: path.to_path_buf(),
data_dir: datadir,
};
if let Err(e) = start_internal_bitcoind(&self.network, exe_config) {
if let Err(e) = start_internal_bitcoind(&self.network, exe_config.clone()) {
self.started =
Some(Err(StartInternalBitcoindError::CommandError(e.to_string())));
return Command::none();
Expand Down Expand Up @@ -689,6 +691,7 @@ impl Step for StartInternalBitcoindStep {
) {
Ok(_) => {
self.bitcoind_config = Some(bitcoind_config);
self.exe_config = Some(exe_config);
self.started = Some(Ok(()));
// Apply changes so that context is updated in case user selects "Previous".
return Command::perform(async {}, |_| Message::Apply);
Expand Down Expand Up @@ -719,13 +722,7 @@ impl Step for StartInternalBitcoindStep {
// Any errors have been handled as part of `message::StartInternalBitcoindMsg::Start`
if let Some(Ok(_)) = self.started {
ctx.bitcoind_config = self.bitcoind_config.clone();
ctx.internal_bitcoind_exe_path = Some(
self.exe_path
.clone()
.expect("Already added")
.canonicalize()
.expect("Failed to canonicalize exe path."),
);
ctx.internal_bitcoind_exe_config = self.exe_config.clone();
return true;
}
false
Expand Down

0 comments on commit 2d94902

Please sign in to comment.