Skip to content

Fix unloadwallet RPC result parsing. #290

@LimpSquid

Description

@LimpSquid

Summary

The unloadwallet RPC returns a JSON object for newer versions of Bitcoin Core. The RPC API is changed since this commit:

bitcoin/bitcoin@642ad31#diff-63c7710d72381cffe692175dd70e47f1891bf75c3e09249ed826f9df3917d02dR2693

Steps to reproduce

  • Run a recent version of Bitcoin core for example 0.21.0.
  • Execute the unloadwallet RPC. Now the following error is returned (which originates from serde): invalid type: map, expected unit.

Current behavior

The unload wallet RPC returns an error for newer versions of Bitcoin core which return a JSON object as described here: https://developer.bitcoin.org/reference/rpc/unloadwallet.html

Expected behavior

Properly parse the result for both the old and new RPC API.

Proposed solution

diff --git a/client/src/client.rs b/client/src/client.rs
index cb242ec..1d705d2 100644
--- a/client/src/client.rs
+++ b/client/src/client.rs
@@ -272,7 +272,7 @@ pub trait RpcApi: Sized {
         self.call("loadwallet", &[wallet.into()])
     }
 
-    fn unload_wallet(&self, wallet: Option<&str>) -> Result<()> {
+    fn unload_wallet(&self, wallet: Option<&str>) -> Result<Option<json::UnloadWalletResult>> {
         let mut args = [opt_into_json(wallet)?];
         self.call("unloadwallet", handle_defaults(&mut args, &[null()]))
     }
diff --git a/json/src/lib.rs b/json/src/lib.rs
index 258c6b7..db3129e 100644
--- a/json/src/lib.rs
+++ b/json/src/lib.rs
@@ -134,6 +134,11 @@ pub struct LoadWalletResult {
     pub warning: Option<String>,
 }
 
+#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
+pub struct UnloadWalletResult {
+    pub warning: Option<String>,
+}
+
 #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
 pub struct ListWalletDirResult {
     pub wallets: Vec<ListWalletDirItem>,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions