Skip to content

Commit 6030b61

Browse files
committed
Update get_tx_out_set_info to Core 22.0+
1 parent 657eebd commit 6030b61

File tree

3 files changed

+88
-12
lines changed

3 files changed

+88
-12
lines changed

client/src/client.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1133,9 +1133,16 @@ pub trait RpcApi: Sized {
11331133
}
11341134

11351135
/// Returns statistics about the unspent transaction output set.
1136-
/// This call may take some time.
1137-
fn get_tx_out_set_info(&self) -> Result<json::GetTxOutSetInfoResult> {
1138-
self.call("gettxoutsetinfo", &[])
1136+
/// Note this call may take some time if you are not using coinstatsindex.
1137+
fn get_tx_out_set_info(
1138+
&self,
1139+
hash_type: Option<json::TxOutSetHashType>,
1140+
hash_or_height: Option<json::HashOrHeight>,
1141+
use_index: Option<bool>,
1142+
) -> Result<json::GetTxOutSetInfoResult> {
1143+
let mut args =
1144+
[opt_into_json(hash_type)?, opt_into_json(hash_or_height)?, opt_into_json(use_index)?];
1145+
self.call("gettxoutsetinfo", handle_defaults(&mut args, &[null(), null(), null()]))
11391146
}
11401147

11411148
/// Returns information about network traffic, including bytes in, bytes out,

integration_test/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ fn test_create_wallet(cl: &Client) {
10301030
}
10311031

10321032
fn test_get_tx_out_set_info(cl: &Client) {
1033-
cl.get_tx_out_set_info().unwrap();
1033+
cl.get_tx_out_set_info(None, None, None).unwrap();
10341034
}
10351035

10361036
fn test_get_chain_tips(cl: &Client) {

json/src/lib.rs

+77-8
Original file line numberDiff line numberDiff line change
@@ -1852,27 +1852,96 @@ pub struct SignRawTransactionInput {
18521852
pub amount: Option<Amount>,
18531853
}
18541854

1855+
/// Used to represent UTXO set hash type
1856+
#[derive(Clone, Serialize, PartialEq, Eq, Debug)]
1857+
#[serde(rename_all = "snake_case")]
1858+
pub enum TxOutSetHashType {
1859+
HashSerialized2,
1860+
Muhash,
1861+
None,
1862+
}
1863+
1864+
/// Used to specify a block hash or a height
1865+
#[derive(Clone, Serialize, PartialEq, Eq, Debug)]
1866+
#[serde(untagged)]
1867+
pub enum HashOrHeight {
1868+
BlockHash(bitcoin::BlockHash),
1869+
Height(u64),
1870+
}
1871+
18551872
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
18561873
pub struct GetTxOutSetInfoResult {
1857-
/// The current block height (index)
1874+
/// The block height (index) of the returned statistics
18581875
pub height: u64,
1859-
/// The hash of the block at the tip of the chain
1876+
/// The hash of the block at which these statistics are calculated
18601877
#[serde(rename = "bestblock")]
18611878
pub best_block: bitcoin::BlockHash,
1862-
/// The number of transactions with unspent outputs
1863-
pub transactions: u64,
1879+
/// The number of transactions with unspent outputs (not available when coinstatsindex is used)
1880+
#[serde(default, skip_serializing_if = "Option::is_none")]
1881+
pub transactions: Option<u64>,
18641882
/// The number of unspent transaction outputs
18651883
#[serde(rename = "txouts")]
18661884
pub tx_outs: u64,
18671885
/// A meaningless metric for UTXO set size
18681886
pub bogosize: u64,
1869-
/// The serialized hash
1870-
pub hash_serialized_2: sha256::Hash,
1871-
/// The estimated size of the chainstate on disk
1872-
pub disk_size: u64,
1887+
/// The serialized hash (only present if 'hash_serialized_2' hash_type is chosen)
1888+
#[serde(default, skip_serializing_if = "Option::is_none")]
1889+
pub hash_serialized_2: Option<sha256::Hash>,
1890+
/// The serialized hash (only present if 'muhash' hash_type is chosen)
1891+
#[serde(default, skip_serializing_if = "Option::is_none")]
1892+
pub muhash: Option<sha256::Hash>,
1893+
/// The estimated size of the chainstate on disk (not available when coinstatsindex is used)
1894+
#[serde(default, skip_serializing_if = "Option::is_none")]
1895+
pub disk_size: Option<u64>,
18731896
/// The total amount
18741897
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
18751898
pub total_amount: Amount,
1899+
/// The total amount of coins permanently excluded from the UTXO set (only available if coinstatsindex is used)
1900+
#[serde(
1901+
default,
1902+
skip_serializing_if = "Option::is_none",
1903+
with = "bitcoin::util::amount::serde::as_btc::opt"
1904+
)]
1905+
pub total_unspendable_amount: Option<Amount>,
1906+
/// Info on amounts in the block at this block height (only available if coinstatsindex is used)
1907+
#[serde(default, skip_serializing_if = "Option::is_none")]
1908+
pub block_info: Option<BlockInfo>,
1909+
}
1910+
1911+
/// Info on amounts in the block at the block height of the `gettxoutsetinfo` call (only available if coinstatsindex is used)
1912+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1913+
pub struct BlockInfo {
1914+
/// Amount of previous outputs spent
1915+
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
1916+
pub prevout_spent: Amount,
1917+
/// Output size of the coinbase transaction
1918+
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
1919+
pub coinbase: Amount,
1920+
/// Newly-created outputs
1921+
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
1922+
pub new_outputs_ex_coinbase: Amount,
1923+
/// Amount of unspendable outputs
1924+
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
1925+
pub unspendable: Amount,
1926+
/// Detailed view of the unspendable categories
1927+
pub unspendables: Unspendables,
1928+
}
1929+
1930+
/// Detailed view of the unspendable categories
1931+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
1932+
pub struct Unspendables {
1933+
/// Unspendable coins from the Genesis block
1934+
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
1935+
pub genesis_block: Amount,
1936+
/// Transactions overridden by duplicates (no longer possible with BIP30)
1937+
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
1938+
pub bip30: Amount,
1939+
/// Amounts sent to scripts that are unspendable (for example OP_RETURN outputs)
1940+
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
1941+
pub scripts: Amount,
1942+
/// Fee rewards that miners did not claim in their coinbase transaction
1943+
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
1944+
pub unclaimed_rewards: Amount,
18761945
}
18771946

18781947
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]

0 commit comments

Comments
 (0)