Skip to content

Commit 0c676c7

Browse files
committed
Add v18 getnodeaddresses, test and reexport
Add `GetNodeAddresses` and `NodeAddress` to v18 types. Remove the todo in the tables and reexport the methods in newer versions. Add macro to clients for v18 getnodeaddresses Add the macro for the new function and reexport for all newer versions. Add integration test for v18 getnodeaddresses
1 parent 1670c1c commit 0c676c7

File tree

25 files changed

+99
-11
lines changed

25 files changed

+99
-11
lines changed

client/src/client_sync/v18/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! We ignore option arguments unless they effect the shape of the returned JSON data.
66
77
pub mod control;
8+
pub mod network;
89
pub mod raw_transactions;
910

1011
use std::collections::BTreeMap;
@@ -74,6 +75,7 @@ crate::impl_client_v17__submitblock!();
7475
crate::impl_client_v17__getaddednodeinfo!();
7576
crate::impl_client_v17__getnettotals!();
7677
crate::impl_client_v17__getnetworkinfo!();
78+
crate::impl_client_v18__getnodeaddresses!();
7779
crate::impl_client_v17__getpeerinfo!();
7880

7981
// == Rawtransactions ==

client/src/client_sync/v18/network.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! Macros for implementing JSON-RPC methods on a client.
4+
//!
5+
//! Requires `Client` to be in scope.
6+
//!
7+
//! Specifically this is methods found under the `== Network ==` section of the
8+
//! API docs of Bitcoin Core `v0.18`.
9+
//!
10+
//! See, or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
11+
12+
/// Implements Bitcoin Core JSON-RPC API method `getnodeaddresses`
13+
#[macro_export]
14+
macro_rules! impl_client_v18__getnodeaddresses {
15+
() => {
16+
impl Client {
17+
pub fn get_node_addresses(&self) -> Result<GetNodeAddresses> {
18+
self.call("getnodeaddresses", &[])
19+
}
20+
}
21+
};
22+
}

client/src/client_sync/v19/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ crate::impl_client_v17__submitblock!();
7373
crate::impl_client_v17__getaddednodeinfo!();
7474
crate::impl_client_v17__getnettotals!();
7575
crate::impl_client_v17__getnetworkinfo!();
76+
crate::impl_client_v18__getnodeaddresses!();
7677
crate::impl_client_v17__getpeerinfo!();
7778

7879
// == Rawtransactions ==

client/src/client_sync/v20.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ crate::impl_client_v17__submitblock!();
7070
crate::impl_client_v17__getaddednodeinfo!();
7171
crate::impl_client_v17__getnettotals!();
7272
crate::impl_client_v17__getnetworkinfo!();
73+
crate::impl_client_v18__getnodeaddresses!();
7374
crate::impl_client_v17__getpeerinfo!();
7475

7576
// == Rawtransactions ==

client/src/client_sync/v21/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ crate::impl_client_v17__submitblock!();
7272
crate::impl_client_v17__getaddednodeinfo!();
7373
crate::impl_client_v17__getnettotals!();
7474
crate::impl_client_v17__getnetworkinfo!();
75+
crate::impl_client_v18__getnodeaddresses!();
7576
crate::impl_client_v17__getpeerinfo!();
7677

7778
// == Rawtransactions ==

client/src/client_sync/v22/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ crate::impl_client_v17__submitblock!();
7373
crate::impl_client_v17__getaddednodeinfo!();
7474
crate::impl_client_v17__getnettotals!();
7575
crate::impl_client_v17__getnetworkinfo!();
76+
crate::impl_client_v18__getnodeaddresses!();
7677
crate::impl_client_v17__getpeerinfo!();
7778

7879
// == Rawtransactions ==

client/src/client_sync/v23/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ crate::impl_client_v17__submitblock!();
7474
crate::impl_client_v17__getaddednodeinfo!();
7575
crate::impl_client_v17__getnettotals!();
7676
crate::impl_client_v17__getnetworkinfo!();
77+
crate::impl_client_v18__getnodeaddresses!();
7778
crate::impl_client_v17__getpeerinfo!();
7879

7980
// == Rawtransactions ==

client/src/client_sync/v24.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ crate::impl_client_v17__submitblock!();
7171
crate::impl_client_v17__getaddednodeinfo!();
7272
crate::impl_client_v17__getnettotals!();
7373
crate::impl_client_v17__getnetworkinfo!();
74+
crate::impl_client_v18__getnodeaddresses!();
7475
crate::impl_client_v17__getpeerinfo!();
7576

7677
// == Rawtransactions ==

client/src/client_sync/v25.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ crate::impl_client_v17__submitblock!();
7171
crate::impl_client_v17__getaddednodeinfo!();
7272
crate::impl_client_v17__getnettotals!();
7373
crate::impl_client_v17__getnetworkinfo!();
74+
crate::impl_client_v18__getnodeaddresses!();
7475
crate::impl_client_v17__getpeerinfo!();
7576

7677
// == Rawtransactions ==

client/src/client_sync/v26/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ crate::impl_client_v17__submitblock!();
7676
crate::impl_client_v17__getaddednodeinfo!();
7777
crate::impl_client_v17__getnettotals!();
7878
crate::impl_client_v17__getnetworkinfo!();
79+
crate::impl_client_v18__getnodeaddresses!();
7980
crate::impl_client_v17__getpeerinfo!();
8081

8182
// == Rawtransactions ==

client/src/client_sync/v27.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ crate::impl_client_v17__submitblock!();
7272
crate::impl_client_v17__getaddednodeinfo!();
7373
crate::impl_client_v17__getnettotals!();
7474
crate::impl_client_v17__getnetworkinfo!();
75+
crate::impl_client_v18__getnodeaddresses!();
7576
crate::impl_client_v17__getpeerinfo!();
7677

7778
// == Rawtransactions ==

client/src/client_sync/v28/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ crate::impl_client_v17__submitblock!();
7474
crate::impl_client_v17__getaddednodeinfo!();
7575
crate::impl_client_v17__getnettotals!();
7676
crate::impl_client_v17__getnetworkinfo!();
77+
crate::impl_client_v18__getnodeaddresses!();
7778
crate::impl_client_v17__getpeerinfo!();
7879

7980
// == Rawtransactions ==

integration_test/tests/network.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ fn network__get_network_info__modelled() {
3131
node.client.check_expected_server_version().expect("unexpected version");
3232
}
3333

34+
#[test]
35+
// Core version 18 onwards.
36+
#[cfg(not(feature = "v17"))]
37+
fn network__get_node_addresses() {
38+
let node = Node::with_wallet(Wallet::None, &[]);
39+
let json: GetNodeAddresses = node.client.get_node_addresses().expect("getnodeaddresses");
40+
assert!(json.0.len() <= 2500);
41+
if let Some(addr) = json.0.first() {
42+
assert!(addr.port > 0);
43+
assert!(!addr.address.is_empty());
44+
assert!(addr.time > 1231006505);
45+
}
46+
}
47+
3448
#[test]
3549
fn network__get_peer_info() {
3650
get_peer_info_one_node_network();

types/src/v18/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
//! | getconnectioncount | returns numeric | |
104104
//! | getnettotals | version | |
105105
//! | getnetworkinfo | version + model | |
106-
//! | getnodeaddresses | version | TODO |
106+
//! | getnodeaddresses | version | |
107107
//! | getpeerinfo | version | |
108108
//! | listbanned | returns string | |
109109
//! | ping | returns nothing | |
@@ -224,11 +224,13 @@
224224
225225
// JSON-RPC types by API section.
226226
mod control;
227+
mod network;
227228
mod raw_transactions;
228229

229230
#[doc(inline)]
230231
pub use self::{
231232
control::{ActiveCommand, GetRpcInfo},
233+
network::{GetNodeAddresses, NodeAddress},
232234
raw_transactions::{
233235
AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
234236
AnalyzePsbtInputMissingError, JoinPsbts, UtxoUpdatePsbt,

types/src/v18/network/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! The JSON-RPC API for Bitcoin Core `v0.18` - network.
4+
//!
5+
//! Types for methods found under the `== Network ==` section of the API docs.
6+
7+
use serde::{Deserialize, Serialize};
8+
9+
/// Result of JSON-RPC method `getnodeaddresses`.
10+
///
11+
/// > getnodeaddresses ( count )
12+
/// >
13+
/// > Return known addresses which can potentially be used to find new nodes in the network.
14+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
15+
pub struct GetNodeAddresses(pub Vec<NodeAddress>);
16+
17+
/// An item from the list returned by the JSON-RPC method `getnodeaddresses`.
18+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
19+
pub struct NodeAddress {
20+
/// Timestamp in seconds since epoch (Jan 1 1970 GMT) when the node was last seen.
21+
pub time: u64,
22+
/// The services offered.
23+
pub services: u64,
24+
/// The address of the node.
25+
pub address: String,
26+
/// The port of the node.
27+
pub port: u16,
28+
}

types/src/v19/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
//! | getconnectioncount | returns numeric | |
104104
//! | getnettotals | version | |
105105
//! | getnetworkinfo | version + model | |
106-
//! | getnodeaddresses | version | TODO |
106+
//! | getnodeaddresses | version | |
107107
//! | getpeerinfo | version | |
108108
//! | listbanned | returns string | |
109109
//! | ping | returns nothing | |
@@ -275,4 +275,5 @@ pub use crate::v17::{
275275
pub use crate::v18::{
276276
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
277277
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
278+
GetNodeAddresses, NodeAddress,
278279
};

types/src/v20/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
//! | getconnectioncount | returns numeric | |
105105
//! | getnettotals | version | |
106106
//! | getnetworkinfo | version + model | |
107-
//! | getnodeaddresses | version | TODO |
107+
//! | getnodeaddresses | version | |
108108
//! | getpeerinfo | version | |
109109
//! | listbanned | returns string | |
110110
//! | ping | returns nothing | |
@@ -267,6 +267,7 @@ pub use crate::{
267267
v18::{
268268
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
269269
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
270+
GetNodeAddresses, NodeAddress,
270271
},
271272
v19::{
272273
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v21/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
//! | getconnectioncount | returns numeric | |
106106
//! | getnettotals | version | |
107107
//! | getnetworkinfo | version + model | |
108-
//! | getnodeaddresses | version | TODO |
108+
//! | getnodeaddresses | version | |
109109
//! | getpeerinfo | version | |
110110
//! | listbanned | returns string | |
111111
//! | ping | returns nothing | |
@@ -273,6 +273,7 @@ pub use crate::{
273273
v18::{
274274
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
275275
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
276+
GetNodeAddresses, NodeAddress,
276277
},
277278
v19::{
278279
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v22/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
//! | getconnectioncount | returns numeric | |
106106
//! | getnettotals | version | |
107107
//! | getnetworkinfo | version + model | |
108-
//! | getnodeaddresses | version | TODO |
108+
//! | getnodeaddresses | version | |
109109
//! | getpeerinfo | version | |
110110
//! | listbanned | returns string | |
111111
//! | ping | returns nothing | |
@@ -287,6 +287,7 @@ pub use crate::{
287287
v18::{
288288
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
289289
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
290+
GetNodeAddresses, NodeAddress,
290291
},
291292
v19::{
292293
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v23/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
//! | getconnectioncount | returns numeric | |
9797
//! | getnettotals | version | |
9898
//! | getnetworkinfo | version + model | |
99-
//! | getnodeaddresses | version | TODO |
99+
//! | getnodeaddresses | version | |
100100
//! | getpeerinfo | version | |
101101
//! | listbanned | returns string | |
102102
//! | ping | returns nothing | |
@@ -282,6 +282,7 @@ pub use crate::{
282282
v18::{
283283
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
284284
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
285+
GetNodeAddresses, NodeAddress,
285286
},
286287
v19::{
287288
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v24/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
//! | getconnectioncount | returns numeric | |
9898
//! | getnettotals | version | |
9999
//! | getnetworkinfo | version + model | |
100-
//! | getnodeaddresses | version | TODO |
100+
//! | getnodeaddresses | version | |
101101
//! | getpeerinfo | version | |
102102
//! | listbanned | returns string | |
103103
//! | ping | returns nothing | |
@@ -283,6 +283,7 @@ pub use crate::{
283283
v18::{
284284
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
285285
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
286+
GetNodeAddresses, NodeAddress,
286287
},
287288
v19::{
288289
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v25/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
//! | getconnectioncount | returns numeric | |
9999
//! | getnettotals | version | |
100100
//! | getnetworkinfo | version + model | |
101-
//! | getnodeaddresses | version | TODO |
101+
//! | getnodeaddresses | version | |
102102
//! | getpeerinfo | version | |
103103
//! | listbanned | returns string | |
104104
//! | ping | returns nothing | |
@@ -280,6 +280,7 @@ pub use crate::{
280280
v18::{
281281
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
282282
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
283+
GetNodeAddresses, NodeAddress,
283284
},
284285
v19::{
285286
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v26/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
//! | getconnectioncount | returns numeric | |
105105
//! | getnettotals | version | |
106106
//! | getnetworkinfo | version + model | |
107-
//! | getnodeaddresses | version | TODO |
107+
//! | getnodeaddresses | version | |
108108
//! | getpeerinfo | version | |
109109
//! | listbanned | returns string | |
110110
//! | ping | returns nothing | |
@@ -300,6 +300,7 @@ pub use crate::{
300300
v18::{
301301
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
302302
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
303+
GetNodeAddresses, NodeAddress,
303304
},
304305
v19::{
305306
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v27/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
//! | getconnectioncount | returns numeric | |
105105
//! | getnettotals | version | |
106106
//! | getnetworkinfo | version + model | |
107-
//! | getnodeaddresses | version | TODO |
107+
//! | getnodeaddresses | version | |
108108
//! | getpeerinfo | version | |
109109
//! | listbanned | returns string | |
110110
//! | ping | returns nothing | |
@@ -284,6 +284,7 @@ pub use crate::{
284284
v18::{
285285
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
286286
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
287+
GetNodeAddresses, NodeAddress,
287288
},
288289
v19::{
289290
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v28/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
//! | getconnectioncount | returns numeric | |
105105
//! | getnettotals | version | |
106106
//! | getnetworkinfo | version + model | |
107-
//! | getnodeaddresses | version | TODO |
107+
//! | getnodeaddresses | version | |
108108
//! | getpeerinfo | version | |
109109
//! | listbanned | returns string | |
110110
//! | ping | returns nothing | |
@@ -291,6 +291,7 @@ pub use crate::{
291291
v18::{
292292
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
293293
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
294+
GetNodeAddresses, NodeAddress,
294295
},
295296
v19::{
296297
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

0 commit comments

Comments
 (0)