Skip to content

Commit

Permalink
wollet: add EsploraClient::set_waterfalls_server_recipient
Browse files Browse the repository at this point in the history
some setups may re-create the client, causing every time to ask the
static server recipient to encrypt descriptors. By allowing a method to
set it clients can avoid that roundtrip.
  • Loading branch information
RCasatta committed Dec 12, 2024
1 parent b0c13ff commit 6db2175
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lwk_wasm/src/esplora.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{Error, Network, Pset, Txid, Update, Wollet};
use lwk_wollet::clients::asyncr;
use lwk_wollet::{age, clients::asyncr};
use wasm_bindgen::prelude::*;

/// Wrapper of [`asyncr::EsploraClient`]
Expand Down Expand Up @@ -28,6 +28,14 @@ impl EsploraClient {
let txid = self.inner.broadcast(&(tx.into())).await?;
Ok(txid.into())
}

pub async fn set_waterfalls_server_recipient(&mut self, recipient: &str) -> Result<(), Error> {
let recipient: age::x25519::Recipient = recipient
.parse()
.map_err(|e: &str| Error::Generic(e.to_string()))?;
self.inner.set_waterfalls_server_recipient(recipient);
Ok(())
}
}

#[cfg(all(test, target_arch = "wasm32"))]
Expand Down
4 changes: 4 additions & 0 deletions lwk_wollet/src/clients/asyncr/esplora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ impl EsploraClient {
self.waterfalls_avoid_encryption = true;
}

pub fn set_waterfalls_server_recipient(&mut self, recipient: Recipient) {
self.waterfalls_server_recipient = Some(recipient);
}

async fn download_txs(
&self,
history_txs_id: &HashSet<Txid>,
Expand Down
4 changes: 4 additions & 0 deletions lwk_wollet/src/clients/blocking/esplora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ impl EsploraClient {
pub fn waterfalls_server_recipient(&mut self) -> Result<Recipient, Error> {
self.rt.block_on(self.client.waterfalls_server_recipient())
}

pub fn set_waterfalls_server_recipient(&mut self, recipient: Recipient) {
self.client.set_waterfalls_server_recipient(recipient);
}
}

impl BlockchainBackend for EsploraClient {
Expand Down

0 comments on commit 6db2175

Please sign in to comment.