bitcoind_request/command/
get_block_hash.rs1use crate::command::CallableCommand;
17use crate::Blockhash;
18use crate::{client::Client, command::request::request};
19use serde::{Deserialize, Serialize};
20use serde_json::value::{to_raw_value, RawValue};
21
22type BlockHeight = u64;
23pub struct GetBlockHashCommand {
24 height: BlockHeight,
25}
26impl GetBlockHashCommand {
27 pub fn new(height: BlockHeight) -> Self {
28 GetBlockHashCommand { height }
29 }
30}
31#[derive(Serialize, Deserialize, Debug)]
33pub struct GetBlockHashCommandResponse(pub Blockhash);
34
35impl CallableCommand for GetBlockHashCommand {
36 type Response = GetBlockHashCommandResponse;
37 fn call(&self, client: &Client) -> Result<Self::Response, jsonrpc::Error> {
38 let height_arg = &self.height;
39 let height_arg_raw_value = to_raw_value(height_arg).unwrap();
40 let command = "getblockhash";
41 let params = vec![height_arg_raw_value];
42 let r = request(client, command, params);
43 let response: GetBlockHashCommandResponse = r.result()?;
44 Ok(response)
45 }
46}