Skip to content

Commit

Permalink
Merge pull request #300 from LimpSquid/master
Browse files Browse the repository at this point in the history
Make getmempoolinfo compatible with supported RPC versions.
  • Loading branch information
stevenroose authored Apr 30, 2023
2 parents 41ff97b + d508785 commit 2017d6d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
31 changes: 31 additions & 0 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ fn main() {
test_wait_for_block(&cl);
test_get_descriptor_info(&cl);
test_derive_addresses(&cl);
test_get_mempool_info(&cl);
//TODO import_multi(
//TODO verify_message(
//TODO encrypt_wallet(&self, passphrase: &str) -> Result<()> {
Expand Down Expand Up @@ -1360,6 +1361,36 @@ fn test_derive_addresses(cl: &Client) {
assert!(cl.derive_addresses(descriptor, None).is_err()); // Range must be specified for a ranged descriptor
}

fn test_get_mempool_info(cl: &Client) {
let res = cl.get_mempool_info().unwrap();

if version() >= 190000 {
assert!(res.loaded.is_some());
} else {
assert!(res.loaded.is_none());
}

if version() >= 210000 {
assert!(res.unbroadcast_count.is_some());
} else {
assert!(res.unbroadcast_count.is_none());
}

if version() >= 220000 {
assert!(res.total_fee.is_some());
} else {
assert!(res.total_fee.is_none());
}

if version() >= 240000 {
assert!(res.incremental_relay_fee.is_some());
assert!(res.full_rbf.is_some());
} else {
assert!(res.incremental_relay_fee.is_none());
assert!(res.full_rbf.is_none());
}
}

fn test_get_index_info(cl: &Client) {
if version() >= 210000 {
let gii = cl.get_index_info().unwrap();
Expand Down
14 changes: 7 additions & 7 deletions json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,16 +1059,16 @@ pub enum ImportMultiRequestScriptPubkey<'a> {
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct GetMempoolInfoResult {
/// True if the mempool is fully loaded
pub loaded: bool,
pub loaded: Option<bool>,
/// Current tx count
pub size: usize,
/// Sum of all virtual transaction sizes as defined in BIP 141. Differs from actual serialized size because witness data is discounted
pub bytes: usize,
/// Total memory usage for the mempool
pub usage: usize,
/// Total fees for the mempool in BTC, ignoring modified fees through prioritisetransaction
#[serde(with = "bitcoin::amount::serde::as_btc")]
pub total_fee: Amount,
#[serde(default, with = "bitcoin::amount::serde::as_btc::opt")]
pub total_fee: Option<Amount>,
/// Maximum memory usage for the mempool
#[serde(rename = "maxmempool")]
pub max_mempool: usize,
Expand All @@ -1079,14 +1079,14 @@ pub struct GetMempoolInfoResult {
#[serde(rename = "minrelaytxfee", with = "bitcoin::amount::serde::as_btc")]
pub min_relay_tx_fee: Amount,
/// Minimum fee rate increment for mempool limiting or replacement in BTC/kvB
#[serde(rename = "incrementalrelayfee", with = "bitcoin::amount::serde::as_btc")]
pub incremental_relay_fee: Amount,
#[serde(rename = "incrementalrelayfee", default, with = "bitcoin::amount::serde::as_btc::opt")]
pub incremental_relay_fee: Option<Amount>,
/// Current number of transactions that haven't passed initial broadcast yet
#[serde(rename = "unbroadcastcount")]
pub unbroadcast_count: usize,
pub unbroadcast_count: Option<usize>,
/// True if the mempool accepts RBF without replaceability signaling inspection
#[serde(rename = "fullrbf")]
pub full_rbf: bool,
pub full_rbf: Option<bool>,
}

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

0 comments on commit 2017d6d

Please sign in to comment.