From 709b045384c3e5b7c28a948eea02b2e4bbc3f806 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Fri, 22 Mar 2024 13:23:19 +0100 Subject: [PATCH] Replace get_chain() with a From trait --- lib/src/model.rs | 10 ++++++++++ lib/src/wallet.rs | 15 ++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/src/model.rs b/lib/src/model.rs index 6d1584e98..a1efa528a 100644 --- a/lib/src/model.rs +++ b/lib/src/model.rs @@ -1,3 +1,4 @@ +use boltz_client::network::Chain; use boltz_client::util::error::S5Error; use lwk_signer::SwSigner; use lwk_wollet::{ElectrumUrl, ElementsNetwork}; @@ -17,6 +18,15 @@ impl From for ElementsNetwork { } } +impl From for Chain { + fn from(value: Network) -> Self { + match value { + Network::Liquid => Chain::Liquid, + Network::LiquidTestnet => Chain::LiquidTestnet, + } + } +} + pub struct WalletOptions { pub signer: SwSigner, pub network: Network, diff --git a/lib/src/wallet.rs b/lib/src/wallet.rs index 0a28f9b8c..d4447f5b4 100644 --- a/lib/src/wallet.rs +++ b/lib/src/wallet.rs @@ -7,7 +7,7 @@ use std::{ use anyhow::{anyhow, Result}; use boltz_client::{ - network::{electrum::ElectrumConfig, Chain}, + network::electrum::ElectrumConfig, swaps::{ boltz::{BoltzApiClient, CreateSwapRequest, BOLTZ_MAINNET_URL, BOLTZ_TESTNET_URL}, liquid::{LBtcSwapScript, LBtcSwapTx}, @@ -160,16 +160,9 @@ impl Wallet { BoltzApiClient::new(base_url) } - fn get_chain(&self) -> Chain { - match self.network { - Network::Liquid => Chain::Liquid, - Network::LiquidTestnet => Chain::LiquidTestnet, - } - } - fn get_network_config(&self) -> ElectrumConfig { ElectrumConfig::new( - self.get_chain(), + self.network.into(), &self.electrum_url.to_string(), true, false, @@ -255,7 +248,7 @@ impl Wallet { let mnemonic = self.signer.mnemonic(); let swap_key = - SwapKey::from_reverse_account(&mnemonic.to_string(), "", self.get_chain(), 0)?; + SwapKey::from_reverse_account(&mnemonic.to_string(), "", self.network.into(), 0)?; let lsk = LiquidSwapKey::from(swap_key); @@ -289,7 +282,7 @@ impl Wallet { let mnemonic = self.signer.mnemonic(); let swap_key = - SwapKey::from_reverse_account(&mnemonic.to_string(), "", self.get_chain(), 0)?; + SwapKey::from_reverse_account(&mnemonic.to_string(), "", self.network.into(), 0)?; let lsk = LiquidSwapKey::from(swap_key); let preimage = Preimage::new();