Skip to content

Commit 3bb6e7b

Browse files
committed
rpc: add network field to rpc getnodeaddresses
1 parent ad4bf8a commit 3bb6e7b

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

doc/release-notes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ Changes to Wallet or GUI related settings can be found in the GUI or Wallet sect
126126

127127
- Passing an invalid `-rpcauth` argument now cause bitcoind to fail to start. (#20461)
128128

129+
- The `getnodeaddresses` RPC now returns a "network" field indicating the
130+
network type (ipv4, ipv6, onion, or i2p) for each address. (#21594)
131+
129132
Tools and Utilities
130133
-------------------
131134

src/rpc/net.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ static RPCHelpMan getnodeaddresses()
848848
{RPCResult::Type::NUM, "services", "The services offered"},
849849
{RPCResult::Type::STR, "address", "The address of the node"},
850850
{RPCResult::Type::NUM, "port", "The port of the node"},
851+
{RPCResult::Type::STR, "network", "The network (" + Join(GetNetworkNames(), ", ") + ") the node connected through"},
851852
}},
852853
}
853854
},
@@ -879,6 +880,7 @@ static RPCHelpMan getnodeaddresses()
879880
obj.pushKV("services", (uint64_t)addr.nServices);
880881
obj.pushKV("address", addr.ToStringIP());
881882
obj.pushKV("port", addr.GetPort());
883+
obj.pushKV("network", GetNetworkName(addr.GetNetClass()));
882884
ret.push_back(obj);
883885
}
884886
return ret;

test/functional/rpc_net.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def test_getnodeaddresses(self):
195195
for i in range(10000):
196196
first_octet = i >> 8
197197
second_octet = i % 256
198-
a = "{}.{}.1.1".format(first_octet, second_octet)
198+
a = "{}.{}.1.1".format(first_octet, second_octet) # IPV4
199199
imported_addrs.append(a)
200200
self.nodes[0].addpeeraddress(a, 8333)
201201

@@ -212,6 +212,7 @@ def test_getnodeaddresses(self):
212212
assert_equal(a["services"], NODE_NETWORK | NODE_WITNESS)
213213
assert a["address"] in imported_addrs
214214
assert_equal(a["port"], 8333)
215+
assert_equal(a["network"], "ipv4")
215216

216217
node_addresses = self.nodes[0].getnodeaddresses(1)
217218
assert_equal(len(node_addresses), 1)

0 commit comments

Comments
 (0)