Skip to content

Commit 2017d6d

Browse files
authored
Merge pull request #300 from LimpSquid/master
Make getmempoolinfo compatible with supported RPC versions.
2 parents 41ff97b + d508785 commit 2017d6d

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

integration_test/src/main.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ fn main() {
213213
test_wait_for_block(&cl);
214214
test_get_descriptor_info(&cl);
215215
test_derive_addresses(&cl);
216+
test_get_mempool_info(&cl);
216217
//TODO import_multi(
217218
//TODO verify_message(
218219
//TODO encrypt_wallet(&self, passphrase: &str) -> Result<()> {
@@ -1360,6 +1361,36 @@ fn test_derive_addresses(cl: &Client) {
13601361
assert!(cl.derive_addresses(descriptor, None).is_err()); // Range must be specified for a ranged descriptor
13611362
}
13621363

1364+
fn test_get_mempool_info(cl: &Client) {
1365+
let res = cl.get_mempool_info().unwrap();
1366+
1367+
if version() >= 190000 {
1368+
assert!(res.loaded.is_some());
1369+
} else {
1370+
assert!(res.loaded.is_none());
1371+
}
1372+
1373+
if version() >= 210000 {
1374+
assert!(res.unbroadcast_count.is_some());
1375+
} else {
1376+
assert!(res.unbroadcast_count.is_none());
1377+
}
1378+
1379+
if version() >= 220000 {
1380+
assert!(res.total_fee.is_some());
1381+
} else {
1382+
assert!(res.total_fee.is_none());
1383+
}
1384+
1385+
if version() >= 240000 {
1386+
assert!(res.incremental_relay_fee.is_some());
1387+
assert!(res.full_rbf.is_some());
1388+
} else {
1389+
assert!(res.incremental_relay_fee.is_none());
1390+
assert!(res.full_rbf.is_none());
1391+
}
1392+
}
1393+
13631394
fn test_get_index_info(cl: &Client) {
13641395
if version() >= 210000 {
13651396
let gii = cl.get_index_info().unwrap();

json/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,16 +1059,16 @@ pub enum ImportMultiRequestScriptPubkey<'a> {
10591059
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
10601060
pub struct GetMempoolInfoResult {
10611061
/// True if the mempool is fully loaded
1062-
pub loaded: bool,
1062+
pub loaded: Option<bool>,
10631063
/// Current tx count
10641064
pub size: usize,
10651065
/// Sum of all virtual transaction sizes as defined in BIP 141. Differs from actual serialized size because witness data is discounted
10661066
pub bytes: usize,
10671067
/// Total memory usage for the mempool
10681068
pub usage: usize,
10691069
/// Total fees for the mempool in BTC, ignoring modified fees through prioritisetransaction
1070-
#[serde(with = "bitcoin::amount::serde::as_btc")]
1071-
pub total_fee: Amount,
1070+
#[serde(default, with = "bitcoin::amount::serde::as_btc::opt")]
1071+
pub total_fee: Option<Amount>,
10721072
/// Maximum memory usage for the mempool
10731073
#[serde(rename = "maxmempool")]
10741074
pub max_mempool: usize,
@@ -1079,14 +1079,14 @@ pub struct GetMempoolInfoResult {
10791079
#[serde(rename = "minrelaytxfee", with = "bitcoin::amount::serde::as_btc")]
10801080
pub min_relay_tx_fee: Amount,
10811081
/// Minimum fee rate increment for mempool limiting or replacement in BTC/kvB
1082-
#[serde(rename = "incrementalrelayfee", with = "bitcoin::amount::serde::as_btc")]
1083-
pub incremental_relay_fee: Amount,
1082+
#[serde(rename = "incrementalrelayfee", default, with = "bitcoin::amount::serde::as_btc::opt")]
1083+
pub incremental_relay_fee: Option<Amount>,
10841084
/// Current number of transactions that haven't passed initial broadcast yet
10851085
#[serde(rename = "unbroadcastcount")]
1086-
pub unbroadcast_count: usize,
1086+
pub unbroadcast_count: Option<usize>,
10871087
/// True if the mempool accepts RBF without replaceability signaling inspection
10881088
#[serde(rename = "fullrbf")]
1089-
pub full_rbf: bool,
1089+
pub full_rbf: Option<bool>,
10901090
}
10911091

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

0 commit comments

Comments
 (0)