From 25396a9d6929b6404ceddc00c4cad37046bc1cc6 Mon Sep 17 00:00:00 2001 From: Riku Date: Thu, 23 May 2024 18:16:34 +0200 Subject: [PATCH] add support for blockchain.scripthash.unsubscribe --- src/electrum/server.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/electrum/server.rs b/src/electrum/server.rs index c3fc6d072..1071d3f5e 100644 --- a/src/electrum/server.rs +++ b/src/electrum/server.rs @@ -290,6 +290,18 @@ impl Connection { Ok(status_hash) } + fn blockchain_scripthash_unsubscribe(&mut self, params: &[Value]) -> Result { + let script_hash = hash_from_value(params.get(0)).chain_err(|| "bad script_hash")?; + + match self.status_hashes.remove(&script_hash) { + None => Ok(json!(false)), + Some(_) => { + self.stats.subscriptions.dec(); + Ok(json!(true)) + } + } + } + #[cfg(not(feature = "liquid"))] fn blockchain_scripthash_get_balance(&self, params: &[Value]) -> Result { let script_hash = hash_from_value(params.get(0)).chain_err(|| "bad script_hash")?; @@ -430,6 +442,7 @@ impl Connection { "blockchain.scripthash.get_history" => self.blockchain_scripthash_get_history(¶ms), "blockchain.scripthash.listunspent" => self.blockchain_scripthash_listunspent(¶ms), "blockchain.scripthash.subscribe" => self.blockchain_scripthash_subscribe(¶ms), + "blockchain.scripthash.unsubscribe" => self.blockchain_scripthash_unsubscribe(¶ms), "blockchain.transaction.broadcast" => self.blockchain_transaction_broadcast(¶ms), "blockchain.transaction.get" => self.blockchain_transaction_get(¶ms), "blockchain.transaction.get_merkle" => self.blockchain_transaction_get_merkle(¶ms),