bitcoind_request/command/get_tx_out_set_info.rs
1/*
2gettxoutsetinfo ( "hash_type" )
3
4Returns statistics about the unspent transaction output set.
5Note this call may take some time.
6
7Arguments:
81. hash_type (string, optional, default=hash_serialized_2) Which UTXO set hash should be calculated. Options: 'hash_serialized_2' (the legacy algorithm), 'none'.
9
10Result:
11{ (json object)
12 "height" : n, (numeric) The current block height (index)
13 "bestblock" : "hex", (string) The hash of the block at the tip of the chain
14 "transactions" : n, (numeric) The number of transactions with unspent outputs
15 "txouts" : n, (numeric) The number of unspent transaction outputs
16 "bogosize" : n, (numeric) A meaningless metric for UTXO set size
17 "hash_serialized_2" : "hex", (string) The serialized hash (only present if 'hash_serialized_2' hash_type is chosen)
18 "disk_size" : n, (numeric) The estimated size of the chainstate on disk
19 "total_amount" : n (numeric) The total amount
20}
21
22Examples:
23> bitcoin-cli gettxoutsetinfo
24> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "gettxoutsetinfo", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
25*/
26
27const GET_TX_OUT_SET_INFO_COMMAND: &str = "gettxoutsetinfo";
28const DEFAULT_HASH_TYPE_ARG: &str = "hash_serialized_2";
29
30use crate::client::Client;
31use crate::command::request::request;
32use crate::command::CallableCommand;
33use serde::Deserialize;
34use serde::Serialize;
35use serde_json::value::{to_raw_value, RawValue};
36
37pub struct GetTxOutSetInfoCommand {}
38impl GetTxOutSetInfoCommand {
39 pub fn new() -> Self {
40 GetTxOutSetInfoCommand {}
41 }
42}
43#[derive(Serialize, Deserialize, Debug, Clone)]
44pub struct GetTxOutSetInfoCommandResponse {
45 pub height: u64, // The current block height (index)
46 pub bestblock: String, // "hex" The hash of the block at the tip of the chain
47 pub transactions: u64, // The number of transactions with unspent outputs
48 pub txouts: u64, // The number of unspent transaction outputs
49 pub bogosize: u64, // A meaningless metric for UTXO set size
50 pub hash_serialized_2: String, // "hex" The serialized hash (only present if 'hash_serialized_2' hash_type is chosen)
51 pub disk_size: u64, // The estimated size of the chainstate on disk
52 pub total_amount: f64, // The total amount
53}
54
55impl CallableCommand for GetTxOutSetInfoCommand {
56 type Response = GetTxOutSetInfoCommandResponse;
57 // TODO: This currently fails. Seems realted to this: https://github.com/bitcoin/bitcoin/issues/25724
58 fn call(&self, client: &Client) -> Result<Self::Response, jsonrpc::Error> {
59 let command = GET_TX_OUT_SET_INFO_COMMAND;
60 // TODO: Implemnt hashtype arg (wasn't an option in bitcoin core v0.20)
61 // let params: Vec<Box<RawValue>> = vec![hash_type_arg_raw_value];
62 let params: Vec<Box<RawValue>> = vec![];
63 let r = request(client, command, params);
64 let response: GetTxOutSetInfoCommandResponse = r.result()?;
65 Ok(response)
66 }
67}