Skip to content

Commit 2e610f7

Browse files
authored
Merge pull request #132 from shesek/202008-utxo-info
Implement RpcApi::get_tx_out_set_info()
2 parents 7011195 + 4864bf3 commit 2e610f7

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

client/src/client.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,12 @@ pub trait RpcApi: Sized {
991991
Ok((res.start_height, res.stop_height))
992992
}
993993

994+
/// Returns statistics about the unspent transaction output set.
995+
/// This call may take some time.
996+
fn get_tx_out_set_info(&self) -> Result<json::GetTxOutSetInfoResult> {
997+
self.call("gettxoutsetinfo", &[])
998+
}
999+
9941000
/// Returns information about network traffic, including bytes in, bytes out,
9951001
/// and current time.
9961002
fn get_net_totals(&self) -> Result<json::GetNetTotalsResult> {

integration_test/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ fn main() {
147147
test_get_peer_info(&cl);
148148
test_rescan_blockchain(&cl);
149149
test_create_wallet(&cl);
150+
test_get_tx_out_set_info(&cl);
150151
test_get_net_totals(&cl);
151152
test_get_network_hash_ps(&cl);
152153
test_uptime(&cl);
@@ -900,6 +901,10 @@ fn test_create_wallet(cl: &Client) {
900901
assert!(wallet_list.iter().zip(wallet_names).all(|(a, b)| a == b));
901902
}
902903

904+
fn test_get_tx_out_set_info(cl: &Client) {
905+
cl.get_tx_out_set_info().unwrap();
906+
}
907+
903908
fn test_get_net_totals(cl: &Client) {
904909
cl.get_net_totals().unwrap();
905910
}

json/src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use std::collections::HashMap;
2626

2727
use bitcoin::consensus::encode;
2828
use bitcoin::hashes::hex::{FromHex, ToHex};
29+
use bitcoin::hashes::sha256;
2930
use bitcoin::util::{bip158, bip32};
3031
use bitcoin::{Address, Amount, PrivateKey, PublicKey, Script, SignedAmount, Transaction};
3132
use serde::de::Error as SerdeError;
@@ -1180,6 +1181,29 @@ pub struct SignRawTransactionInput {
11801181
pub amount: Option<Amount>,
11811182
}
11821183

1184+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1185+
pub struct GetTxOutSetInfoResult {
1186+
/// The current block height (index)
1187+
pub height: u64,
1188+
/// The hash of the block at the tip of the chain
1189+
#[serde(rename = "bestblock")]
1190+
pub best_block: bitcoin::BlockHash,
1191+
/// The number of transactions with unspent outputs
1192+
pub transactions: u64,
1193+
/// The number of unspent transaction outputs
1194+
#[serde(rename = "txouts")]
1195+
pub tx_outs: u64,
1196+
/// A meaningless metric for UTXO set size
1197+
pub bogosize: u64,
1198+
/// The serialized hash
1199+
pub hash_serialized_2: sha256::Hash,
1200+
/// The estimated size of the chainstate on disk
1201+
pub disk_size: u64,
1202+
/// The total amount
1203+
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
1204+
pub total_amount: Amount,
1205+
}
1206+
11831207
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
11841208
pub struct GetNetTotalsResult {
11851209
/// Total bytes received

0 commit comments

Comments
 (0)