gui: implement Daemon.update_wallet_metadata() for lianad
This commit is contained in:
parent
6988fa40c9
commit
02e28bbd3e
@ -107,6 +107,25 @@ impl WalletSetting {
|
||||
}
|
||||
map
|
||||
}
|
||||
|
||||
pub fn update_alias(&mut self, key: &Fingerprint, alias: &str) {
|
||||
let key_aliases = self.keys_aliases();
|
||||
if key_aliases.contains_key(key) {
|
||||
self.keys = self
|
||||
.keys
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|mut ks| {
|
||||
if ks.master_fingerprint == *key {
|
||||
ks.name = alias.into();
|
||||
ks
|
||||
} else {
|
||||
ks
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)]
|
||||
|
||||
@ -21,6 +21,7 @@ use lianad::{
|
||||
StartupError,
|
||||
};
|
||||
|
||||
use crate::app::settings::Settings;
|
||||
use crate::{hw::HardwareWalletConfig, node};
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -364,12 +365,33 @@ pub trait Daemon: Debug {
|
||||
Ok(events)
|
||||
}
|
||||
|
||||
/// Implemented by LianaLite backend
|
||||
/// Reimplemented by LianaLite backend
|
||||
async fn update_wallet_metadata(
|
||||
&self,
|
||||
_fingerprint_aliases: &HashMap<Fingerprint, String>,
|
||||
fingerprint_aliases: &HashMap<Fingerprint, String>,
|
||||
_hws: &[HardwareWalletConfig],
|
||||
) -> Result<(), DaemonError> {
|
||||
if let Some(datadir) = self
|
||||
.config()
|
||||
.ok_or(DaemonError::Unexpected("Config missing".into()))?
|
||||
.data_dir()
|
||||
{
|
||||
let network = self.get_info().await?.network;
|
||||
let mut settings = Settings::from_file(datadir, network)
|
||||
.map_err(|_| DaemonError::Unexpected("Fail to read Settings from file".into()))?;
|
||||
let wallet = if settings.wallets.len() == 1 {
|
||||
settings.wallets.get_mut(0).expect("already checked")
|
||||
} else {
|
||||
return Err(DaemonError::Unexpected(
|
||||
"Settings file contains more than one wallet".into(),
|
||||
));
|
||||
};
|
||||
for fg in wallet.keys_aliases().keys() {
|
||||
if fingerprint_aliases.contains_key(fg) {
|
||||
wallet.update_alias(fg, fingerprint_aliases.get(fg).expect("checked"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user