Skip to content

Commit 37b0821

Browse files
committed
Add getaddrmaninfo struct and test
Add the `getaddrmaninfo` struct, macro and test. Update the reexports. There is no required model. Update the types table to `version` only.
1 parent 9ee00e0 commit 37b0821

File tree

15 files changed

+73
-9
lines changed

15 files changed

+73
-9
lines changed

client/src/client_sync/v26/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
pub mod blockchain;
88
pub mod mining;
9+
pub mod network;
910
pub mod raw_transactions;
1011

1112
use std::collections::BTreeMap;
@@ -92,6 +93,7 @@ crate::impl_client_v17__add_node!();
9293
crate::impl_client_v17__clear_banned!();
9394
crate::impl_client_v17__disconnect_node!();
9495
crate::impl_client_v17__get_added_node_info!();
96+
crate::impl_client_v26__get_addr_man_info!();
9597
crate::impl_client_v17__get_connection_count!();
9698
crate::impl_client_v17__get_net_totals!();
9799
crate::impl_client_v17__get_network_info!();
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 `v26`.
9+
//!
10+
//! See, or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
11+
12+
/// Implements Bitcoin Core JSON-RPC API method `getaddrmaninfo`.
13+
#[macro_export]
14+
macro_rules! impl_client_v26__get_addr_man_info {
15+
() => {
16+
impl Client {
17+
pub fn get_addr_man_info(&self) -> Result<GetAddrManInfo> {
18+
self.call("getaddrmaninfo", &[])
19+
}
20+
}
21+
};
22+
}

client/src/client_sync/v27/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ crate::impl_client_v17__add_node!();
8787
crate::impl_client_v17__clear_banned!();
8888
crate::impl_client_v17__disconnect_node!();
8989
crate::impl_client_v17__get_added_node_info!();
90+
crate::impl_client_v26__get_addr_man_info!();
9091
crate::impl_client_v17__get_connection_count!();
9192
crate::impl_client_v17__get_net_totals!();
9293
crate::impl_client_v17__get_network_info!();

client/src/client_sync/v28/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ crate::impl_client_v17__add_node!();
8989
crate::impl_client_v17__clear_banned!();
9090
crate::impl_client_v17__disconnect_node!();
9191
crate::impl_client_v17__get_added_node_info!();
92+
crate::impl_client_v26__get_addr_man_info!();
9293
crate::impl_client_v17__get_connection_count!();
9394
crate::impl_client_v17__get_net_totals!();
9495
crate::impl_client_v17__get_network_info!();

client/src/client_sync/v29/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ crate::impl_client_v17__add_node!();
8989
crate::impl_client_v17__clear_banned!();
9090
crate::impl_client_v17__disconnect_node!();
9191
crate::impl_client_v17__get_added_node_info!();
92+
crate::impl_client_v26__get_addr_man_info!();
9293
crate::impl_client_v17__get_connection_count!();
9394
crate::impl_client_v17__get_net_totals!();
9495
crate::impl_client_v17__get_network_info!();

integration_test/tests/network.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ fn network__get_added_node_info() {
4949
let _: GetAddedNodeInfo = node.client.get_added_node_info().expect("getaddednodeinfo");
5050
}
5151

52+
#[test]
53+
#[cfg(not(feature = "v25_and_below"))]
54+
fn network__get_addr_man_info() {
55+
let node = Node::with_wallet(Wallet::None, &[]);
56+
let json: GetAddrManInfo = node.client.get_addr_man_info().expect("getaddrmaninfo");
57+
assert!(!json.0.is_empty());
58+
59+
for (network_name, network_info) in &json.0 {
60+
assert!(!network_name.is_empty());
61+
assert_eq!(network_info.total, network_info.new + network_info.tried);
62+
};
63+
}
64+
5265
#[test]
5366
fn network__get_connection_count() {
5467
let node = Node::with_wallet(Wallet::None, &[]);

types/src/v26/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
//! | clearbanned | returns nothing | |
101101
//! | disconnectnode | returns nothing | |
102102
//! | getaddednodeinfo | version | |
103-
//! | getaddrmaninfo | version + model | TODO |
103+
//! | getaddrmaninfo | version | |
104104
//! | getconnectioncount | version | |
105105
//! | getnettotals | version | |
106106
//! | getnetworkinfo | version + model | |
@@ -260,7 +260,7 @@ pub use self::{
260260
blockchain::{DumpTxOutSet, DumpTxOutSetError, GetTxOutSetInfo, GetTxOutSetInfoError, LoadTxOutSet, LoadTxOutSetError, GetChainStates, GetChainStatesError, ChainState},
261261
control::Logging,
262262
mining::{GetPrioritisedTransactions, PrioritisedTransaction},
263-
network::{GetPeerInfo, PeerInfo},
263+
network::{AddrManInfoNetwork, GetAddrManInfo, GetPeerInfo, PeerInfo},
264264
raw_transactions::{
265265
DescriptorProcessPsbt, DescriptorProcessPsbtError, SubmitPackage, SubmitPackageError,
266266
SubmitPackageTxResult, SubmitPackageTxResultError, SubmitPackageTxResultFees,

types/src/v26/network.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@ use alloc::collections::BTreeMap;
88

99
use serde::{Deserialize, Serialize};
1010

11+
/// Result of JSON-RPC method `getaddrmaninfo`.
12+
///
13+
/// > getaddrmaninfo
14+
/// >
15+
/// > Provides information about the node's address manager by returning the number of addresses in the `new` and `tried` tables and their sum for all networks.
16+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
17+
#[serde(deny_unknown_fields)]
18+
pub struct GetAddrManInfo(pub BTreeMap<String, AddrManInfoNetwork>);
19+
20+
/// Address manager information returned as part of `getaddrmaninfo`.
21+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
22+
#[serde(deny_unknown_fields)]
23+
pub struct AddrManInfoNetwork {
24+
/// Number of addresses in the new table, which represent potential peers the node has discovered but hasn't yet successfully connected to.
25+
pub new: u64,
26+
/// Number of addresses in the tried table, which represent peers the node has successfully connected to in the past.
27+
pub tried: u64,
28+
/// Total number of addresses in both new/tried tables.
29+
pub total: u64,
30+
}
31+
1132
/// Result of JSON-RPC method `getpeerinfo`.
1233
///
1334
/// > getpeerinfo

types/src/v27/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
//! | clearbanned | returns nothing | |
101101
//! | disconnectnode | returns nothing | |
102102
//! | getaddednodeinfo | version | |
103-
//! | getaddrmaninfo | version + model | TODO |
103+
//! | getaddrmaninfo | version | |
104104
//! | getconnectioncount | version | |
105105
//! | getnettotals | version | |
106106
//! | getnetworkinfo | version + model | |
@@ -331,5 +331,6 @@ pub use crate::{
331331
SubmitPackageTxResultFees, SubmitPackageTxResultFeesError, UnloadWallet,
332332
DumpTxOutSet, DumpTxOutSetError, LoadTxOutSet, LoadTxOutSetError,
333333
GetChainStates, GetChainStatesError, ChainState,
334+
AddrManInfoNetwork, GetAddrManInfo,
334335
},
335336
};

types/src/v28/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
//! | clearbanned | returns nothing | |
101101
//! | disconnectnode | returns nothing | |
102102
//! | getaddednodeinfo | version | |
103-
//! | getaddrmaninfo | version + model | TODO |
103+
//! | getaddrmaninfo | version | |
104104
//! | getconnectioncount | version | |
105105
//! | getnettotals | version | |
106106
//! | getnetworkinfo | version + model | |
@@ -343,6 +343,7 @@ pub use crate::{
343343
GetTxOutSetInfo, GetTxOutSetInfoError, LastProcessedBlock, LastProcessedBlockError,
344344
LoadWallet, PeerInfo, UnloadWallet, DumpTxOutSet, DumpTxOutSetError,
345345
LoadTxOutSet, LoadTxOutSetError, GetChainStates, GetChainStatesError, ChainState,
346+
AddrManInfoNetwork, GetAddrManInfo,
346347
},
347348
v27::{GetPrioritisedTransactions, PrioritisedTransaction},
348349
};

0 commit comments

Comments
 (0)