Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit 56f1dcb

Browse files
committed
f Account for getnetworkinfo returing array of warnings now
1 parent f1ed6ec commit 56f1dcb

File tree

5 files changed

+87
-5
lines changed

5 files changed

+87
-5
lines changed

json/src/model/network.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct GetNetworkInfo {
3636
/// List of local addresses.
3737
pub local_addresses: Vec<GetNetworkInfoAddress>,
3838
/// Any network and blockchain warnings.
39-
pub warnings: String,
39+
pub warnings: Vec<String>,
4040
}
4141

4242
/// Part of the result of the JSON-RPC method `getnetworkinfo` (information per network).

json/src/v17/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ pub use self::{
182182
generating::{Generate, GenerateToAddress},
183183
network::{
184184
AddedNode, AddedNodeAddress, Banned, GetAddedNodeInfo, GetNetTotals, GetNetworkInfo,
185-
GetNetworkInfoAddress, GetNetworkInfoNetwork, GetPeerInfo, ListBanned, PeerInfo,
186-
UploadTarget,
185+
GetNetworkInfoAddress, GetNetworkInfoError, GetNetworkInfoNetwork, GetPeerInfo, ListBanned,
186+
PeerInfo, UploadTarget,
187187
},
188188
raw_transactions::SendRawTransaction,
189189
wallet::{

json/src/v17/network.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl GetNetworkInfo {
177177
relay_fee,
178178
incremental_fee,
179179
local_addresses: self.local_addresses.into_iter().map(|a| a.into_model()).collect(),
180-
warnings: self.warnings,
180+
warnings: vec![self.warnings],
181181
})
182182
}
183183
}

json/src/v28/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,15 @@
180180
//! **== Zmq ==**
181181
//! - [ ] `getzmqnotifications`
182182
183+
mod network;
184+
185+
#[doc(inline)]
186+
pub use self::network::GetNetworkInfo;
183187
#[doc(inline)]
184188
pub use crate::{
185189
v17::{
186190
GenerateToAddress, GetBalance, GetBestBlockHash, GetBlockVerbosityOne,
187-
GetBlockVerbosityZero, GetNetworkInfo, GetNetworkInfoAddress, GetNetworkInfoNetwork,
191+
GetBlockVerbosityZero, GetNetworkInfoAddress, GetNetworkInfoError, GetNetworkInfoNetwork,
188192
GetNewAddress, GetTransaction, GetTransactionDetail, GetTransactionDetailCategory,
189193
GetTxOut, SendRawTransaction,
190194
},

json/src/v28/network.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! The JSON-RPC API for Bitcoin Core v28.0 - network.
4+
//!
5+
//! Types for methods found under the `== Network ==` section of the API docs.
6+
use serde::{Deserialize, Serialize};
7+
8+
use super::{GetNetworkInfoAddress, GetNetworkInfoError, GetNetworkInfoNetwork};
9+
use crate::model;
10+
11+
/// Result of the JSON-RPC method `getnetworkinfo`.
12+
///
13+
/// > getnetworkinfo
14+
///
15+
/// > Returns an object containing various state info regarding P2P networking.
16+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
17+
pub struct GetNetworkInfo {
18+
/// The server version.
19+
pub version: usize,
20+
/// The server subversion string.
21+
pub subversion: String,
22+
/// The protocol version.
23+
#[serde(rename = "protocolversion")]
24+
pub protocol_version: usize,
25+
/// The services we offer to the network (hex string).
26+
#[serde(rename = "localservices")]
27+
pub local_services: String,
28+
/// `true` if transaction relay is requested from peers.
29+
#[serde(rename = "localrelay")]
30+
pub local_relay: bool,
31+
/// The time offset.
32+
#[serde(rename = "timeoffset")]
33+
pub time_offset: isize,
34+
/// The total number of connections.
35+
pub connections: usize,
36+
/// Whether p2p networking is enabled.
37+
#[serde(rename = "networkactive")]
38+
pub network_active: bool,
39+
/// Information per network.
40+
pub networks: Vec<GetNetworkInfoNetwork>,
41+
/// Minimum relay fee rate for transactions in BTC/kB.
42+
#[serde(rename = "relayfee")]
43+
pub relay_fee: f64,
44+
/// Minimum fee rate increment for mempool limiting or replacement in BTC/kB.
45+
#[serde(rename = "incrementalfee")]
46+
pub incremental_fee: f64,
47+
/// List of local addresses.
48+
#[serde(rename = "localaddresses")]
49+
pub local_addresses: Vec<GetNetworkInfoAddress>,
50+
/// Any network and blockchain warnings.
51+
pub warnings: Vec<String>,
52+
}
53+
54+
impl GetNetworkInfo {
55+
/// Converts version specific type to a version in-specific, more strongly typed type.
56+
pub fn into_model(self) -> Result<model::GetNetworkInfo, GetNetworkInfoError> {
57+
use GetNetworkInfoError as E;
58+
59+
let relay_fee = crate::btc_per_kb(self.relay_fee).map_err(E::RelayFee)?;
60+
let incremental_fee = crate::btc_per_kb(self.incremental_fee).map_err(E::IncrementalFee)?;
61+
62+
Ok(model::GetNetworkInfo {
63+
version: self.version,
64+
subversion: self.subversion,
65+
protocol_version: self.protocol_version,
66+
local_services: self.local_services,
67+
local_relay: self.local_relay,
68+
time_offset: self.time_offset,
69+
connections: self.connections,
70+
network_active: self.network_active,
71+
networks: self.networks.into_iter().map(|n| n.into_model()).collect(),
72+
relay_fee,
73+
incremental_fee,
74+
local_addresses: self.local_addresses.into_iter().map(|a| a.into_model()).collect(),
75+
warnings: self.warnings,
76+
})
77+
}
78+
}

0 commit comments

Comments
 (0)