Skip to content

Commit ecae377

Browse files
committed
Implement RpcApi::get_tx_out_set_info()
1 parent 6983d5f commit ecae377

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
@@ -988,6 +988,12 @@ pub trait RpcApi: Sized {
988988
self.call("rescanblockchain", handle_defaults(&mut args, &[0.into(), null()]))?;
989989
Ok((res.start_height, res.stop_height))
990990
}
991+
992+
/// Returns statistics about the unspent transaction output set.
993+
/// This call may take some time.
994+
fn get_tx_out_set_info(&self) -> Result<json::GetTxOutSetInfoResult> {
995+
self.call("gettxoutsetinfo", &[])
996+
}
991997
}
992998

993999
/// Client implements a JSON-RPC client for the Bitcoin Core daemon or compatible APIs.

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
//TODO import_multi(
151152
//TODO verify_message(
152153
//TODO wait_for_new_block(&self, timeout: u64) -> Result<json::BlockRef> {
@@ -896,6 +897,10 @@ fn test_create_wallet(cl: &Client) {
896897
assert!(wallet_list.iter().zip(wallet_names).all(|(a, b)| a == b));
897898
}
898899

900+
fn test_get_tx_out_set_info(cl: &Client) {
901+
cl.get_tx_out_set_info().unwrap();
902+
}
903+
899904
fn test_stop(cl: Client) {
900905
println!("Stopping: '{}'", cl.stop().unwrap());
901906
}

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;
@@ -1176,6 +1177,29 @@ pub struct SignRawTransactionInput {
11761177
pub amount: Option<Amount>,
11771178
}
11781179

1180+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1181+
pub struct GetTxOutSetInfoResult {
1182+
/// The current block height (index)
1183+
pub height: u64,
1184+
/// The hash of the block at the tip of the chain
1185+
#[serde(rename = "bestblock")]
1186+
pub best_block: bitcoin::BlockHash,
1187+
/// The number of transactions with unspent outputs
1188+
pub transactions: u64,
1189+
/// The number of unspent transaction outputs
1190+
#[serde(rename = "txouts")]
1191+
pub tx_outs: u64,
1192+
/// A meaningless metric for UTXO set size
1193+
pub bogosize: u64,
1194+
/// The serialized hash
1195+
pub hash_serialized_2: sha256::Hash,
1196+
/// The estimated size of the chainstate on disk
1197+
pub disk_size: u64,
1198+
/// The total amount
1199+
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
1200+
pub total_amount: Amount,
1201+
}
1202+
11791203
/// Used to represent an address type.
11801204
#[derive(Copy, Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
11811205
#[serde(rename_all = "kebab-case")]

0 commit comments

Comments
 (0)