Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit d007f78

Browse files
authored
v17: Add support for network methods (#39)
Add support to the `v17` client and integration tests for network section methods. Note, we do not implement `into_model` for the network methods because apart from `FeeRate` there are no `rust-bitcoin` types required. Note also `getaddednodeinfo` is untested because without configuring the network it returns an empty list so a test within the current framework would be smoke and mirrors.
2 parents e60ae79 + 81afb0d commit d007f78

File tree

8 files changed

+223
-174
lines changed

8 files changed

+223
-174
lines changed

client/src/client_sync/v17/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::client_sync::{handle_defaults, into_json};
1919
use crate::json::v17::*;
2020

2121
crate::define_jsonrpc_minreq_client!("v17");
22+
crate::impl_client_check_expected_server_version!({ [170100] });
2223

2324
// == Blockchain ==
2425
crate::impl_client_v17__getblockchaininfo!();
@@ -45,8 +46,9 @@ crate::impl_client_v17__generatetoaddress!();
4546
crate::impl_client_v17__generate!();
4647

4748
// == Network ==
49+
crate::impl_client_v17__getnettotals!();
4850
crate::impl_client_v17__getnetworkinfo!();
49-
crate::impl_client_check_expected_server_version!({ [170100] });
51+
crate::impl_client_v17__getpeerinfo!();
5052

5153
// == Rawtransactions ==
5254
crate::impl_client_v17__sendrawtransaction!();

client/src/client_sync/v17/network.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
//!
1010
//! See, or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
1111
12+
/// Implements bitcoind JSON-RPC API method `getnettotals`
13+
#[macro_export]
14+
macro_rules! impl_client_v17__getnettotals {
15+
() => {
16+
impl Client {
17+
pub fn get_net_totals(&self) -> Result<GetNetTotals> { self.call("getnettotals", &[]) }
18+
}
19+
};
20+
}
21+
1222
/// Implements bitcoind JSON-RPC API method `getnetworkinfo`
1323
#[macro_export]
1424
macro_rules! impl_client_v17__getnetworkinfo {
@@ -26,3 +36,13 @@ macro_rules! impl_client_v17__getnetworkinfo {
2636
}
2737
};
2838
}
39+
40+
/// Implements bitcoind JSON-RPC API method `getpeerinfo`
41+
#[macro_export]
42+
macro_rules! impl_client_v17__getpeerinfo {
43+
() => {
44+
impl Client {
45+
pub fn get_peer_info(&self) -> Result<GetPeerInfo> { self.call("getpeerinfo", &[]) }
46+
}
47+
};
48+
}

integration_test/src/v17/network.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,40 @@
55
//! Specifically this is methods found under the `== Network ==` section of the
66
//! API docs of `bitcoind v0.17.1`.
77
8+
/// Requires `Client` to be in scope and to implement `get_network_info`.
9+
#[macro_export]
10+
macro_rules! impl_test_v17__getnettotals {
11+
() => {
12+
#[test]
13+
fn get_net_totals() {
14+
let bitcoind = $crate::bitcoind_no_wallet();
15+
let _ = bitcoind.client.get_net_totals().expect("getnettotals");
16+
}
17+
};
18+
}
19+
820
/// Requires `Client` to be in scope and to implement `get_network_info`.
921
#[macro_export]
1022
macro_rules! impl_test_v17__getnetworkinfo {
1123
() => {
1224
#[test]
1325
fn get_network_info() {
1426
let bitcoind = $crate::bitcoind_no_wallet();
15-
let json = bitcoind.client.get_network_info().expect("getnetworkinfo");
16-
json.into_model().unwrap();
27+
let _ = bitcoind.client.get_network_info().expect("getnetworkinfo");
1728

1829
bitcoind.client.check_expected_server_version().expect("unexpected version");
1930
}
2031
};
2132
}
33+
34+
/// Requires `Client` to be in scope and to implement `get_peer_info`.
35+
#[macro_export]
36+
macro_rules! impl_test_v17__getpeerinfo {
37+
() => {
38+
#[test]
39+
fn get_peer_info() {
40+
let bitcoind = $crate::bitcoind_no_wallet();
41+
let _ = bitcoind.client.get_peer_info().expect("getpeerinfo");
42+
}
43+
};
44+
}

integration_test/tests/v17_api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ mod generating {
4343
mod network {
4444
use super::*;
4545

46+
impl_test_v17__getnettotals!();
4647
impl_test_v17__getnetworkinfo!();
48+
impl_test_v17__getpeerinfo!();
4749
}
4850

4951
// == Rawtransactions ==

json/src/model/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ mod blockchain;
1212
mod control;
1313
mod generating;
1414
mod mining;
15-
mod network;
1615
mod raw_transactions;
1716
mod util;
1817
mod wallet;
@@ -33,7 +32,6 @@ pub use self::{
3332
GetMempoolAncestorsVerbose, GetTxOut, Softfork, SoftforkType,
3433
},
3534
generating::{Generate, GenerateToAddress},
36-
network::{GetNetworkInfo, GetNetworkInfoAddress, GetNetworkInfoNetwork},
3735
raw_transactions::SendRawTransaction,
3836
wallet::{
3937
CreateWallet, GetBalance, GetBalances, GetBalancesMine, GetBalancesWatchOnly,

json/src/model/network.rs

Lines changed: 0 additions & 68 deletions
This file was deleted.

json/src/v17/mod.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@
5757
//! - [ ] `submitblock "hexdata" ( "dummy" )`
5858
//!
5959
//! **== Network ==**
60-
//! - [ ] `addnode "node" "add|remove|onetry"`
61-
//! - [ ] `clearbanned`
62-
//! - [ ] `disconnectnode "[address]" [nodeid]`
60+
//! - [-] `addnode "node" "add|remove|onetry"`
61+
//! - [-] `clearbanned`
62+
//! - [-] `disconnectnode "[address]" [nodeid]`
6363
//! - [ ] `getaddednodeinfo ( "node" )`
64-
//! - [ ] `getconnectioncount`
65-
//! - [ ] `getnettotals`
64+
//! - [-] `getconnectioncount`
65+
//! - [x] `getnettotals`
6666
//! - [x] `getnetworkinfo`
67-
//! - [ ] `getpeerinfo`
68-
//! - [ ] `listbanned`
69-
//! - [ ] `ping`
70-
//! - [ ] `setban "subnet" "add|remove" (bantime) (absolute)`
71-
//! - [ ] `setnetworkactive true|false`
67+
//! - [x] `getpeerinfo`
68+
//! - [-] `listbanned`
69+
//! - [-] `ping`
70+
//! - [-] `setban "subnet" "add|remove" (bantime) (absolute)`
71+
//! - [-] `setnetworkactive true|false`
7272
//!
7373
//! **== Rawtransactions ==**
7474
//! - [ ] `combinepsbt ["psbt",...]`
@@ -179,7 +179,10 @@ pub use self::{
179179
},
180180
control::{GetMemoryInfoStats, Locked, Logging, Uptime},
181181
generating::{Generate, GenerateToAddress},
182-
network::{GetNetworkInfo, GetNetworkInfoAddress, GetNetworkInfoNetwork},
182+
network::{
183+
AddedNodeAddress, BytesPerMessage, GetAddedNodeInfo, GetNetTotals, GetNetworkInfo,
184+
GetNetworkInfoAddress, GetNetworkInfoNetwork, GetPeerInfo, PeerInfo, UploadTarget,
185+
},
183186
raw_transactions::SendRawTransaction,
184187
wallet::{
185188
CreateWallet, GetBalance, GetNewAddress, GetTransaction, GetTransactionDetail,

0 commit comments

Comments
 (0)