Skip to content

Commit

Permalink
Replace get_chain() with a From trait (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
ok300 authored Mar 26, 2024
1 parent 16a13ef commit 8d2fb76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 10 additions & 0 deletions lib/src/model.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use boltz_client::network::Chain;
use boltz_client::util::error::S5Error;
use lwk_signer::SwSigner;
use lwk_wollet::{ElectrumUrl, ElementsNetwork};
Expand All @@ -17,6 +18,15 @@ impl From<Network> for ElementsNetwork {
}
}

impl From<Network> 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,
Expand Down
15 changes: 4 additions & 11 deletions lib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 8d2fb76

Please sign in to comment.