gui: include node type in embedded daemon backend

This is for convenience in case we need to know the node type
being used.

Although we expect there to always be a node type, it is kept as
`Option` to be consistent with the daemon config.
This commit is contained in:
Michael Mallan 2024-10-21 10:25:45 +01:00
parent 67c9262a30
commit f34bb1b79a
No known key found for this signature in database
GPG Key ID: 5177CDCEDB0EABEB
6 changed files with 29 additions and 8 deletions

View File

@ -242,7 +242,7 @@ impl App {
pub fn stop(&mut self) {
info!("Close requested");
if self.daemon.backend() == DaemonBackend::EmbeddedLianad {
if self.daemon.backend().is_embedded() {
if let Err(e) = Handle::current().block_on(async { self.daemon.stop().await }) {
error!("{}", e);
} else {

View File

@ -62,7 +62,7 @@ impl State for SettingsState {
BitcoindSettingsState::new(
daemon.config().cloned(),
cache,
daemon.backend() != DaemonBackend::EmbeddedLianad,
!daemon.backend().is_embedded(),
self.internal_bitcoind,
)
.into(),

View File

@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet};
use std::path::Path;
use tokio::sync::Mutex;
use super::{model::*, Daemon, DaemonBackend, DaemonError};
use super::{model::*, node, Daemon, DaemonBackend, DaemonError};
use async_trait::async_trait;
use liana::{
commands::{CoinStatus, LabelItem},
@ -51,7 +51,12 @@ impl std::fmt::Debug for EmbeddedDaemon {
#[async_trait]
impl Daemon for EmbeddedDaemon {
fn backend(&self) -> DaemonBackend {
DaemonBackend::EmbeddedLianad
let node_type = self
.config
.bitcoin_backend
.as_ref()
.map(node::NodeType::from);
DaemonBackend::EmbeddedLianad(node_type)
}
fn config(&self) -> Option<&Config> {

View File

@ -20,7 +20,7 @@ use liana::{
StartupError,
};
use crate::hw::HardwareWalletConfig;
use crate::{hw::HardwareWalletConfig, node};
#[derive(Debug)]
pub enum DaemonError {
@ -62,11 +62,17 @@ impl std::fmt::Display for DaemonError {
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DaemonBackend {
EmbeddedLianad,
EmbeddedLianad(Option<node::NodeType>),
ExternalLianad,
RemoteBackend,
}
impl DaemonBackend {
pub fn is_embedded(&self) -> bool {
matches!(self, DaemonBackend::EmbeddedLianad(_))
}
}
#[async_trait]
pub trait Daemon: Debug {
fn backend(&self) -> DaemonBackend;

View File

@ -22,7 +22,6 @@ use liana_ui::{
widget::*,
};
use crate::daemon::DaemonBackend;
use crate::{
app::{
cache::Cache,
@ -227,7 +226,7 @@ impl Loader {
pub fn stop(&mut self) {
info!("Close requested");
if let Step::Syncing { daemon, .. } = &mut self.step {
if daemon.backend() == DaemonBackend::EmbeddedLianad {
if daemon.backend().is_embedded() {
info!("Stopping internal daemon...");
if let Err(e) = Handle::current().block_on(async { daemon.stop().await }) {
warn!("Internal daemon failed to stop: {}", e);

View File

@ -1,3 +1,5 @@
use liana::config::BitcoinBackend;
pub mod bitcoind;
pub mod electrum;
@ -6,3 +8,12 @@ pub enum NodeType {
Bitcoind,
Electrum,
}
impl From<&BitcoinBackend> for NodeType {
fn from(bitcoin_backend: &BitcoinBackend) -> Self {
match bitcoin_backend {
BitcoinBackend::Bitcoind(_) => Self::Bitcoind,
BitcoinBackend::Electrum(_) => Self::Electrum,
}
}
}