diff --git a/src/bin/cashierd.rs b/src/bin/cashierd.rs index cd6a6d8c3..78c61265f 100644 --- a/src/bin/cashierd.rs +++ b/src/bin/cashierd.rs @@ -32,7 +32,9 @@ use drk::{ fn handle_bridge_error(error_code: u32) -> Result<()> { match error_code { 1 => Err(Error::BridgeError("Not Supported Client".into())), - 2 => Err(Error::BridgeError("Unable to watch the deposit address".into())), + 2 => Err(Error::BridgeError( + "Unable to watch the deposit address".into(), + )), 3 => Err(Error::BridgeError("Unable to send the token".into())), _ => Err(Error::BridgeError("Unknown error_code".into())), } @@ -505,7 +507,7 @@ impl Cashierd { } let sol_client = - SolClient::new(serialize(&main_keypair), &network.blockchain).await?; + SolClient::new(main_keypair, &network.blockchain).await?; bridge2.add_clients(NetworkName::Solana, sol_client).await?; } @@ -513,7 +515,7 @@ impl Cashierd { #[cfg(feature = "btc")] NetworkName::Bitcoin => { debug!(target: "CASHIER DAEMON", "Add btc network"); - use drk::service::btc::{BtcClient, Keypair}; + use drk::service::btc::{BtcClient, Keypair, BtcFailed}; let bridge2 = self.bridge.clone(); @@ -521,19 +523,28 @@ impl Cashierd { let main_keypairs = self.cashier_wallet.get_main_keys(&NetworkName::Bitcoin)?; - if main_keypairs.is_empty() { - main_keypair = Keypair::new(); - self.cashier_wallet.put_main_keys( - &serialize(&main_keypair), - &serialize(&main_keypair.pubkey()), - &NetworkName::Bitcoin, - )?; + if network.keypair.is_empty() { + if main_keypairs.is_empty() { + main_keypair = Keypair::new(); + self.cashier_wallet.put_main_keys( + &serialize(&main_keypair), + &serialize(&main_keypair.pubkey()), + &NetworkName::Bitcoin, + )?; + } else { + main_keypair = deserialize(&main_keypairs[main_keypairs.len() - 1].0)?; + } } else { - main_keypair = deserialize(&main_keypairs[main_keypairs.len() - 1].0)?; + let keypair_str = drk::cli::cli_config::load_keypair_to_str( + PathBuf::from(expand_path(&network.keypair.clone())?), + )?; + let keypair_bytes: Vec = serde_json::from_str(&keypair_str)?; + main_keypair = Keypair::from_bytes(&keypair_bytes) + .map_err(|e| BtcFailed::DecodeAndEncodeError(e.to_string()))?; } let btc_client = - BtcClient::new(serialize(&main_keypair), &network.blockchain).await?; + BtcClient::new(main_keypair, &network.blockchain).await?; bridge2 .add_clients(NetworkName::Bitcoin, btc_client) diff --git a/src/bin/darkfid.rs b/src/bin/darkfid.rs index 5f36af717..d374fae23 100644 --- a/src/bin/darkfid.rs +++ b/src/bin/darkfid.rs @@ -213,7 +213,7 @@ impl Darkfid { async fn features(&self, id: Value, _params: Value) -> JsonResult { let req = jsonreq(json!("features"), json!([])); let rep: JsonResult; - // TODO: this just selects the first cashier in the list + // NOTE: this just selects the first cashier in the list match send_request(&self.cashiers[0].rpc_url, json!(req)).await { Ok(v) => rep = v, Err(e) => { diff --git a/src/service/btc.rs b/src/service/btc.rs index a0e785588..3c9b0bb62 100644 --- a/src/service/btc.rs +++ b/src/service/btc.rs @@ -168,8 +168,7 @@ pub struct BtcClient { } impl BtcClient { - pub async fn new(main_keypair: Vec, network: &str) -> Result> { - let main_keypair: Keypair = deserialize(&main_keypair)?; + pub async fn new(main_keypair: Keypair, network: &str) -> Result> { let notify_channel = async_channel::unbounded(); diff --git a/src/service/sol.rs b/src/service/sol.rs index 89b3be29d..baa46f34c 100644 --- a/src/service/sol.rs +++ b/src/service/sol.rs @@ -50,8 +50,7 @@ pub struct SolClient { } impl SolClient { - pub async fn new(main_keypair: Vec, network: &str) -> Result> { - let main_keypair: Keypair = deserialize(&main_keypair)?; + pub async fn new(main_keypair: Keypair, network: &str) -> Result> { let notify_channel = async_channel::unbounded(); info!(target: "SOL BRIDGE", "Main SOL wallet pubkey: {:?}", &main_keypair.pubkey());