Skip to content
Closed
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
6 changes: 3 additions & 3 deletions types/src/model/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ pub struct GetBlockStats {
pub subsidy: Option<Amount>,
/// Total size of all segwit transactions.
pub segwit_total_size: Option<u32>,
/// Total weight of all segwit transactions divided by segwit scale factor (4).
/// Total weight of all segwit transactions.
pub segwit_total_weight: Option<Weight>,
/// The number of segwit transactions.
pub segwit_txs: Option<u32>,
Expand All @@ -436,11 +436,11 @@ pub struct GetBlockStats {
pub total_out: Option<Amount>,
/// Total size of all non-coinbase transactions.
pub total_size: Option<u32>,
/// Total weight of all non-coinbase transactions divided by segwit scale factor (4).
/// Total weight of all non-coinbase transactions.
pub total_weight: Option<Weight>,
/// The fee total.
pub total_fee: Option<Amount>,
/// The number of transactions (excluding coinbase).
/// The number of transactions (including coinbase).
pub txs: Option<u32>,
/// The increase/decrease in the number of unspent outputs.
pub utxo_increase: Option<i32>,
Expand Down
78 changes: 73 additions & 5 deletions types/src/v21/blockchain/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,83 @@

use alloc::collections::BTreeMap;

use bitcoin::{hex, BlockHash, Network, Txid, Work, Wtxid};
use bitcoin::{hex, Amount, BlockHash, FeeRate, Network, Txid, Weight, Work, Wtxid};

use super::{
GetBlockchainInfo, GetBlockchainInfoError, GetMempoolAncestors, GetMempoolAncestorsVerbose,
GetMempoolDescendants, GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo,
GetMempoolInfoError, GetRawMempool, GetRawMempoolSequence, GetRawMempoolVerbose,
MapMempoolEntryError, MempoolEntry, MempoolEntryError,
GetBlockStats, GetBlockchainInfo, GetBlockchainInfoError, GetMempoolAncestors,
GetMempoolAncestorsVerbose, GetMempoolDescendants, GetMempoolDescendantsVerbose,
GetMempoolEntry, GetMempoolInfo, GetMempoolInfoError, GetRawMempool, GetRawMempoolSequence,
GetRawMempoolVerbose, MapMempoolEntryError, MempoolEntry, MempoolEntryError,
};
use crate::model;
use crate::v17::GetBlockStatsError;

impl GetBlockStats {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::GetBlockStats, GetBlockStatsError> {
use GetBlockStatsError as E;

// `FeeRate::sat_per_vb` returns an option if value overflows.
let average_fee_rate = self.average_fee_rate.and_then(FeeRate::from_sat_per_vb);
let block_hash =
self.block_hash.map(|h| h.parse::<BlockHash>()).transpose().map_err(E::BlockHash)?;
let fee_rate_percentiles = self
.fee_rate_percentiles
.map(|arr| arr.iter().map(|vb| FeeRate::from_sat_per_vb(*vb)).collect());
let max_fee_rate = self.max_fee_rate.and_then(FeeRate::from_sat_per_vb);
let minimum_fee_rate = self.minimum_fee_rate.and_then(FeeRate::from_sat_per_vb);

// FIXME: Double check that these values are virtual bytes and not weight units.
let segwit_total_weight = self.segwit_total_weight.and_then(Weight::from_vb);
let total_weight = self.total_weight.and_then(Weight::from_vb);

Ok(model::GetBlockStats {
average_fee: self.average_fee.map(Amount::from_sat),
average_fee_rate,
average_tx_size: self
.average_tx_size
.map(|v| crate::to_u32(v, "average_tx_size"))
.transpose()?,
block_hash,
fee_rate_percentiles,
height: self.height.map(|v| crate::to_u32(v, "height")).transpose()?,
inputs: self.inputs.map(|v| crate::to_u32(v, "inputs")).transpose()?,
max_fee: self.max_fee.map(Amount::from_sat),
max_fee_rate,
max_tx_size: self.max_tx_size.map(|v| crate::to_u32(v, "max_tx_size")).transpose()?,
median_fee: self.median_fee.map(Amount::from_sat),
median_time: self.median_time.map(|v| crate::to_u32(v, "median_time")).transpose()?,
median_tx_size: self
.median_tx_size
.map(|v| crate::to_u32(v, "median_tx_size"))
.transpose()?,
minimum_fee: self.minimum_fee.map(Amount::from_sat),
minimum_fee_rate,
minimum_tx_size: self
.minimum_tx_size
.map(|v| crate::to_u32(v, "minimum_tx_size"))
.transpose()?,
outputs: self.outputs.map(|v| crate::to_u32(v, "outputs")).transpose()?,
subsidy: self.subsidy.map(Amount::from_sat),
segwit_total_size: self
.segwit_total_size
.map(|v| crate::to_u32(v, "segwit_total_size"))
.transpose()?,
segwit_total_weight,
segwit_txs: self.segwit_txs.map(|v| crate::to_u32(v, "segwit_txs")).transpose()?,
time: self.time.map(|v| crate::to_u32(v, "time")).transpose()?,
total_out: self.total_out.map(Amount::from_sat),
total_size: self.total_size.map(|v| crate::to_u32(v, "total_size")).transpose()?,
total_weight,
total_fee: self.total_fee.map(Amount::from_sat),
txs: self.txs.map(|v| crate::to_u32(v, "txs")).transpose()?,
utxo_increase: self.utxo_increase,
utxo_size_increase: self.utxo_size_increase,
utxo_increase_actual: None, // v25 and later only.
utxo_size_increase_actual: None, // v25 and later only.
})
}
}

impl GetBlockchainInfo {
/// Converts version specific type to a version nonspecific, more strongly typed type.
Expand Down
102 changes: 102 additions & 0 deletions types/src/v21/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,108 @@ pub use super::{
Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBlockchainInfoError, GetMempoolInfoError,
MapMempoolEntryError, MempoolEntryError, MempoolEntryFees,
};
pub use crate::v17::GetBlockStatsError;

/// Result of JSON-RPC method `getblockstats`.
///
/// > getblockstats hash_or_height ( stats )
/// >
/// > Compute per block statistics for a given window. All amounts are in satoshis.
/// > It won't work for some heights with pruning.
/// >
/// > Arguments:
/// > 1. hash_or_height (string or numeric, required) The block hash or height of the target block
/// > 2. stats (json array, optional, default=all values) Values to plot (see result below)
/// > [
/// > "height", (string) Selected statistic
/// > "time", (string) Selected statistic
/// > ...
/// > ]
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct GetBlockStats {
/// Average fee in the block.
#[serde(rename = "avgfee")]
pub average_fee: Option<u64>,
// FIXME: Remember these docs will become silently stale when unit changes in a later version of Core.
/// Average feerate (in satoshis per virtual byte).
#[serde(rename = "avgfeerate")]
pub average_fee_rate: Option<u64>,
/// Average transaction size.
#[serde(rename = "avgtxsize")]
pub average_tx_size: Option<i64>,
/// The block hash (to check for potential reorgs).
#[serde(rename = "blockhash")]
pub block_hash: Option<String>,
/// Feerates at the 10th, 25th, 50th, 75th, and 90th percentile weight unit (in satoshis per
/// virtual byte).
#[serde(rename = "feerate_percentiles")]
pub fee_rate_percentiles: Option<[u64; 5]>,
/// The height of the block.
pub height: Option<i64>,
/// The number of inputs (excluding coinbase).
#[serde(rename = "ins")]
pub inputs: Option<i64>,
/// Maximum fee in the block.
#[serde(rename = "maxfee")]
pub max_fee: Option<u64>,
/// Maximum feerate (in satoshis per virtual byte).
#[serde(rename = "maxfeerate")]
pub max_fee_rate: Option<u64>,
/// Maximum transaction size.
#[serde(rename = "maxtxsize")]
pub max_tx_size: Option<i64>,
/// Truncated median fee in the block.
#[serde(rename = "medianfee")]
pub median_fee: Option<u64>,
/// The block median time past.
#[serde(rename = "mediantime")]
pub median_time: Option<i64>,
/// Truncated median transaction size.
#[serde(rename = "mediantxsize")]
pub median_tx_size: Option<i64>,
/// Minimum fee in the block.
#[serde(rename = "minfee")]
pub minimum_fee: Option<u64>,
/// Minimum feerate (in satoshis per virtual byte).
#[serde(rename = "minfeerate")]
pub minimum_fee_rate: Option<u64>,
/// Minimum transaction size.
#[serde(rename = "mintxsize")]
pub minimum_tx_size: Option<i64>,
/// The number of outputs.
#[serde(rename = "outs")]
pub outputs: Option<i64>,
/// The block subsidy.
pub subsidy: Option<u64>,
/// Total size of all segwit transactions.
#[serde(rename = "swtotal_size")]
pub segwit_total_size: Option<i64>,
/// Total weight of all segwit transactions.
#[serde(rename = "swtotal_weight")]
pub segwit_total_weight: Option<u64>,
/// The number of segwit transactions.
#[serde(rename = "swtxs")]
pub segwit_txs: Option<i64>,
/// The block time.
pub time: Option<i64>,
/// Total amount in all outputs (excluding coinbase and thus reward [ie subsidy + totalfee]).
pub total_out: Option<u64>,
/// Total size of all non-coinbase transactions.
pub total_size: Option<i64>,
/// Total weight of all non-coinbase transactions.
pub total_weight: Option<u64>,
/// The fee total.
#[serde(rename = "totalfee")]
pub total_fee: Option<u64>,
/// The number of transactions (including coinbase).
pub txs: Option<i64>,
/// The increase/decrease in the number of unspent outputs.
pub utxo_increase: Option<i32>,
/// The increase/decrease in size for the utxo index (not discounting op_return and similar).
#[serde(rename = "utxo_size_inc")]
pub utxo_size_increase: Option<i32>,
}

/// Result of JSON-RPC method `getblockchaininfo`.
///
Expand Down
26 changes: 13 additions & 13 deletions types/src/v21/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ mod wallet;
#[doc(inline)]
pub use self::{
blockchain::{
Bip9SoftforkInfo, GetBlockchainInfo, GetMempoolAncestors, GetMempoolAncestorsVerbose,
GetMempoolDescendants, GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo,
GetRawMempool, GetRawMempoolSequence, GetRawMempoolVerbose, MempoolEntry, Softfork,
SoftforkType,
Bip9SoftforkInfo, GetBlockStats, GetBlockStatsError, GetBlockchainInfo,
GetMempoolAncestors, GetMempoolAncestorsVerbose, GetMempoolDescendants,
GetMempoolDescendantsVerbose, GetMempoolEntry, GetMempoolInfo, GetRawMempool,
GetRawMempoolSequence, GetRawMempoolVerbose, MempoolEntry, Softfork, SoftforkType,
},
generating::GenerateBlock,
hidden::AddPeerAddress,
Expand Down Expand Up @@ -275,15 +275,15 @@ pub use crate::{
FinalizePsbt, FinalizePsbtError, FundRawTransaction, FundRawTransactionError, Generate,
GenerateToAddress, GetAddedNodeInfo, GetAddressInfoEmbeddedError, GetAddressesByLabel,
GetBalance, GetBestBlockHash, GetBlockCount, GetBlockHash, GetBlockHeader,
GetBlockHeaderError, GetBlockHeaderVerbose, GetBlockHeaderVerboseError, GetBlockStats,
GetBlockStatsError, GetBlockTemplate, GetBlockTemplateError, GetBlockVerboseOne,
GetBlockVerboseOneError, GetBlockVerboseZero, GetChainTips, GetChainTxStatsError,
GetConnectionCount, GetDifficulty, GetMemoryInfoStats, GetMempoolInfoError, GetMiningInfo,
GetNetTotals, GetNetworkInfoAddress, GetNetworkInfoError, GetNetworkInfoNetwork,
GetNewAddress, GetRawChangeAddress, GetRawTransaction, GetRawTransactionVerbose,
GetRawTransactionVerboseError, GetReceivedByAddress, GetTransactionDetailError,
GetTransactionError, GetTxOut, GetTxOutError, GetTxOutSetInfo, GetTxOutSetInfoError,
GetUnconfirmedBalance, GetWalletInfoError, ListAddressGroupings, ListAddressGroupingsError,
GetBlockHeaderError, GetBlockHeaderVerbose, GetBlockHeaderVerboseError, GetBlockTemplate,
GetBlockTemplateError, GetBlockVerboseOne, GetBlockVerboseOneError, GetBlockVerboseZero,
GetChainTips, GetChainTxStatsError, GetConnectionCount, GetDifficulty, GetMemoryInfoStats,
GetMempoolInfoError, GetMiningInfo, GetNetTotals, GetNetworkInfoAddress,
GetNetworkInfoError, GetNetworkInfoNetwork, GetNewAddress, GetRawChangeAddress,
GetRawTransaction, GetRawTransactionVerbose, GetRawTransactionVerboseError,
GetReceivedByAddress, GetTransactionDetailError, GetTransactionError, GetTxOut,
GetTxOutError, GetTxOutSetInfo, GetTxOutSetInfoError, GetUnconfirmedBalance,
GetWalletInfoError, ListAddressGroupings, ListAddressGroupingsError,
ListAddressGroupingsItem, ListLabels, ListLockUnspent, ListLockUnspentItem,
ListLockUnspentItemError, ListReceivedByAddressError, ListUnspentItemError, ListWallets,
LoadWallet, LockUnspent, Locked, NumericError, PartialSignatureError, PruneBlockchain,
Expand Down
31 changes: 15 additions & 16 deletions types/src/v22/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,14 @@ pub use crate::{
FundRawTransactionError, Generate, GenerateToAddress, GetAddedNodeInfo,
GetAddressInfoEmbeddedError, GetAddressesByLabel, GetBalance, GetBestBlockHash,
GetBlockCount, GetBlockHash, GetBlockHeader, GetBlockHeaderError, GetBlockHeaderVerbose,
GetBlockHeaderVerboseError, GetBlockStats, GetBlockStatsError, GetBlockTemplate,
GetBlockTemplateError, GetBlockVerboseOne, GetBlockVerboseOneError, GetBlockVerboseZero,
GetChainTips, GetChainTxStatsError, GetConnectionCount, GetDifficulty, GetMemoryInfoStats,
GetMempoolInfoError, GetMiningInfo, GetNetTotals, GetNetworkInfoAddress,
GetNetworkInfoError, GetNetworkInfoNetwork, GetNewAddress, GetRawChangeAddress,
GetRawTransaction, GetRawTransactionVerbose, GetRawTransactionVerboseError,
GetReceivedByAddress, GetTransactionDetailError, GetTransactionError, GetTxOut,
GetTxOutError, GetTxOutSetInfo, GetTxOutSetInfoError, GetUnconfirmedBalance,
GetWalletInfoError, ListAddressGroupings, ListAddressGroupingsError,
GetBlockHeaderVerboseError, GetBlockTemplate, GetBlockTemplateError, GetBlockVerboseOne,
GetBlockVerboseOneError, GetBlockVerboseZero, GetChainTips, GetChainTxStatsError,
GetConnectionCount, GetDifficulty, GetMemoryInfoStats, GetMempoolInfoError, GetMiningInfo,
GetNetTotals, GetNetworkInfoAddress, GetNetworkInfoError, GetNetworkInfoNetwork,
GetNewAddress, GetRawChangeAddress, GetRawTransaction, GetRawTransactionVerbose,
GetRawTransactionVerboseError, GetReceivedByAddress, GetTransactionDetailError,
GetTransactionError, GetTxOut, GetTxOutError, GetTxOutSetInfo, GetTxOutSetInfoError,
GetUnconfirmedBalance, GetWalletInfoError, ListAddressGroupings, ListAddressGroupingsError,
ListAddressGroupingsItem, ListLabels, ListLockUnspent, ListLockUnspentItem,
ListLockUnspentItemError, ListReceivedByAddressError, ListUnspentItemError, ListWallets,
LoadWallet, LockUnspent, Locked, NumericError, PartialSignatureError, PruneBlockchain,
Expand Down Expand Up @@ -323,13 +322,13 @@ pub use crate::{
ScanTxOutSetStart, ScanTxOutSetUnspent, TransactionItem, TransactionItemError,
},
v21::{
AddPeerAddress, Bip9SoftforkInfo, GenerateBlock, GetBlockchainInfo, GetIndexInfo,
GetIndexInfoName, GetMempoolAncestors, GetMempoolAncestorsVerbose, GetMempoolDescendants,
GetMempoolDescendantsVerbose, GetMempoolEntry, GetNetworkInfo, GetRawMempool,
GetRawMempoolSequence, GetRawMempoolVerbose, GetWalletInfo, GetWalletInfoScanning,
ImportDescriptors, ImportDescriptorsResult, MempoolEntry, PsbtBumpFee, PsbtBumpFeeError,
Send, SendError, SendMany, SendManyVerbose, Softfork, SoftforkType, UnloadWallet,
UpgradeWallet,
AddPeerAddress, Bip9SoftforkInfo, GenerateBlock, GetBlockStats, GetBlockStatsError,
GetBlockchainInfo, GetIndexInfo, GetIndexInfoName, GetMempoolAncestors,
GetMempoolAncestorsVerbose, GetMempoolDescendants, GetMempoolDescendantsVerbose,
GetMempoolEntry, GetNetworkInfo, GetRawMempool, GetRawMempoolSequence,
GetRawMempoolVerbose, GetWalletInfo, GetWalletInfoScanning, ImportDescriptors,
ImportDescriptorsResult, MempoolEntry, PsbtBumpFee, PsbtBumpFeeError, Send, SendError,
SendMany, SendManyVerbose, Softfork, SoftforkType, UnloadWallet, UpgradeWallet,
},
ScriptPubKey,
};
Loading
Loading