From d8b9c2bdaa02ad38dffeb0208640e50dc09f1327 Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Mon, 18 Sep 2023 11:57:25 +0200 Subject: [PATCH] sdk: add `set_keys` method to `Client` Closes #167 --- crates/nostr-sdk/src/client/blocking.rs | 5 +++++ crates/nostr-sdk/src/client/mod.rs | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/crates/nostr-sdk/src/client/blocking.rs b/crates/nostr-sdk/src/client/blocking.rs index c6520fab8..d501e2422 100644 --- a/crates/nostr-sdk/src/client/blocking.rs +++ b/crates/nostr-sdk/src/client/blocking.rs @@ -74,6 +74,11 @@ impl Client { RUNTIME.block_on(async { self.client.keys().await }) } + /// Change [`Keys`] + pub fn set_keys(&self, keys: &Keys) { + RUNTIME.block_on(async { self.client.set_keys(keys).await }) + } + /// Start a previously stopped client pub fn start(&self) { RUNTIME.block_on(async { self.client.start().await }) diff --git a/crates/nostr-sdk/src/client/mod.rs b/crates/nostr-sdk/src/client/mod.rs index c275b8377..620cb6ac0 100644 --- a/crates/nostr-sdk/src/client/mod.rs +++ b/crates/nostr-sdk/src/client/mod.rs @@ -208,6 +208,12 @@ impl Client { keys.clone() } + /// Change [`Keys`] + pub async fn set_keys(&self, keys: &Keys) { + let mut current_keys = self.keys.write().await; + *current_keys = keys.clone(); + } + /// Get [`RelayPool`] pub fn pool(&self) -> RelayPool { self.pool.clone()