Merge #932: Reset bitcoind default settings on network change

8146269296bd1a6a638c726be7b2b5c53d9ff730 Reset bitcoind default settings on network change (edouardparis)

Pull request description:

  close #812

ACKs for top commit:
  edouardparis:
    Self-ACK 8146269296bd1a6a638c726be7b2b5c53d9ff730

Tree-SHA512: 359ea05c663b76615fcae2ecde8e1c63a0345db92e498d4d57b373eab04d6fcb40a46382314caf8edc58c25aae84956e41ee6bfc465a74f91b4f15aaa40d07ed
This commit is contained in:
edouardparis 2024-01-23 16:44:26 +01:00
commit e671e508ef
No known key found for this signature in database
GPG Key ID: E65F7A089C20DC8F

View File

@ -472,6 +472,9 @@ pub struct DefineBitcoind {
selected_auth_type: RpcAuthType, selected_auth_type: RpcAuthType,
address: form::Value<String>, address: form::Value<String>,
is_running: Option<Result<(), Error>>, is_running: Option<Result<(), Error>>,
// Internal cache to detect network change.
network: Option<Network>,
} }
impl DefineBitcoind { impl DefineBitcoind {
@ -481,6 +484,7 @@ impl DefineBitcoind {
selected_auth_type: RpcAuthType::CookieFile, selected_auth_type: RpcAuthType::CookieFile,
address: form::Value::default(), address: form::Value::default(),
is_running: None, is_running: None,
network: None,
} }
} }
@ -520,13 +524,21 @@ impl DefineBitcoind {
impl Step for DefineBitcoind { impl Step for DefineBitcoind {
fn load_context(&mut self, ctx: &Context) { fn load_context(&mut self, ctx: &Context) {
if self.rpc_auth_vals.cookie_path.value.is_empty() { if self.rpc_auth_vals.cookie_path.value.is_empty()
// if network changed then the values must be reset to default.
|| self.network != Some(ctx.bitcoin_config.network)
{
self.rpc_auth_vals.cookie_path.value = self.rpc_auth_vals.cookie_path.value =
bitcoind_default_cookie_path(&ctx.bitcoin_config.network).unwrap_or_default() bitcoind_default_cookie_path(&ctx.bitcoin_config.network).unwrap_or_default()
} }
if self.address.value.is_empty() { if self.address.value.is_empty()
// if network changed then the values must be reset to default.
|| self.network != Some(ctx.bitcoin_config.network)
{
self.address.value = bitcoind_default_address(&ctx.bitcoin_config.network); self.address.value = bitcoind_default_address(&ctx.bitcoin_config.network);
} }
self.network = Some(ctx.bitcoin_config.network);
} }
fn update(&mut self, _hws: &mut HardwareWallets, message: Message) -> Command<Message> { fn update(&mut self, _hws: &mut HardwareWallets, message: Message) -> Command<Message> {
if let Message::DefineBitcoind(msg) = message { if let Message::DefineBitcoind(msg) = message {