Skip to content

Commit f3a7d08

Browse files
committed
Redefine getmempoolentry type for version changes
The return types change in v19, v21, v23 and v24. Redefine the type for these versions with the changes. Update into functions and reexports.
1 parent 35862d5 commit f3a7d08

File tree

20 files changed

+477
-46
lines changed

20 files changed

+477
-46
lines changed

types/src/model/blockchain.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,12 @@ pub struct GetMempoolEntry(pub MempoolEntry);
383383
/// A relative (ancestor or descendant) transaction of a transaction in the mempool.
384384
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
385385
pub struct MempoolEntry {
386-
/// Virtual transaction size as defined in BIP 141.
386+
/// Virtual transaction size as defined in BIP 141. v0.19 and later only.
387387
///
388388
/// This is different from actual serialized size for witness transactions as witness data is discounted.
389-
///
390-
/// This was deprecated with Bitcoin Core v0.19 and hence will be `None` for v0.19 and later.
389+
pub vsize: Option<u32>,
390+
/// Same as vsize. This was deprecated with Bitcoin Core v0.19 and hence
391+
/// will be `None` for v0.19 and later.
391392
pub size: Option<u32>,
392393
/// Transaction weight as defined in BIP 141
393394
///
@@ -416,6 +417,9 @@ pub struct MempoolEntry {
416417
pub spent_by: Vec<Txid>,
417418
/// Whether this transaction could be replaced due to BIP125 (replace-by-fee)
418419
pub bip125_replaceable: Option<bool>,
420+
/// Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by
421+
/// any peers). v0.21 and later only.
422+
pub unbroadcast: Option<bool>,
419423
}
420424

421425
/// (No docs in Core v0.17.)

types/src/v17/blockchain/into.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ impl MempoolEntry {
413413
.map_err(E::SpentBy)?;
414414

415415
Ok(model::MempoolEntry {
416+
vsize: None,
416417
size,
417418
weight,
418419
time,
@@ -426,6 +427,7 @@ impl MempoolEntry {
426427
depends,
427428
spent_by,
428429
bip125_replaceable: None,
430+
unbroadcast: None,
429431
})
430432
}
431433
}

types/src/v18/blockchain/into.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl MempoolEntry {
4141
.map_err(E::SpentBy)?;
4242

4343
Ok(model::MempoolEntry {
44+
vsize: None,
4445
size,
4546
weight,
4647
time,
@@ -54,6 +55,7 @@ impl MempoolEntry {
5455
depends,
5556
spent_by,
5657
bip125_replaceable: Some(self.bip125_replaceable),
58+
unbroadcast: None,
5759
})
5860
}
5961
}

types/src/v19/blockchain/into.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ impl MempoolEntry {
124124
pub fn into_model(self) -> Result<model::MempoolEntry, MempoolEntryError> {
125125
use MempoolEntryError as E;
126126

127+
let vsize = Some(crate::to_u32(self.vsize, "vsize")?);
127128
let size = None;
128129
let weight = Some(crate::to_u32(self.weight, "weight")?);
129130
let time = crate::to_u32(self.time, "time")?;
@@ -148,6 +149,7 @@ impl MempoolEntry {
148149
.map_err(E::SpentBy)?;
149150

150151
Ok(model::MempoolEntry {
152+
vsize,
151153
size,
152154
weight,
153155
time,
@@ -161,6 +163,7 @@ impl MempoolEntry {
161163
depends,
162164
spent_by,
163165
bip125_replaceable: Some(self.bip125_replaceable),
166+
unbroadcast: None,
164167
})
165168
}
166169
}

types/src/v19/blockchain/mod.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,18 @@ pub struct GetMempoolEntry(pub MempoolEntry);
205205
pub struct MempoolEntry {
206206
/// Virtual transaction size as defined in BIP 141.
207207
///
208-
/// This is different from actual serialized size for witness transactions as witness data is discounted.
208+
/// This is different from actual serialized size for witness transactions as witness data is discounted. v0.19 and later only.
209+
pub vsize: i64,
210+
/// DEPRECATED: same as vsize. Only returned if bitcoind is started with -deprecatedrpc=size
211+
/// size will be completely removed in v0.20.
212+
pub size: Option<i64>,
213+
/// Transaction weight as defined in BIP 141.
209214
pub weight: i64,
215+
/// DEPRECATED: Transaction fee in BTC.
216+
pub fee: f64,
217+
/// DEPRECATED: Transaction fee with fee deltas used for mining priority.
218+
#[serde(rename = "modifiedfee")]
219+
pub modified_fee: f64,
210220
/// Local time transaction entered pool in seconds since 1 Jan 1970 GMT.
211221
pub time: i64,
212222
/// Block height when transaction entered pool.
@@ -217,15 +227,22 @@ pub struct MempoolEntry {
217227
/// Virtual transaction size of in-mempool descendants (including this one).
218228
#[serde(rename = "descendantsize")]
219229
pub descendant_size: i64,
230+
/// DEPRECATED: Modified fees (see above) of in-mempool descendants (including this one).
231+
#[serde(rename = "descendantfees")]
232+
pub descendant_fees: f64,
220233
/// Number of in-mempool ancestor transactions (including this one).
221234
#[serde(rename = "ancestorcount")]
222235
pub ancestor_count: i64,
223236
/// Virtual transaction size of in-mempool ancestors (including this one).
224237
#[serde(rename = "ancestorsize")]
225238
pub ancestor_size: i64,
239+
/// DEPRECATED: Modified fees (see above) of in-mempool ancestors (including this one).
240+
#[serde(rename = "ancestorfees")]
241+
pub ancestor_fees: f64,
226242
/// Hash of serialized transaction, including witness data.
227243
pub wtxid: String,
228-
/// (No docs in Core v0.19.)
244+
/// Fee object which contains the base fee, modified fee (with fee deltas), and
245+
/// ancestor/descendant fee totals all in BTC.
229246
pub fees: MempoolEntryFees,
230247
/// Unconfirmed transactions used as inputs for this transaction (parent transaction id).
231248
pub depends: Vec<String>,
@@ -237,7 +254,10 @@ pub struct MempoolEntry {
237254
pub bip125_replaceable: bool,
238255
}
239256

240-
/// (No docs in Core v0.19.)
257+
/// The `fees` field from the result of JSON-RPC method `getmempoolentry`.
258+
///
259+
/// Contains the base fee, modified fee (with fee deltas), and ancestor/descendant fee totals,
260+
/// all in BTC.
241261
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
242262
pub struct MempoolEntryFees {
243263
/// Transaction fee in BTC.

types/src/v21/blockchain/into.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
use bitcoin::{Txid, Wtxid};
4+
5+
use super::{GetMempoolEntry, MempoolEntry, MempoolEntryError};
6+
use crate::model;
7+
8+
impl GetMempoolEntry {
9+
/// Converts version specific type to a version nonspecific, more strongly typed type.
10+
pub fn into_model(self) -> Result<model::GetMempoolEntry, MempoolEntryError> {
11+
Ok(model::GetMempoolEntry(self.0.into_model()?))
12+
}
13+
}
14+
15+
impl MempoolEntry {
16+
/// Converts version specific type to a version nonspecific, more strongly typed type.
17+
pub fn into_model(self) -> Result<model::MempoolEntry, MempoolEntryError> {
18+
use MempoolEntryError as E;
19+
20+
let vsize = Some(crate::to_u32(self.vsize, "vsize")?);
21+
let size = None;
22+
let weight = Some(crate::to_u32(self.weight, "weight")?);
23+
let time = crate::to_u32(self.time, "time")?;
24+
let height = crate::to_u32(self.height, "height")?;
25+
let descendant_count = crate::to_u32(self.descendant_count, "descendant_count")?;
26+
let descendant_size = crate::to_u32(self.descendant_size, "descendant_size")?;
27+
let ancestor_count = crate::to_u32(self.ancestor_count, "ancestor_count")?;
28+
let ancestor_size = crate::to_u32(self.ancestor_size, "ancestor_size")?;
29+
let wtxid = self.wtxid.parse::<Wtxid>().map_err(E::Wtxid)?;
30+
let fees = self.fees.into_model().map_err(E::Fees)?;
31+
let depends = self
32+
.depends
33+
.iter()
34+
.map(|txid| txid.parse::<Txid>())
35+
.collect::<Result<Vec<_>, _>>()
36+
.map_err(E::Depends)?;
37+
let spent_by = self
38+
.spent_by
39+
.iter()
40+
.map(|txid| txid.parse::<Txid>())
41+
.collect::<Result<Vec<_>, _>>()
42+
.map_err(E::SpentBy)?;
43+
44+
Ok(model::MempoolEntry {
45+
vsize,
46+
size,
47+
weight,
48+
time,
49+
height,
50+
descendant_count,
51+
descendant_size,
52+
ancestor_count,
53+
ancestor_size,
54+
wtxid,
55+
fees,
56+
depends,
57+
spent_by,
58+
bip125_replaceable: Some(self.bip125_replaceable),
59+
unbroadcast: Some(self.unbroadcast),
60+
})
61+
}
62+
}

types/src/v21/blockchain/mod.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! The JSON-RPC API for Bitcoin Core `v0.21` - blockchain.
4+
//!
5+
//! Types for methods found under the `== Blockchain ==` section of the API docs.
6+
7+
mod into;
8+
9+
use serde::{Deserialize, Serialize};
10+
11+
pub use super::{MempoolEntryError, MempoolEntryFees};
12+
13+
/// Result of JSON-RPC method `getmempoolentry`.
14+
///
15+
/// > getmempoolentry txid
16+
/// >
17+
/// > Returns mempool data for given transaction
18+
/// >
19+
/// > Arguments:
20+
/// > 1. "txid" (string, required) The transaction id (must be in mempool)
21+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
22+
pub struct GetMempoolEntry(pub MempoolEntry);
23+
24+
/// A relative (ancestor or descendant) transaction of a transaction in the mempool.
25+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
26+
pub struct MempoolEntry {
27+
/// Virtual transaction size as defined in BIP 141.
28+
///
29+
/// This is different from actual serialized size for witness transactions as witness data is discounted. v0.19 and later only.
30+
pub vsize: i64,
31+
/// Transaction weight as defined in BIP 141.
32+
pub weight: i64,
33+
/// DEPRECATED: Transaction fee in BTC.
34+
pub fee: f64,
35+
/// DEPRECATED: Transaction fee with fee deltas used for mining priority.
36+
#[serde(rename = "modifiedfee")]
37+
pub modified_fee: f64,
38+
/// Local time transaction entered pool in seconds since 1 Jan 1970 GMT.
39+
pub time: i64,
40+
/// Block height when transaction entered pool.
41+
pub height: i64,
42+
/// Number of in-mempool descendant transactions (including this one).
43+
#[serde(rename = "descendantcount")]
44+
pub descendant_count: i64,
45+
/// Virtual transaction size of in-mempool descendants (including this one).
46+
#[serde(rename = "descendantsize")]
47+
pub descendant_size: i64,
48+
/// DEPRECATED: Modified fees (see above) of in-mempool descendants (including this one).
49+
#[serde(rename = "descendantfees")]
50+
pub descendant_fees: f64,
51+
/// Number of in-mempool ancestor transactions (including this one).
52+
#[serde(rename = "ancestorcount")]
53+
pub ancestor_count: i64,
54+
/// Virtual transaction size of in-mempool ancestors (including this one).
55+
#[serde(rename = "ancestorsize")]
56+
pub ancestor_size: i64,
57+
/// DEPRECATED: Modified fees (see above) of in-mempool ancestors (including this one).
58+
#[serde(rename = "ancestorfees")]
59+
pub ancestor_fees: f64,
60+
/// Hash of serialized transaction, including witness data.
61+
pub wtxid: String,
62+
/// Fee object which contains the base fee, modified fee (with fee deltas), and ancestor/descendant fee totals all in BTC.
63+
pub fees: MempoolEntryFees,
64+
/// Unconfirmed transactions used as inputs for this transaction (parent transaction id).
65+
pub depends: Vec<String>,
66+
/// Unconfirmed transactions spending outputs from this transaction (child transaction id).
67+
#[serde(rename = "spentby")]
68+
pub spent_by: Vec<String>,
69+
/// Whether this transaction could be replaced due to BIP125 (replace-by-fee)
70+
#[serde(rename = "bip125-replaceable")]
71+
pub bip125_replaceable: bool,
72+
/// Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by
73+
/// any peers)
74+
pub unbroadcast: bool,
75+
}

types/src/v21/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,11 @@
232232
//! </details>
233233
234234
// JSON-RPC types by API section.
235+
mod blockchain;
235236
mod wallet;
236237

237238
#[doc(inline)]
238-
pub use self::wallet::UnloadWallet;
239+
pub use self::{blockchain::GetMempoolEntry, wallet::UnloadWallet};
239240
#[doc(inline)]
240241
pub use crate::{
241242
v17::{
@@ -283,9 +284,8 @@ pub use crate::{
283284
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,
284285
GetBalancesWatchOnly, GetBlockFilter, GetBlockFilterError, GetBlockchainInfo,
285286
GetBlockchainInfoError, GetDescriptorInfo, GetMempoolAncestors, GetMempoolAncestorsVerbose,
286-
GetMempoolDescendants, GetMempoolDescendantsVerbose, GetMempoolEntry, MapMempoolEntryError,
287-
MempoolEntry, MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, Softfork,
288-
SoftforkType,
287+
GetMempoolDescendants, GetMempoolDescendantsVerbose, MapMempoolEntryError, MempoolEntry,
288+
MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, Softfork, SoftforkType,
289289
},
290290
v20::{Banned, ListBanned, Logging},
291291
};

types/src/v22/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,9 @@ pub use crate::{
298298
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,
299299
GetBalancesWatchOnly, GetBlockFilter, GetBlockFilterError, GetBlockchainInfo,
300300
GetBlockchainInfoError, GetDescriptorInfo, GetMempoolAncestors, GetMempoolAncestorsVerbose,
301-
GetMempoolDescendants, GetMempoolDescendantsVerbose, GetMempoolEntry, MapMempoolEntryError,
302-
MempoolEntry, MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, Softfork,
303-
SoftforkType,
301+
GetMempoolDescendants, GetMempoolDescendantsVerbose, MapMempoolEntryError, MempoolEntry,
302+
MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, Softfork, SoftforkType,
304303
},
305-
v21::UnloadWallet,
304+
v21::{GetMempoolEntry, UnloadWallet},
306305
ScriptPubkey,
307306
};

types/src/v23/blockchain/into.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
use bitcoin::{Txid, Wtxid};
4+
5+
use super::{GetMempoolEntry, MempoolEntry, MempoolEntryError};
6+
use crate::model;
7+
8+
impl GetMempoolEntry {
9+
/// Converts version specific type to a version nonspecific, more strongly typed type.
10+
pub fn into_model(self) -> Result<model::GetMempoolEntry, MempoolEntryError> {
11+
Ok(model::GetMempoolEntry(self.0.into_model()?))
12+
}
13+
}
14+
15+
impl MempoolEntry {
16+
/// Converts version specific type to a version nonspecific, more strongly typed type.
17+
pub fn into_model(self) -> Result<model::MempoolEntry, MempoolEntryError> {
18+
use MempoolEntryError as E;
19+
20+
let vsize = Some(crate::to_u32(self.vsize, "vsize")?);
21+
let size = None;
22+
let weight = Some(crate::to_u32(self.weight, "weight")?);
23+
let time = crate::to_u32(self.time, "time")?;
24+
let height = crate::to_u32(self.height, "height")?;
25+
let descendant_count = crate::to_u32(self.descendant_count, "descendant_count")?;
26+
let descendant_size = crate::to_u32(self.descendant_size, "descendant_size")?;
27+
let ancestor_count = crate::to_u32(self.ancestor_count, "ancestor_count")?;
28+
let ancestor_size = crate::to_u32(self.ancestor_size, "ancestor_size")?;
29+
let wtxid = self.wtxid.parse::<Wtxid>().map_err(E::Wtxid)?;
30+
let fees = self.fees.into_model().map_err(E::Fees)?;
31+
let depends = self
32+
.depends
33+
.iter()
34+
.map(|txid| txid.parse::<Txid>())
35+
.collect::<Result<Vec<_>, _>>()
36+
.map_err(E::Depends)?;
37+
let spent_by = self
38+
.spent_by
39+
.iter()
40+
.map(|txid| txid.parse::<Txid>())
41+
.collect::<Result<Vec<_>, _>>()
42+
.map_err(E::SpentBy)?;
43+
44+
Ok(model::MempoolEntry {
45+
vsize,
46+
size,
47+
weight,
48+
time,
49+
height,
50+
descendant_count,
51+
descendant_size,
52+
ancestor_count,
53+
ancestor_size,
54+
wtxid,
55+
fees,
56+
depends,
57+
spent_by,
58+
bip125_replaceable: Some(self.bip125_replaceable),
59+
unbroadcast: Some(self.unbroadcast),
60+
})
61+
}
62+
}

0 commit comments

Comments
 (0)