Skip to content

Update get_tx_out_set_info to Core 22.0+ #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,16 @@ pub trait RpcApi: Sized {
}

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

/// Returns information about network traffic, including bytes in, bytes out,
Expand Down
2 changes: 1 addition & 1 deletion integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ fn test_create_wallet(cl: &Client) {
}

fn test_get_tx_out_set_info(cl: &Client) {
cl.get_tx_out_set_info().unwrap();
cl.get_tx_out_set_info(None, None, None).unwrap();
}

fn test_get_chain_tips(cl: &Client) {
Expand Down
85 changes: 77 additions & 8 deletions json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1852,27 +1852,96 @@ pub struct SignRawTransactionInput {
pub amount: Option<Amount>,
}

/// Used to represent UTXO set hash type
#[derive(Clone, Serialize, PartialEq, Eq, Debug)]
#[serde(rename_all = "snake_case")]
pub enum TxOutSetHashType {
HashSerialized2,
Muhash,
None,
}

/// Used to specify a block hash or a height
#[derive(Clone, Serialize, PartialEq, Eq, Debug)]
#[serde(untagged)]
pub enum HashOrHeight {
BlockHash(bitcoin::BlockHash),
Height(u64),
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct GetTxOutSetInfoResult {
/// The current block height (index)
/// The block height (index) of the returned statistics
pub height: u64,
/// The hash of the block at the tip of the chain
/// The hash of the block at which these statistics are calculated
#[serde(rename = "bestblock")]
pub best_block: bitcoin::BlockHash,
/// The number of transactions with unspent outputs
pub transactions: u64,
/// The number of transactions with unspent outputs (not available when coinstatsindex is used)
#[serde(default, skip_serializing_if = "Option::is_none")]
pub transactions: Option<u64>,
/// The number of unspent transaction outputs
#[serde(rename = "txouts")]
pub tx_outs: u64,
/// A meaningless metric for UTXO set size
pub bogosize: u64,
/// The serialized hash
pub hash_serialized_2: sha256::Hash,
/// The estimated size of the chainstate on disk
pub disk_size: u64,
/// The serialized hash (only present if 'hash_serialized_2' hash_type is chosen)
#[serde(default, skip_serializing_if = "Option::is_none")]
pub hash_serialized_2: Option<sha256::Hash>,
/// The serialized hash (only present if 'muhash' hash_type is chosen)
#[serde(default, skip_serializing_if = "Option::is_none")]
pub muhash: Option<sha256::Hash>,
/// The estimated size of the chainstate on disk (not available when coinstatsindex is used)
#[serde(default, skip_serializing_if = "Option::is_none")]
pub disk_size: Option<u64>,
/// The total amount
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
pub total_amount: Amount,
/// The total amount of coins permanently excluded from the UTXO set (only available if coinstatsindex is used)
#[serde(
default,
skip_serializing_if = "Option::is_none",
with = "bitcoin::util::amount::serde::as_btc::opt"
)]
pub total_unspendable_amount: Option<Amount>,
/// Info on amounts in the block at this block height (only available if coinstatsindex is used)
#[serde(default, skip_serializing_if = "Option::is_none")]
pub block_info: Option<BlockInfo>,
}

/// Info on amounts in the block at the block height of the `gettxoutsetinfo` call (only available if coinstatsindex is used)
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct BlockInfo {
/// Amount of previous outputs spent
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
pub prevout_spent: Amount,
/// Output size of the coinbase transaction
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
pub coinbase: Amount,
/// Newly-created outputs
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
pub new_outputs_ex_coinbase: Amount,
/// Amount of unspendable outputs
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
pub unspendable: Amount,
/// Detailed view of the unspendable categories
pub unspendables: Unspendables,
}

/// Detailed view of the unspendable categories
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct Unspendables {
/// Unspendable coins from the Genesis block
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
pub genesis_block: Amount,
/// Transactions overridden by duplicates (no longer possible with BIP30)
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
pub bip30: Amount,
/// Amounts sent to scripts that are unspendable (for example OP_RETURN outputs)
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
pub scripts: Amount,
/// Fee rewards that miners did not claim in their coinbase transaction
#[serde(with = "bitcoin::util::amount::serde::as_btc")]
pub unclaimed_rewards: Amount,
}

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