|
| 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 | +} |
0 commit comments