Skip to content

Commit 4c32f09

Browse files
committed
Add missing fields to getnetworkinfo, getpeerinfo
getnetworkinfo had missing fields in v21 and v28. getpeerinfo had missing fields in multiple versions. Redefine the types with the missing fields. Add the fields to the `GetNetworkInfo` model and update the into functions. Update the reexports.
1 parent 56ffb4f commit 4c32f09

File tree

19 files changed

+738
-16
lines changed

19 files changed

+738
-16
lines changed

types/src/model/network.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ pub struct GetNetworkInfo {
2828
pub time_offset: isize,
2929
/// The total number of connections.
3030
pub connections: usize,
31+
/// The number of inbound connections. v28 and later only.
32+
pub connections_in: Option<usize>,
33+
/// The number of outbound connections. v28 and later only.
34+
pub connections_out: Option<usize>,
3135
/// Whether p2p networking is enabled.
3236
pub network_active: bool,
3337
/// Information per network.

types/src/v17/network/into.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ impl GetNetworkInfo {
2121
local_relay: self.local_relay,
2222
time_offset: self.time_offset,
2323
connections: self.connections,
24+
connections_in: None,
25+
connections_out: None,
2426
network_active: self.network_active,
2527
networks: self.networks.into_iter().map(|n| n.into_model()).collect(),
2628
relay_fee,

types/src/v19/network/into.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ impl GetNetworkInfo {
2020
local_relay: self.local_relay,
2121
time_offset: self.time_offset,
2222
connections: self.connections,
23+
connections_in: None,
24+
connections_out: None,
2325
network_active: self.network_active,
2426
networks: self.networks.into_iter().map(|n| n.into_model()).collect(),
2527
relay_fee,

types/src/v21/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@
233233
234234
// JSON-RPC types by API section.
235235
mod blockchain;
236+
mod network;
236237
mod wallet;
237238

238239
#[doc(inline)]
@@ -241,6 +242,7 @@ pub use self::{
241242
Bip9SoftforkInfo, GetBlockchainInfo, GetMempoolEntry, GetMempoolInfo, Softfork,
242243
SoftforkType,
243244
},
245+
network::{GetNetworkInfo, GetPeerInfo},
244246
wallet::UnloadWallet,
245247
};
246248
#[doc(inline)]
@@ -289,7 +291,7 @@ pub use crate::{
289291
GetBalancesWatchOnly, GetBlockFilter, GetBlockFilterError,
290292
GetBlockchainInfoError, GetChainTxStats, GetDescriptorInfo, GetMempoolAncestors,
291293
GetMempoolAncestorsVerbose, GetMempoolDescendants, GetMempoolDescendantsVerbose,
292-
GetNetworkInfo, GetPeerInfo, GetRpcInfo, MapMempoolEntryError,
294+
GetRpcInfo, MapMempoolEntryError,
293295
MempoolEntry, MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, PeerInfo,
294296
},
295297
v20::{Banned, CreateMultisig, ListBanned, Logging},

types/src/v21/network/into.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
use super::{GetNetworkInfo, GetNetworkInfoError};
4+
use crate::model;
5+
6+
impl GetNetworkInfo {
7+
/// Converts version specific type to a version nonspecific, more strongly typed type.
8+
pub fn into_model(self) -> Result<model::GetNetworkInfo, GetNetworkInfoError> {
9+
use GetNetworkInfoError as E;
10+
11+
let relay_fee = crate::btc_per_kb(self.relay_fee).map_err(E::RelayFee)?;
12+
let incremental_fee = crate::btc_per_kb(self.incremental_fee).map_err(E::IncrementalFee)?;
13+
14+
Ok(model::GetNetworkInfo {
15+
version: self.version,
16+
subversion: self.subversion,
17+
protocol_version: self.protocol_version,
18+
local_services: self.local_services,
19+
local_services_names: Some(self.local_services_names),
20+
local_relay: self.local_relay,
21+
time_offset: self.time_offset,
22+
connections: self.connections,
23+
connections_in: Some(self.connections_in),
24+
connections_out: Some(self.connections_out),
25+
network_active: self.network_active,
26+
networks: self.networks.into_iter().map(|n| n.into_model()).collect(),
27+
relay_fee,
28+
incremental_fee,
29+
local_addresses: self.local_addresses.into_iter().map(|a| a.into_model()).collect(),
30+
warnings: vec![self.warnings],
31+
})
32+
}
33+
}

types/src/v21/network/mod.rs

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! The JSON-RPC API for Bitcoin Core `v0.21` - network.
4+
//!
5+
//! Types for methods found under the `== Network ==` section of the API docs.
6+
7+
mod into;
8+
9+
use alloc::collections::BTreeMap;
10+
11+
use serde::{Deserialize, Serialize};
12+
13+
use super::{GetNetworkInfoAddress, GetNetworkInfoError, GetNetworkInfoNetwork};
14+
15+
/// Result of the JSON-RPC method `getnetworkinfo`.
16+
///
17+
/// > getnetworkinfo
18+
///
19+
/// > Returns an object containing various state info regarding P2P networking.
20+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
21+
pub struct GetNetworkInfo {
22+
/// The server version.
23+
pub version: usize,
24+
/// The server subversion string.
25+
pub subversion: String,
26+
/// The protocol version.
27+
#[serde(rename = "protocolversion")]
28+
pub protocol_version: usize,
29+
/// The services we offer to the network (hex string).
30+
#[serde(rename = "localservices")]
31+
pub local_services: String,
32+
/// The services we offer to the network. v0.19 and later only.
33+
#[serde(rename = "localservicesnames")]
34+
pub local_services_names: Vec<String>,
35+
/// `true` if transaction relay is requested from peers.
36+
#[serde(rename = "localrelay")]
37+
pub local_relay: bool,
38+
/// The time offset.
39+
#[serde(rename = "timeoffset")]
40+
pub time_offset: isize,
41+
/// The total number of connections.
42+
pub connections: usize,
43+
/// The number of inbound connections. v21 and later only.
44+
pub connections_in: usize,
45+
/// The number of outbound connections. v21 and later only.
46+
pub connections_out: usize,
47+
/// Whether p2p networking is enabled.
48+
#[serde(rename = "networkactive")]
49+
pub network_active: bool,
50+
/// Information per network.
51+
pub networks: Vec<GetNetworkInfoNetwork>,
52+
/// Minimum relay fee rate for transactions in BTC/kB.
53+
#[serde(rename = "relayfee")]
54+
pub relay_fee: f64,
55+
/// Minimum fee rate increment for mempool limiting or replacement in BTC/kB.
56+
#[serde(rename = "incrementalfee")]
57+
pub incremental_fee: f64,
58+
/// List of local addresses.
59+
#[serde(rename = "localaddresses")]
60+
pub local_addresses: Vec<GetNetworkInfoAddress>,
61+
/// Any network and blockchain warnings.
62+
pub warnings: String,
63+
}
64+
65+
/// Result of JSON-RPC method `getpeerinfo`.
66+
///
67+
/// > getpeerinfo
68+
/// >
69+
/// > Returns data about each connected network node as a json array of objects.
70+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
71+
pub struct GetPeerInfo(pub Vec<PeerInfo>);
72+
73+
/// An item from the list returned by the JSON-RPC method `getpeerinfo`.
74+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
75+
pub struct PeerInfo {
76+
/// Peer index.
77+
pub id: u32,
78+
/// The IP address and port of the peer ("host:port").
79+
#[serde(rename = "addr")]
80+
pub address: String,
81+
/// Bind address of the connection to the peer ("ip:port").
82+
#[serde(rename = "addrbind")]
83+
pub address_bind: String,
84+
/// Local address as reported by the peer.
85+
#[serde(rename = "addrlocal")]
86+
pub address_local: Option<String>,
87+
/// Network (ipv4, ipv6, or onion) the peer connected through.
88+
pub network: Option<String>,
89+
/// The services offered.
90+
pub services: String,
91+
/// The services offered, in human-readable form. v0.19 and later only.
92+
#[serde(rename = "servicesnames")]
93+
pub services_names: Vec<String>,
94+
/// Whether peer has asked us to relay transactions to it.
95+
#[serde(rename = "relaytxes")]
96+
pub relay_transactions: bool,
97+
/// The time in seconds since epoch (Jan 1 1970 GMT) of the last send.
98+
#[serde(rename = "lastsend")]
99+
pub last_send: i64,
100+
/// The time in seconds since epoch (Jan 1 1970 GMT) of the last receive.
101+
#[serde(rename = "lastrecv")]
102+
pub last_received: i64,
103+
/// The UNIX epoch time of the last valid transaction received from this peer. v21 and later only.
104+
pub last_transaction: i64,
105+
/// The UNIX epoch time of the last block received from this peer. v21 and later only.
106+
pub last_block: i64,
107+
/// The total bytes sent.
108+
#[serde(rename = "bytessent")]
109+
pub bytes_sent: u64,
110+
/// The total bytes received.
111+
#[serde(rename = "bytesrecv")]
112+
pub bytes_received: u64,
113+
/// The connection time in seconds since epoch (Jan 1 1970 GMT).
114+
#[serde(rename = "conntime")]
115+
pub connection_time: i64,
116+
/// The time offset in seconds.
117+
#[serde(rename = "timeoffset")]
118+
pub time_offset: i64,
119+
/// Ping time (if available).
120+
#[serde(rename = "pingtime")]
121+
pub ping_time: Option<f64>,
122+
/// Minimum observed ping time (if any at all).
123+
#[serde(rename = "minping")]
124+
pub minimum_ping: Option<f64>,
125+
/// Ping wait (if non-zero).
126+
#[serde(rename = "pingwait")]
127+
pub ping_wait: Option<f64>,
128+
/// The peer version, such as 70001.
129+
pub version: u32,
130+
/// The string version (e.g. "/Satoshi:0.8.5/").
131+
#[serde(rename = "subver")]
132+
pub subversion: String,
133+
/// Inbound (true) or Outbound (false).
134+
pub inbound: bool,
135+
/// Whether connection was due to addnode/-connect or if it was an automatic/inbound connection.
136+
#[serde(rename = "addnode")]
137+
pub add_node: Option<bool>,
138+
/// The starting height (block) of the peer.
139+
#[serde(rename = "startingheight")]
140+
pub starting_height: i64,
141+
/// The ban score.
142+
#[serde(rename = "banscore")]
143+
pub ban_score: Option<i64>,
144+
/// The last header we have in common with this peer.
145+
pub synced_headers: i64,
146+
/// The last block we have in common with this peer.
147+
pub synced_blocks: i64,
148+
/// The heights of blocks we're currently asking from this peer.
149+
pub inflight: Vec<u64>,
150+
/// The total number of addresses processed, excluding those dropped due to rate limiting. v21 and
151+
/// later only.
152+
pub addr_processed: usize,
153+
/// The total number of addresses dropped due to rate limiting. v21 and later only.
154+
pub addr_rate_limited: usize,
155+
/// Any special permissions that have been granted to this peer. v0.19 and later only.
156+
pub permissions: Vec<String>,
157+
/// The minimum fee rate for transactions this peer accepts. v0.19 and later only.
158+
#[serde(rename = "minfeefilter")]
159+
pub minimum_fee_filter: f64,
160+
/// Whether the peer is whitelisted (deprecated in v0.21).
161+
pub whitelisted: Option<bool>,
162+
/// The total bytes sent aggregated by message type.
163+
#[serde(rename = "bytessent_per_msg")]
164+
pub bytes_sent_per_message: BTreeMap<String, u64>,
165+
/// The total bytes received aggregated by message type.
166+
#[serde(rename = "bytesrecv_per_msg")]
167+
pub bytes_received_per_message: BTreeMap<String, u64>,
168+
/// Type of connection.
169+
pub connection_type: Option<String>,
170+
}

types/src/v22/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ mod network;
251251
pub use self::{
252252
blockchain::GetMempoolInfo,
253253
control::Logging,
254-
network::{Banned, ListBanned},
254+
network::{Banned, GetPeerInfo, ListBanned},
255255
};
256256
#[doc(inline)]
257257
pub use crate::{
@@ -299,13 +299,13 @@ pub use crate::{
299299
GetBalancesWatchOnly, GetBlockFilter, GetBlockFilterError,
300300
GetBlockchainInfoError, GetChainTxStats, GetDescriptorInfo, GetMempoolAncestors,
301301
GetMempoolAncestorsVerbose, GetMempoolDescendants, GetMempoolDescendantsVerbose,
302-
GetNetworkInfo, GetPeerInfo, GetRpcInfo, MapMempoolEntryError,
302+
GetRpcInfo, MapMempoolEntryError,
303303
MempoolEntry, MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, PeerInfo,
304304
},
305305
v20::CreateMultisig,
306306
v21::{
307307
Bip9SoftforkInfo, GetBlockchainInfo, GetMempoolEntry, Softfork, SoftforkType,
308-
UnloadWallet,
308+
UnloadWallet, GetNetworkInfo,
309309
},
310310
ScriptPubkey,
311311
};

0 commit comments

Comments
 (0)