Skip to content
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
1 change: 0 additions & 1 deletion integration_test/tests/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ fn blockchain__get_mempool_entry__modelled() {
}

#[test]
#[cfg(feature = "v29_and_below")]
fn blockchain__get_mempool_info__modelled() {
let node = Node::with_wallet(Wallet::Default, &[]);
node.fund_wallet();
Expand Down
1 change: 0 additions & 1 deletion integration_test/tests/mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ fn mining__get_block_template__modelled() {
}

#[test]
#[cfg(feature = "v29_and_below")]
fn mining__get_mining_info() {
let node = Node::with_wallet(Wallet::Default, &[]);

Expand Down
6 changes: 5 additions & 1 deletion types/src/model/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,17 @@ pub struct GetMempoolInfo {
pub mempool_min_fee: Option<FeeRate>,
/// Current minimum relay fee for transactions.
pub min_relay_tx_fee: Option<FeeRate>,
/// Minimum fee rate increment for mempool limiting or replacement in BTC/kvB. v24 and later only.
/// Minimum fee rate increment for mempool limiting or replacement. v24 and later only.
pub incremental_relay_fee: Option<FeeRate>,
/// Current number of transactions that haven't passed initial broadcast yet. v21 and later only.
pub unbroadcast_count: Option<u32>,
/// True if the mempool accepts RBF without replaceability signaling inspection. v24 and later
/// only.
pub full_rbf: Option<bool>,
/// True if the mempool accepts transactions with bare multisig outputs.
pub permit_bare_multisig: Option<bool>,
/// Maximum number of bytes that can be used by OP_RETURN outputs in the mempool.
pub max_data_carrier_size: Option<u64>,
}

/// Models the result of JSON-RPC method `getrawmempool` with verbose set to false.
Expand Down
5 changes: 4 additions & 1 deletion types/src/model/mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
use std::collections::BTreeMap;

use bitcoin::{
block, Amount, BlockHash, CompactTarget, SignedAmount, Target, Transaction, Txid, Weight, Wtxid,
block, Amount, BlockHash, CompactTarget, FeeRate, SignedAmount, Target, Transaction, Txid,
Weight, Wtxid,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -115,6 +116,8 @@ pub struct GetMiningInfo {
pub network_hash_ps: i64,
/// The size of the mempool.
pub pooled_tx: i64,
/// Minimum feerate of packages selected for block inclusion.
pub block_min_tx_fee: Option<FeeRate>,
/// Current network name as defined in BIP70 (main, test, regtest).
pub chain: String,
/// The block challenge (aka. block script).
Expand Down
2 changes: 2 additions & 0 deletions types/src/v17/blockchain/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ impl GetMempoolInfo {
incremental_relay_fee: None,
unbroadcast_count: None,
full_rbf: None,
permit_bare_multisig: None,
max_data_carrier_size: None,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions types/src/v17/mining/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl GetMiningInfo {
target: None,
network_hash_ps: self.network_hash_ps,
pooled_tx: self.pooled_tx,
block_min_tx_fee: None,
chain: self.chain,
signet_challenge: None,
next: None,
Expand Down
2 changes: 2 additions & 0 deletions types/src/v19/blockchain/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ impl GetMempoolInfo {
incremental_relay_fee: None,
unbroadcast_count: None,
full_rbf: None,
permit_bare_multisig: None,
max_data_carrier_size: None,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions types/src/v21/blockchain/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ impl GetMempoolInfo {
incremental_relay_fee: None,
unbroadcast_count,
full_rbf: None,
permit_bare_multisig: None,
max_data_carrier_size: None,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions types/src/v22/blockchain/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ impl GetMempoolInfo {
incremental_relay_fee: None,
unbroadcast_count,
full_rbf: None,
permit_bare_multisig: None,
max_data_carrier_size: None,
})
}
}
2 changes: 2 additions & 0 deletions types/src/v24/blockchain/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ impl GetMempoolInfo {
incremental_relay_fee,
unbroadcast_count,
full_rbf: Some(self.full_rbf),
permit_bare_multisig: None,
max_data_carrier_size: None,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions types/src/v28/mining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl GetMiningInfo {
target: None,
network_hash_ps: self.network_hash_ps,
pooled_tx: self.pooled_tx,
block_min_tx_fee: None,
chain: self.chain,
signet_challenge: None,
next: None,
Expand Down
1 change: 1 addition & 0 deletions types/src/v29/mining/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl GetMiningInfo {
target: Some(target),
network_hash_ps: self.network_hash_ps,
pooled_tx: self.pooled_tx,
block_min_tx_fee: None,
chain: self.chain,
signet_challenge: self.signet_challenge,
next: Some(next),
Expand Down
34 changes: 34 additions & 0 deletions types/src/v30/blockchain/into.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: CC0-1.0

use super::{GetMempoolInfo, GetMempoolInfoError};
use crate::model;

impl GetMempoolInfo {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::GetMempoolInfo, GetMempoolInfoError> {
let size = crate::to_u32(self.size, "size")?;
let bytes = crate::to_u32(self.bytes, "bytes")?;
let usage = crate::to_u32(self.usage, "usage")?;
let max_mempool = crate::to_u32(self.max_mempool, "max_mempool")?;
let mempool_min_fee = crate::btc_per_kb(self.mempool_min_fee)?;
let min_relay_tx_fee = crate::btc_per_kb(self.min_relay_tx_fee)?;
let incremental_relay_fee = crate::btc_per_kb(self.incremental_relay_fee)?;
let unbroadcast_count = Some(crate::to_u32(self.unbroadcast_count, "unbroadcast_count")?);

Ok(model::GetMempoolInfo {
loaded: Some(self.loaded),
size,
bytes,
usage,
total_fee: Some(self.total_fee),
max_mempool,
mempool_min_fee,
min_relay_tx_fee,
incremental_relay_fee,
unbroadcast_count,
full_rbf: Some(self.full_rbf),
permit_bare_multisig: Some(self.permit_bare_multisig),
max_data_carrier_size: Some(self.max_data_carrier_size),
})
}
}
59 changes: 59 additions & 0 deletions types/src/v30/blockchain/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: CC0-1.0

//! The JSON-RPC API for Bitcoin Core `v30` - blockchain.
//!
//! Types for methods found under the `== Blockchain ==` section of the API docs.

mod into;

use serde::{Deserialize, Serialize};

pub use super::GetMempoolInfoError;

/// Result of JSON-RPC method `getmempoolinfo` with verbose set to `true`.
///
/// > getmempoolinfo
/// >
/// > Returns details on the active state of the TX memory pool.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct GetMempoolInfo {
/// True if the initial load attempt of the persisted mempool finished.
pub loaded: bool,
/// Current tx count.
pub size: i64,
/// Sum of all virtual transaction sizes as defined in BIP 141.
///
/// Differs from actual serialized size because witness data is discounted.
pub bytes: i64,
/// Total memory usage for the mempool.
pub usage: i64,
/// Total fees for the mempool in BTC, ignoring modified fees through prioritisetransaction.
pub total_fee: f64,
/// Maximum memory usage for the mempool.
#[serde(rename = "maxmempool")]
pub max_mempool: i64,
/// Minimum fee rate in BTC/kB for a transaction to be accepted.
///
/// This is the maximum of `minrelaytxfee` and the minimum mempool fee.
#[serde(rename = "mempoolminfee")]
pub mempool_min_fee: f64,
/// Current minimum relay fee for transactions.
#[serde(rename = "minrelaytxfee")]
pub min_relay_tx_fee: f64,
/// Minimum fee rate increment for mempool limiting or replacement in BTC/kvB.
#[serde(rename = "incrementalrelayfee")]
pub incremental_relay_fee: f64,
/// Current number of transactions that haven't passed initial broadcast yet.
#[serde(rename = "unbroadcastcount")]
pub unbroadcast_count: i64,
/// True if the mempool accepts RBF without replaceability signaling inspection.
#[serde(rename = "fullrbf")]
pub full_rbf: bool,
/// True if the mempool accepts transactions with bare multisig outputs.
#[serde(rename = "permitbaremultisig")]
pub permit_bare_multisig: bool,
/// Maximum number of bytes that can be used by OP_RETURN outputs in the mempool.
#[serde(rename = "maxdatacarriersize")]
pub max_data_carrier_size: u64,
}
47 changes: 47 additions & 0 deletions types/src/v30/mining/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: CC0-1.0

use core::fmt;

use bitcoin::amount::ParseAmountError;
use bitcoin::error::UnprefixedHexError;

use super::NextBlockInfoError;
use crate::error::write_err;

/// Error when converting a `GetMiningInfo` type into the model type.
#[derive(Debug)]
pub enum GetMiningInfoError {
/// Conversion of the `bits` field failed.
Bits(UnprefixedHexError),
/// Conversion of the `target` field failed.
Target(UnprefixedHexError),
/// Conversion of the `block_min_tx_fee` field failed.
BlockMinTxFee(ParseAmountError),
/// Conversion of one of the items in field `next` failed.
Next(NextBlockInfoError),
}

impl fmt::Display for GetMiningInfoError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Bits(ref e) => write_err!(f, "conversion of the `bits` field failed"; e),
Self::Target(ref e) => write_err!(f, "conversion of the `target` field failed"; e),
Self::BlockMinTxFee(ref e) =>
write_err!(f, "conversion of the `block_min_tx_fee` field failed"; e),
Self::Next(ref e) =>
write_err!(f, "conversion of one of the items in field `next` failed"; e),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for GetMiningInfoError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Bits(ref e) => Some(e),
Self::Target(ref e) => Some(e),
Self::BlockMinTxFee(ref e) => Some(e),
Self::Next(ref e) => Some(e),
}
}
}
37 changes: 37 additions & 0 deletions types/src/v30/mining/into.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: CC0-1.0

use bitcoin::{CompactTarget, Target, Weight};

use super::{GetMiningInfo, GetMiningInfoError};
use crate::model;

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

let current_block_weight = self.current_block_weight.map(Weight::from_wu);
let bits = CompactTarget::from_unprefixed_hex(&self.bits).map_err(E::Bits)?;
let target = Target::from_unprefixed_hex(self.target.as_ref()).map_err(E::Target)?;
let block_min_tx_fee =
crate::btc_per_kb(self.block_min_tx_fee).map_err(E::BlockMinTxFee)?;

let next = self.next.into_model().map_err(E::Next)?;

Ok(model::GetMiningInfo {
blocks: self.blocks,
current_block_weight,
current_block_tx: self.current_block_tx,
bits: Some(bits),
difficulty: self.difficulty,
target: Some(target),
network_hash_ps: self.network_hash_ps,
pooled_tx: self.pooled_tx,
block_min_tx_fee,
chain: self.chain,
signet_challenge: self.signet_challenge,
next: Some(next),
warnings: self.warnings,
})
}
}
57 changes: 57 additions & 0 deletions types/src/v30/mining/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: CC0-1.0

//! The JSON-RPC API for Bitcoin Core `v29` - mining.
//!
//! Types for methods found under the `== Mining ==` section of the API docs.

mod error;
mod into;

use serde::{Deserialize, Serialize};

pub use self::error::GetMiningInfoError;
pub use super::{NextBlockInfo, NextBlockInfoError};

/// Result of the JSON-RPC method `getmininginfo`.
///
/// > getmininginfo
/// >
/// > Returns a json object containing mining-related information.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct GetMiningInfo {
/// The current block.
pub blocks: u64,
/// The block weight (including reserved weight for block header, txs count and coinbase tx) of
/// the last assembled block (only present if a block was ever assembled).
#[serde(rename = "currentblockweight")]
pub current_block_weight: Option<u64>,
/// The number of block transactions (excluding coinbase) of the last assembled block (only
/// present if a block was ever assembled).
#[serde(rename = "currentblocktx")]
pub current_block_tx: Option<i64>,
/// The current nBits, compact representation of the block difficulty target.
pub bits: String,
/// The current difficulty.
pub difficulty: f64,
/// The current target.
pub target: String,
/// The network hashes per second.
#[serde(rename = "networkhashps")]
pub network_hash_ps: i64,
/// The size of the mempool.
#[serde(rename = "pooledtx")]
pub pooled_tx: i64,
/// Minimum feerate of packages selected for block inclusion in BTC/kvB.
#[serde(rename = "blockmintxfee")]
pub block_min_tx_fee: f64,
/// Current network name as defined in BIP70 (main, test, regtest).
pub chain: String,
/// The block challenge (aka. block script), in hexadecimal (only present if the current network
/// is a signet).
pub signet_challenge: Option<String>,
/// The next block.
pub next: NextBlockInfo,
/// Any network and blockchain warnings.
pub warnings: Vec<String>,
}
Loading