Skip to content

Commit

Permalink
make electrs address configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Melnik committed Sep 26, 2019
1 parent 77dd759 commit 7b36e40
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion wallet/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ impl GlobalContext {

pub fn electrs_context(&self, mode: WalletLibraryMode) -> Result<(WalletContext, Mnemonic), Box<dyn Error>> {
let cfg = self.wallet_config.clone();
let (wallet, mnemonic) = ElectrumxWallet::new(cfg, mode)?;
let address = "127.0.0.1:60401".parse().unwrap();
let (wallet, mnemonic) = ElectrumxWallet::new(address, cfg, mode)?;
Ok((WalletContext::Electrs {
wallet: Box::new(wallet),
bitcoind: self.client()?,
Expand Down
10 changes: 7 additions & 3 deletions wallet/src/electrumx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use hex;
use std::{
error::Error,
collections::HashMap,
net::SocketAddr
};

use electrumx_client::{
Expand All @@ -34,7 +35,8 @@ use super::mnemonic::Mnemonic;

pub struct ElectrumxWallet {
pub wallet_lib: Box<dyn WalletLibraryInterface + Send>,
electrumx_client: ElectrumxClient<String>,
electrumx_address: SocketAddr,
electrumx_client: ElectrumxClient<SocketAddr>,
}

impl Wallet for ElectrumxWallet {
Expand All @@ -47,7 +49,7 @@ impl Wallet for ElectrumxWallet {
}

fn reconnect(&mut self) {
self.electrumx_client = ElectrumxClient::new("127.0.0.1:60401".to_string()).unwrap();
self.electrumx_client = ElectrumxClient::new(self.electrumx_address).unwrap();
}

fn send_coins(
Expand Down Expand Up @@ -134,15 +136,17 @@ impl Wallet for ElectrumxWallet {

impl ElectrumxWallet {
pub fn new(
electrumx_address: SocketAddr,
wc: WalletConfig,
mode: WalletLibraryMode,
) -> Result<(ElectrumxWallet, Mnemonic), WalletError> {
let (wallet_lib, mnemonic) = WalletLibrary::new(wc, mode)?;
let electrumx_client = ElectrumxClient::new("127.0.0.1:60401".to_string()).unwrap();
let electrumx_client = ElectrumxClient::new(electrumx_address).unwrap();

Ok((
ElectrumxWallet {
wallet_lib: Box::new(wallet_lib),
electrumx_address,
electrumx_client,
},
mnemonic,
Expand Down

0 comments on commit 7b36e40

Please sign in to comment.