Skip to content

Commit 71a6018

Browse files
committed
Merge #154: Implement getnodeaddresses method and test
4c4d8ba Run cargo format (Jamil Lambert, PhD) 0c676c7 Add v18 getnodeaddresses, test and reexport (Jamil Lambert, PhD) Pull request description: Implement the `getnodeaddresses` method added in V18, including integration test and reexports in newer versions. ACKs for top commit: tcharding: ACK 4c4d8ba Tree-SHA512: 44469f2140c808cd76fdf3b7b363951e90c73fefda974493fb4870816ec28b8dc7862a428a7b4c16bb95bf86eb9d7bab00678f7678de8339324543eabdaeee06
2 parents 1670c1c + 4c4d8ba commit 71a6018

File tree

25 files changed

+109
-21
lines changed

25 files changed

+109
-21
lines changed

client/src/client_sync/v18/mod.rs

+2
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

+22
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

+1
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

+14
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

+3-1
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

+28
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

+3-2
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 | |
@@ -274,5 +274,6 @@ pub use crate::v17::{
274274
#[doc(inline)]
275275
pub use crate::v18::{
276276
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
277-
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
277+
AnalyzePsbtInputMissingError, GetNodeAddresses, GetRpcInfo, JoinPsbts, NodeAddress,
278+
UtxoUpdatePsbt,
278279
};

types/src/v20/mod.rs

+3-2
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 | |
@@ -266,7 +266,8 @@ pub use crate::{
266266
},
267267
v18::{
268268
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
269-
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
269+
AnalyzePsbtInputMissingError, GetNodeAddresses, GetRpcInfo, JoinPsbts, NodeAddress,
270+
UtxoUpdatePsbt,
270271
},
271272
v19::{
272273
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v21/mod.rs

+3-2
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 | |
@@ -272,7 +272,8 @@ pub use crate::{
272272
},
273273
v18::{
274274
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
275-
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
275+
AnalyzePsbtInputMissingError, GetNodeAddresses, GetRpcInfo, JoinPsbts, NodeAddress,
276+
UtxoUpdatePsbt,
276277
},
277278
v19::{
278279
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v22/mod.rs

+3-2
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 | |
@@ -286,7 +286,8 @@ pub use crate::{
286286
},
287287
v18::{
288288
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
289-
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
289+
AnalyzePsbtInputMissingError, GetNodeAddresses, GetRpcInfo, JoinPsbts, NodeAddress,
290+
UtxoUpdatePsbt,
290291
},
291292
v19::{
292293
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v23/mod.rs

+3-2
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 | |
@@ -281,7 +281,8 @@ pub use crate::{
281281
},
282282
v18::{
283283
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
284-
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
284+
AnalyzePsbtInputMissingError, GetNodeAddresses, GetRpcInfo, JoinPsbts, NodeAddress,
285+
UtxoUpdatePsbt,
285286
},
286287
v19::{
287288
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v24/mod.rs

+3-2
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 | |
@@ -282,7 +282,8 @@ pub use crate::{
282282
},
283283
v18::{
284284
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
285-
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
285+
AnalyzePsbtInputMissingError, GetNodeAddresses, GetRpcInfo, JoinPsbts, NodeAddress,
286+
UtxoUpdatePsbt,
286287
},
287288
v19::{
288289
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v25/mod.rs

+3-2
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 | |
@@ -279,7 +279,8 @@ pub use crate::{
279279
},
280280
v18::{
281281
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
282-
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
282+
AnalyzePsbtInputMissingError, GetNodeAddresses, GetRpcInfo, JoinPsbts, NodeAddress,
283+
UtxoUpdatePsbt,
283284
},
284285
v19::{
285286
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v26/mod.rs

+3-2
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 | |
@@ -299,7 +299,8 @@ pub use crate::{
299299
},
300300
v18::{
301301
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
302-
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
302+
AnalyzePsbtInputMissingError, GetNodeAddresses, GetRpcInfo, JoinPsbts, NodeAddress,
303+
UtxoUpdatePsbt,
303304
},
304305
v19::{
305306
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v27/mod.rs

+3-2
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 | |
@@ -283,7 +283,8 @@ pub use crate::{
283283
},
284284
v18::{
285285
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
286-
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
286+
AnalyzePsbtInputMissingError, GetNodeAddresses, GetRpcInfo, JoinPsbts, NodeAddress,
287+
UtxoUpdatePsbt,
287288
},
288289
v19::{
289290
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

types/src/v28/mod.rs

+3-2
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 | |
@@ -290,7 +290,8 @@ pub use crate::{
290290
},
291291
v18::{
292292
ActiveCommand, AnalyzePsbt, AnalyzePsbtError, AnalyzePsbtInput, AnalyzePsbtInputMissing,
293-
AnalyzePsbtInputMissingError, GetRpcInfo, JoinPsbts, UtxoUpdatePsbt,
293+
AnalyzePsbtInputMissingError, GetNodeAddresses, GetRpcInfo, JoinPsbts, NodeAddress,
294+
UtxoUpdatePsbt,
294295
},
295296
v19::{
296297
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,

0 commit comments

Comments
 (0)