bitcoind_request/command/
get_difficulty.rs

1/*
2getdifficulty
3
4Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
5
6Result:
7n    (numeric) the proof-of-work difficulty as a multiple of the minimum difficulty.
8
9Examples:
10> bitcoin-cli getdifficulty
11> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getdifficulty", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
12*/
13use crate::command::CallableCommand;
14use crate::{client::Client, command::request::request};
15use serde::{Deserialize, Serialize};
16
17const GET_DIFFICULTY_COMMAND: &str = "getdifficulty";
18
19pub struct GetDifficultyCommand {}
20impl GetDifficultyCommand {
21    pub fn new() -> Self {
22        GetDifficultyCommand {}
23    }
24}
25// TODO: struct GetDifficultyCommandResponse(String);
26#[derive(Serialize, Deserialize, Debug)]
27pub struct GetDifficultyCommandResponse(pub f64);
28
29impl CallableCommand for GetDifficultyCommand {
30    type Response = GetDifficultyCommandResponse;
31    fn call(&self, client: &Client) -> Result<Self::Response, jsonrpc::Error> {
32        let params = vec![];
33        let r = request(client, GET_DIFFICULTY_COMMAND, params);
34        let response: GetDifficultyCommandResponse = r.result()?;
35        Ok(response)
36    }
37}