This patch adds a network field to RPC getnodeaddresses
, which is useful on its own, particularly with the addition of new networks like I2P and others in the future, and which I also found helpful for adding a new CLI command as a follow-up to this pull that calls getnodeaddresses
and needs to know the network of each address.
While here, also improve the getnodeaddresses
code and help.
0$ bitcoin-cli -signet getnodeaddresses 3
1[
2 {
3 "time": 1611564659,
4 "services": 1033,
5 "address": "2600:1702:3c30:734f:8f2e:744b:2a51:dfa5",
6 "port": 38333,
7 "network": "ipv6"
8 },
9 {
10 "time": 1617531931,
11 "services": 1033,
12 "address": "153.126.143.201",
13 "port": 38333,
14 "network": "ipv4"
15 },
16 {
17 "time": 1617473058,
18 "services": 1033,
19 "address": "nsgyo7begau4yecc46ljfecaykyzszcseapxmtu6adrfagfrrzrlngyd.onion",
20 "port": 38333,
21 "network": "onion"
22 }
23]
24
25$ bitcoin-cli help getnodeaddresses
26getnodeaddresses ( count )
27
28Return known addresses, which can potentially be used to find new nodes in the network.
29
30Arguments:
311. count (numeric, optional, default=1) The maximum number of addresses to return. Specify 0 to return all known addresses.
32
33Result:
34[ (json array)
35 { (json object)
36 "time" : xxx, (numeric) The UNIX epoch time when the node was last seen
37 "services" : n, (numeric) The services offered by the node
38 "address" : "str", (string) The address of the node
39 "port" : n, (numeric) The port number of the node
40 "network" : "str" (string) The network (ipv4, ipv6, onion, i2p) the node connected through
41 },
42 ...
43]
Future idea: allow passing getnodeaddresses
a network (or networks) as an argument to return only addresses in that network.