bitcoind_request/command/
get_block_count.rs

1/*
2getblockcount
3
4Returns the height of the most-work fully-validated chain.
5The genesis block has height 0.
6
7Result:
8n    (numeric) The current block count
9
10Examples:
11> bitcoin-cli getblockcount
12> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getblockcount", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
13*/
14use crate::command::CallableCommand;
15use crate::{client::Client, command::request::request};
16use serde::{Deserialize, Serialize};
17use serde_json::value::RawValue;
18
19pub struct GetBlockCountCommand {}
20impl GetBlockCountCommand {
21    pub fn new() -> Self {
22        GetBlockCountCommand {}
23    }
24}
25
26#[derive(Serialize, Deserialize, Debug)]
27pub struct GetBlockCountCommandResponse(pub u64);
28
29impl CallableCommand for GetBlockCountCommand {
30    type Response = GetBlockCountCommandResponse;
31    fn call(&self, client: &Client) -> Result<Self::Response, jsonrpc::Error> {
32        let command = "getblockcount";
33        let params: Vec<Box<RawValue>> = vec![];
34        let r = request(client, command, params);
35        let response: GetBlockCountCommandResponse = r.result()?;
36        Ok(response)
37    }
38}