rust-bitcoin / rust-bitcoincore-rpc

Rust RPC client library for the Bitcoin Core JSON-RPC API.
326 stars 244 forks source link

getaddressinfo "labels" field #124

Open justinmoon opened 4 years ago

justinmoon commented 4 years ago

It seems like right now this field contains mixed content:

  "labels" : [                      (json array) Array of labels associated with the address. Currently limited to one label but returned
                                    as an array to keep the API stable if multiple labels are enabled in the future.
    "str",                          (string) The label name. Defaults to "".
    {                               (json object) label data, DEPRECATED, will be removed in 0.21. To re-enable, launch bitcoind with `-deprecatedrpc=labelspurpose`
      "name" : "str",               (string) The label name. Defaults to "".
      "purpose" : "str"             (string) The purpose of the associated address (send or receive).
    },
    ...
  ]

Right now my 0.20 node causes a bad response because rust-bitcoincore-rpc can't interpret the leading "string" value.

stevenroose commented 4 years ago

I think this one is quite possible using the serde untagged enum representation: https://serde.rs/enum-representations.html#untagged

#[derive(Serialize, Deserialize)]
#[serde(untagged)]
pub enum Label {
    #[serde(default)]
    Name(String),
    #[deprecated(note = "will be removed in Bitcoin Core v0.21")]
    Info {
        name: String,
        purpose: String,
    },
}

Or something.