bitcoind_request/command/get_network_info.rs
1/*
2getnetworkinfo
3Returns an object containing various state info regarding P2P networking.
4
5Result:
6{ (json object)
7 "version" : n, (numeric) the server version
8 "subversion" : "str", (string) the server subversion string
9 "protocolversion" : n, (numeric) the protocol version
10 "localservices" : "hex", (string) the services we offer to the network
11 "localservicesnames" : [ (json array) the services we offer to the network, in human-readable form
12 "str", (string) the service name
13 ...
14 ],
15 "localrelay" : true|false, (boolean) true if transaction relay is requested from peers
16 "timeoffset" : n, (numeric) the time offset
17 "connections" : n, (numeric) the total number of connections
18 "connections_in" : n, (numeric) the number of inbound connections
19 "connections_out" : n, (numeric) the number of outbound connections
20 "networkactive" : true|false, (boolean) whether p2p networking is enabled
21 "networks" : [ (json array) information per network
22 { (json object)
23 "name" : "str", (string) network (ipv4, ipv6, onion, i2p)
24 "limited" : true|false, (boolean) is the network limited using -onlynet?
25 "reachable" : true|false, (boolean) is the network reachable?
26 "proxy" : "str", (string) ("host:port") the proxy that is used for this network, or empty if none
27 "proxy_randomize_credentials" : true|false (boolean) Whether randomized credentials are used
28 },
29 ...
30 ],
31 "relayfee" : n, (numeric) minimum relay fee rate for transactions in BTC/kvB
32 "incrementalfee" : n, (numeric) minimum fee rate increment for mempool limiting or BIP 125 replacement in BTC/kvB
33 "localaddresses" : [ (json array) list of local addresses
34 { (json object)
35 "address" : "str", (string) network address
36 "port" : n, (numeric) network port
37 "score" : n (numeric) relative score
38 },
39 ...
40 ],
41 "warnings" : "str" (string) any network and blockchain warnings
42}
43
44Examples:
45> bitcoin-cli getnetworkinfo
46> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getnetworkinfo", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
47*/
48use crate::client::Client;
49use crate::command::request::request;
50use crate::command::CallableCommand;
51use serde::Deserialize;
52use serde::Serialize;
53use serde_json::value::RawValue;
54
55pub struct GetNetworkInfoCommand {}
56impl GetNetworkInfoCommand {
57 pub fn new() -> Self {
58 GetNetworkInfoCommand {}
59 }
60}
61
62#[derive(Serialize, Deserialize, Debug)]
63pub struct Network {
64 pub name: String,
65 pub limited: bool,
66 pub reachable: bool,
67 pub proxy: String,
68 pub proxy_randomize_credentials: bool,
69}
70#[derive(Serialize, Deserialize, Debug)]
71pub struct LocalAddress {
72 pub address: String,
73 pub port: u64,
74 pub score: u64,
75}
76#[derive(Serialize, Deserialize, Debug)]
77pub struct GetNetworkInfoCommandResponse {
78 pub version: u64,
79 pub subversion: String,
80 pub protocolversion: u64,
81 pub localservices: String,
82 pub localservicesnames: Vec<String>,
83 pub localrelay: bool,
84 pub timeoffset: u64,
85 pub connections: u64,
86 pub connections_in: u64,
87 pub connections_out: u64,
88 pub networkactive: bool,
89 pub networks: Vec<Network>,
90 pub relayfee: f64,
91 pub incrementalfee: f64,
92 pub localaddresses: Vec<LocalAddress>,
93 pub warnings: String,
94}
95
96impl CallableCommand for GetNetworkInfoCommand {
97 type Response = GetNetworkInfoCommandResponse;
98 fn call(&self, client: &Client) -> Result<Self::Response, jsonrpc::Error> {
99 let command = "getnetworkinfo";
100 let params: Vec<Box<RawValue>> = vec![];
101 let r = request(client, command, params);
102 let response: GetNetworkInfoCommandResponse = r.result()?;
103 Ok(response)
104 }
105}