Skip to content

Commit b1f1461

Browse files
committed
Merge #251: Add missing return fields in v18
9c37a4b Run the formatter (Jamil Lambert, PhD) 97e8906 Add missing listunspent field in v18 (Jamil Lambert, PhD) 4c88282 Add missing getpeerinfo field in v18 (Jamil Lambert, PhD) 3636ffc Add missing getmempoolentry field in v18 (Jamil Lambert, PhD) Pull request description: Some of the types in v18 had missing return fields. Add all of the missing fields and update the models, into function and reexports accordingly. Redefinitions of the types and into functions are copies of the v17 versions with the missing field added. Run the formatter in a separate commit to make the changes to the reexports easier to review. ACKs for top commit: tcharding: ACK 9c37a4b Tree-SHA512: 148581b52193e8e2cef35c859e8c45b2f05e0b5a06e9fbfece5e35a64172b66f33fbaae375f666efe919a46ccc9161e00a6e68e6d7d6283df606c248c38ce142
2 parents f005c0f + 9c37a4b commit b1f1461

File tree

23 files changed

+393
-144
lines changed

23 files changed

+393
-144
lines changed

types/src/model/blockchain.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ pub struct MempoolEntry {
414414
pub depends: Vec<Txid>,
415415
/// Unconfirmed transactions spending outputs from this transaction (child transaction id).
416416
pub spent_by: Vec<Txid>,
417+
/// Whether this transaction could be replaced due to BIP125 (replace-by-fee)
418+
pub bip125_replaceable: Option<bool>,
417419
}
418420

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

types/src/model/wallet.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ pub struct ListUnspentItem {
610610
pub spendable: bool,
611611
/// Whether we know how to spend this output, ignoring the lack of keys.
612612
pub solvable: bool,
613+
/// A descriptor for spending this output (only when solvable)
614+
pub descriptor: Option<String>,
613615
/// Whether this output is considered safe to spend. Unconfirmed transactions from outside keys
614616
/// and unconfirmed replacement transactions are considered unsafe and are not eligible for
615617
/// spending by fundrawtransaction and sendtoaddress.

types/src/v17/blockchain/into.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ impl MempoolEntry {
425425
fees,
426426
depends,
427427
spent_by,
428+
bip125_replaceable: None,
428429
})
429430
}
430431
}

types/src/v17/wallet/into.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ impl ListUnspentItem {
668668
redeem_script,
669669
spendable: self.spendable,
670670
solvable: self.solvable,
671+
descriptor: None,
671672
safe: self.safe,
672673
})
673674
}

types/src/v18/blockchain/into.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 size = Some(crate::to_u32(self.size, "size")?);
21+
let weight = None;
22+
let time = crate::to_u32(self.time, "time")?;
23+
let height = crate::to_u32(self.height, "height")?;
24+
let descendant_count = crate::to_u32(self.descendant_count, "descendant_count")?;
25+
let descendant_size = crate::to_u32(self.descendant_size, "descendant_size")?;
26+
let ancestor_count = crate::to_u32(self.ancestor_count, "ancestor_count")?;
27+
let ancestor_size = crate::to_u32(self.ancestor_size, "ancestor_size")?;
28+
let wtxid = self.wtxid.parse::<Wtxid>().map_err(E::Wtxid)?;
29+
let fees = self.fees.into_model().map_err(E::Fees)?;
30+
let depends = self
31+
.depends
32+
.iter()
33+
.map(|txid| txid.parse::<Txid>())
34+
.collect::<Result<Vec<_>, _>>()
35+
.map_err(E::Depends)?;
36+
let spent_by = self
37+
.spent_by
38+
.iter()
39+
.map(|txid| txid.parse::<Txid>())
40+
.collect::<Result<Vec<_>, _>>()
41+
.map_err(E::SpentBy)?;
42+
43+
Ok(model::MempoolEntry {
44+
size,
45+
weight,
46+
time,
47+
height,
48+
descendant_count,
49+
descendant_size,
50+
ancestor_count,
51+
ancestor_size,
52+
wtxid,
53+
fees,
54+
depends,
55+
spent_by,
56+
bip125_replaceable: Some(self.bip125_replaceable),
57+
})
58+
}
59+
}

types/src/v18/blockchain/mod.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! The JSON-RPC API for Bitcoin Core `v0.18` - 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+
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.
30+
pub size: i64,
31+
/// DEPRECATED: Transaction fee in BTC.
32+
pub fee: f64,
33+
/// DEPRECATED: Transaction fee with fee deltas used for mining priority.
34+
#[serde(rename = "modifiedfee")]
35+
pub modified_fee: f64,
36+
/// Local time transaction entered pool in seconds since 1 Jan 1970 GMT.
37+
pub time: i64,
38+
/// Block height when transaction entered pool.
39+
pub height: i64,
40+
/// Number of in-mempool descendant transactions (including this one).
41+
#[serde(rename = "descendantcount")]
42+
pub descendant_count: i64,
43+
/// Virtual transaction size of in-mempool descendants (including this one).
44+
#[serde(rename = "descendantsize")]
45+
pub descendant_size: i64,
46+
/// DEPRECATED: Modified fees (see above) of in-mempool descendants (including this one).
47+
#[serde(rename = "descendantfees")]
48+
pub descendant_fees: f64,
49+
/// Number of in-mempool ancestor transactions (including this one).
50+
#[serde(rename = "ancestorcount")]
51+
pub ancestor_count: i64,
52+
/// Virtual transaction size of in-mempool ancestors (including this one).
53+
#[serde(rename = "ancestorsize")]
54+
pub ancestor_size: i64,
55+
/// DEPRECATED: Modified fees (see above) of in-mempool ancestors (including this one).
56+
#[serde(rename = "ancestorfees")]
57+
pub ancestor_fees: f64,
58+
/// Hash of serialized transaction, including witness data.
59+
pub wtxid: String,
60+
/// (No docs in Core v0.17.)
61+
pub fees: MempoolEntryFees,
62+
/// Unconfirmed transactions used as inputs for this transaction (parent transaction id).
63+
pub depends: Vec<String>,
64+
/// Unconfirmed transactions spending outputs from this transaction (child transaction id).
65+
#[serde(rename = "spentby")]
66+
pub spent_by: Vec<String>,
67+
/// Whether this transaction could be replaced due to BIP125 (replace-by-fee)
68+
#[serde(rename = "bip125-replaceable")]
69+
pub bip125_replaceable: bool,
70+
}

types/src/v18/mod.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@
223223
//! </details>
224224
225225
// JSON-RPC types by API section.
226+
mod blockchain;
226227
mod control;
227228
mod network;
228229
mod raw_transactions;
@@ -231,8 +232,9 @@ mod wallet;
231232

232233
#[doc(inline)]
233234
pub use self::{
235+
blockchain::{GetMempoolEntry, MempoolEntry},
234236
control::{ActiveCommand, GetRpcInfo},
235-
network::{GetNodeAddresses, NodeAddress},
237+
network::{GetNodeAddresses, GetPeerInfo, NodeAddress, PeerInfo},
236238
raw_transactions::{
237239
AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
238240
AnalyzePsbtInputMissingError, JoinPsbts, UtxoUpdatePsbt,
@@ -260,25 +262,24 @@ pub use crate::v17::{
260262
GetBlockchainInfo, GetBlockchainInfoError, GetChainTips, GetChainTxStats, GetChainTxStatsError,
261263
GetConnectionCount, GetDifficulty, GetMemoryInfoStats, GetMempoolAncestors,
262264
GetMempoolAncestorsVerbose, GetMempoolDescendants, GetMempoolDescendantsVerbose,
263-
GetMempoolEntry, GetMempoolInfo, GetMempoolInfoError, GetMiningInfo, GetNetTotals,
264-
GetNetworkInfo, GetNetworkInfoAddress, GetNetworkInfoError, GetNetworkInfoNetwork,
265-
GetNewAddress, GetPeerInfo, GetRawChangeAddress, GetRawMempool, GetRawMempoolVerbose,
266-
GetRawTransaction, GetRawTransactionVerbose, GetRawTransactionVerboseError,
267-
GetReceivedByAddress, GetTransaction, GetTransactionDetail, GetTransactionDetailError,
268-
GetTransactionError, GetTxOut, GetTxOutError, GetTxOutSetInfo, GetTxOutSetInfoError,
269-
GetUnconfirmedBalance, GetWalletInfo, GetWalletInfoError, GetZmqNotifications,
270-
ListAddressGroupings, ListAddressGroupingsError, ListAddressGroupingsItem, ListBanned,
271-
ListLabels, ListLockUnspent, ListLockUnspentItem, ListLockUnspentItemError,
272-
ListReceivedByAddress, ListReceivedByAddressError, ListReceivedByAddressItem, ListSinceBlock,
273-
ListSinceBlockError, ListSinceBlockTransaction, ListSinceBlockTransactionError,
274-
ListTransactions, ListTransactionsItem, ListTransactionsItemError, ListUnspentItemError,
275-
ListWallets, LoadWallet, Locked, Logging, MapMempoolEntryError, MempoolAcceptance,
276-
MempoolEntry, MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, PeerInfo,
277-
PruneBlockchain, PsbtInput, PsbtOutput, PsbtScript, RawTransaction, RawTransactionError,
278-
RawTransactionInput, RawTransactionOutput, RescanBlockchain, SendMany, SendRawTransaction,
279-
SendToAddress, SetNetworkActive, SignFail, SignFailError, SignMessage, SignMessageWithPrivKey,
280-
SignRawTransaction, SignRawTransactionError, Softfork, SoftforkReject, TestMempoolAccept,
281-
TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError, VerifyChain,
282-
VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt, WalletCreateFundedPsbtError,
283-
WalletProcessPsbt, WitnessUtxo,
265+
GetMempoolInfo, GetMempoolInfoError, GetMiningInfo, GetNetTotals, GetNetworkInfo,
266+
GetNetworkInfoAddress, GetNetworkInfoError, GetNetworkInfoNetwork, GetNewAddress,
267+
GetRawChangeAddress, GetRawMempool, GetRawMempoolVerbose, GetRawTransaction,
268+
GetRawTransactionVerbose, GetRawTransactionVerboseError, GetReceivedByAddress, GetTransaction,
269+
GetTransactionDetail, GetTransactionDetailError, GetTransactionError, GetTxOut, GetTxOutError,
270+
GetTxOutSetInfo, GetTxOutSetInfoError, GetUnconfirmedBalance, GetWalletInfo,
271+
GetWalletInfoError, GetZmqNotifications, ListAddressGroupings, ListAddressGroupingsError,
272+
ListAddressGroupingsItem, ListBanned, ListLabels, ListLockUnspent, ListLockUnspentItem,
273+
ListLockUnspentItemError, ListReceivedByAddress, ListReceivedByAddressError,
274+
ListReceivedByAddressItem, ListSinceBlock, ListSinceBlockError, ListSinceBlockTransaction,
275+
ListSinceBlockTransactionError, ListTransactions, ListTransactionsItem,
276+
ListTransactionsItemError, ListUnspentItemError, ListWallets, LoadWallet, Locked, Logging,
277+
MapMempoolEntryError, MempoolAcceptance, MempoolEntryError, MempoolEntryFees,
278+
MempoolEntryFeesError, PruneBlockchain, PsbtInput, PsbtOutput, PsbtScript, RawTransaction,
279+
RawTransactionError, RawTransactionInput, RawTransactionOutput, RescanBlockchain, SendMany,
280+
SendRawTransaction, SendToAddress, SetNetworkActive, SignFail, SignFailError, SignMessage,
281+
SignMessageWithPrivKey, SignRawTransaction, SignRawTransactionError, Softfork, SoftforkReject,
282+
TestMempoolAccept, TransactionCategory, UploadTarget, ValidateAddress, ValidateAddressError,
283+
VerifyChain, VerifyMessage, VerifyTxOutProof, WalletCreateFundedPsbt,
284+
WalletCreateFundedPsbtError, WalletProcessPsbt, WitnessUtxo,
284285
};

types/src/v18/network/mod.rs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
77
mod into;
88

9+
use alloc::collections::BTreeMap;
10+
911
use serde::{Deserialize, Serialize};
1012

1113
/// Result of JSON-RPC method `getnodeaddresses`.
@@ -28,3 +30,96 @@ pub struct NodeAddress {
2830
/// The port of the node.
2931
pub port: u16,
3032
}
33+
34+
/// Result of JSON-RPC method `getpeerinfo`.
35+
///
36+
/// > getpeerinfo
37+
/// >
38+
/// > Returns data about each connected network node as a json array of objects.
39+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
40+
pub struct GetPeerInfo(pub Vec<PeerInfo>);
41+
42+
/// An item from the list returned by the JSON-RPC method `getpeerinfo`.
43+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
44+
pub struct PeerInfo {
45+
/// Peer index.
46+
pub id: u32,
47+
/// The IP address and port of the peer ("host:port").
48+
#[serde(rename = "addr")]
49+
pub address: String,
50+
/// Bind address of the connection to the peer ("ip:port").
51+
#[serde(rename = "addrbind")]
52+
pub address_bind: String,
53+
/// Local address as reported by the peer.
54+
#[serde(rename = "addrlocal")]
55+
pub address_local: Option<String>,
56+
/// Network (ipv4, ipv6, or onion) the peer connected through.
57+
pub network: Option<String>,
58+
/// The services offered.
59+
pub services: String,
60+
/// Whether peer has asked us to relay transactions to it.
61+
#[serde(rename = "relaytxes")]
62+
pub relay_transactions: bool,
63+
/// The time in seconds since epoch (Jan 1 1970 GMT) of the last send.
64+
#[serde(rename = "lastsend")]
65+
pub last_send: i64,
66+
/// The time in seconds since epoch (Jan 1 1970 GMT) of the last receive.
67+
#[serde(rename = "lastrecv")]
68+
pub last_received: i64,
69+
/// The total bytes sent.
70+
#[serde(rename = "bytessent")]
71+
pub bytes_sent: u64,
72+
/// The total bytes received.
73+
#[serde(rename = "bytesrecv")]
74+
pub bytes_received: u64,
75+
/// The connection time in seconds since epoch (Jan 1 1970 GMT).
76+
#[serde(rename = "conntime")]
77+
pub connection_time: i64,
78+
/// The time offset in seconds.
79+
#[serde(rename = "timeoffset")]
80+
pub time_offset: i64,
81+
/// Ping time (if available).
82+
#[serde(rename = "pingtime")]
83+
pub ping_time: Option<f64>,
84+
/// Minimum observed ping time (if any at all).
85+
#[serde(rename = "minping")]
86+
pub minimum_ping: Option<f64>,
87+
/// Ping wait (if non-zero).
88+
#[serde(rename = "pingwait")]
89+
pub ping_wait: Option<f64>,
90+
/// The peer version, such as 70001.
91+
pub version: u32,
92+
/// The string version (e.g. "/Satoshi:0.8.5/").
93+
#[serde(rename = "subver")]
94+
pub subversion: String,
95+
/// Inbound (true) or Outbound (false).
96+
pub inbound: bool,
97+
/// Whether connection was due to addnode/-connect or if it was an automatic/inbound connection.
98+
#[serde(rename = "addnode")]
99+
pub add_node: Option<bool>,
100+
/// The starting height (block) of the peer.
101+
#[serde(rename = "startingheight")]
102+
pub starting_height: i64,
103+
/// The ban score.
104+
#[serde(rename = "banscore")]
105+
pub ban_score: Option<i64>,
106+
/// The last header we have in common with this peer.
107+
pub synced_headers: i64,
108+
/// The last block we have in common with this peer.
109+
pub synced_blocks: i64,
110+
/// The heights of blocks we're currently asking from this peer.
111+
pub inflight: Vec<u64>,
112+
/// Whether the peer is whitelisted (deprecated in v0.21).
113+
pub whitelisted: Option<bool>,
114+
/// The minimum fee rate for transactions this peer accepts.
115+
#[serde(rename = "minfeefilter")]
116+
pub min_fee_filter: Option<f64>,
117+
/// The total bytes sent aggregated by message type.
118+
#[serde(rename = "bytessent_per_msg")]
119+
pub bytes_sent_per_message: BTreeMap<String, u64>,
120+
/// The total bytes received aggregated by message type.
121+
#[serde(rename = "bytesrecv_per_msg")]
122+
pub bytes_received_per_message: BTreeMap<String, u64>,
123+
/// Type of connection.
124+
pub connection_type: Option<String>,
125+
}

types/src/v18/wallet/into.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ impl ListUnspentItem {
7272
.redeem_script
7373
.map(|hex| ScriptBuf::from_hex(&hex).map_err(E::RedeemScript))
7474
.transpose()?;
75-
7675
Ok(model::ListUnspentItem {
7776
txid,
7877
vout,
@@ -84,6 +83,7 @@ impl ListUnspentItem {
8483
redeem_script,
8584
spendable: self.spendable,
8685
solvable: self.solvable,
86+
descriptor: self.descriptor,
8787
safe: self.safe,
8888
})
8989
}

types/src/v18/wallet/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ pub struct ListUnspentItem {
7676
pub spendable: bool,
7777
/// Whether we know how to spend this output, ignoring the lack of keys.
7878
pub solvable: bool,
79+
/// A descriptor for spending this output (only when solvable)
80+
#[serde(rename = "desc")]
81+
pub descriptor: Option<String>,
7982
/// Whether this output is considered safe to spend. Unconfirmed transactions from outside keys
8083
/// and unconfirmed replacement transactions are considered unsafe and are not eligible for
8184
/// spending by fundrawtransaction and sendtoaddress.

0 commit comments

Comments
 (0)