bitcoind_request/command/
get_best_block_hash.rs1use crate::client::Client;
2use crate::command::request::request;
15use crate::command::CallableCommand;
16use crate::Blockhash;
17use crate::BlockhashHexEncoded;
18use serde::Deserialize;
19use serde::Serialize;
20use serde_json::value::{to_raw_value, RawValue};
21
22pub struct GetBestBlockHashCommand {
23 blockhash_hex_encoded: BlockhashHexEncoded,
24}
25impl GetBestBlockHashCommand {
26 pub fn new(blockhash_hex_encoded: BlockhashHexEncoded) -> Self {
27 GetBestBlockHashCommand {
28 blockhash_hex_encoded,
29 }
30 }
31}
32#[derive(Serialize, Deserialize, Debug)]
33pub struct GetBestBlockHashCommandResponse(pub Blockhash);
34
35impl CallableCommand for GetBestBlockHashCommand {
36 type Response = GetBestBlockHashCommandResponse;
37 fn call(&self, client: &Client) -> Result<Self::Response, jsonrpc::Error> {
38 let blockhash_arg = &self.blockhash_hex_encoded.0;
39 let command = "getbestblockhash";
40 let params: Vec<Box<RawValue>> = vec![];
41 let r = request(client, command, params);
42 let response: GetBestBlockHashCommandResponse = r.result()?;
43 Ok(response)
44 }
45}