Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions integration_test/tests/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ fn network__get_network_info__modelled() {
fn network__get_node_addresses() {
let node = Node::with_wallet(Wallet::None, &[]);
let json: GetNodeAddresses = node.client.get_node_addresses().expect("getnodeaddresses");
assert!(json.0.len() <= 2500);
if let Some(addr) = json.0.first() {
let res: Result<mtype::GetNodeAddresses, _> = json.into_model();
let model = res.expect("GetNodeAddresses into model");
assert!(model.0.len() <= 2500);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing the list is empty 😂. It was an AI suggested sanity check that the list was smaller than the max allowed size.

if let Some(addr) = model.0.first() {
assert!(addr.port > 0);
assert!(!addr.address.is_empty());
assert!(addr.time > 1231006505);
}
Comment on lines +43 to 46
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code block will never be run because there is only one node started. We'd need to start a multi-node network to test this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #320 to follow this up. Adding a multi-node network did not work for me either.

}
Expand Down
4 changes: 3 additions & 1 deletion types/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ pub use self::{
BlockTemplateTransaction, GetBlockTemplate, GetPrioritisedTransactions,
PrioritisedTransaction,
},
network::{GetNetworkInfo, GetNetworkInfoAddress, GetNetworkInfoNetwork},
network::{
GetNetworkInfo, GetNetworkInfoAddress, GetNetworkInfoNetwork, GetNodeAddresses, NodeAddress,
},
raw_transactions::{
AnalyzePsbt, AnalyzePsbtInput, AnalyzePsbtInputMissing, CombinePsbt, CombineRawTransaction,
ConvertToPsbt, CreatePsbt, CreateRawTransaction, DecodePsbt, DecodeRawTransaction,
Expand Down
24 changes: 23 additions & 1 deletion types/src/model/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
//! These structs model the types returned by the JSON-RPC API but have concrete types
//! and are not specific to a specific version of Bitcoin Core.

use bitcoin::FeeRate;
use bitcoin::address::NetworkUnchecked;
use bitcoin::{Address, FeeRate};
use serde::{Deserialize, Serialize};

/// Models the result of JSON-RPC method `getnetworkinfo`.
Expand Down Expand Up @@ -64,3 +65,24 @@ pub struct GetNetworkInfoAddress {
/// Relative score.
pub score: u32,
}

/// Result of JSON-RPC method `getnodeaddresses`.
///
/// > getnodeaddresses ( count )
/// >
/// > Return known addresses which can potentially be used to find new nodes in the network.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct GetNodeAddresses(pub Vec<NodeAddress>);

/// An item from the list returned by the JSON-RPC method `getnodeaddresses`.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct NodeAddress {
/// Timestamp in seconds since epoch (Jan 1 1970 GMT) when the node was last seen.
pub time: u64,
/// The services offered.
pub services: u64,
/// The address of the node.
pub address: Address<NetworkUnchecked>,
/// The port of the node.
pub port: u16,
}
2 changes: 1 addition & 1 deletion types/src/v18/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
//! | getconnectioncount | returns numeric | |
//! | getnettotals | version | |
//! | getnetworkinfo | version + model | |
//! | getnodeaddresses | version | |
//! | getnodeaddresses | version + model | |
//! | getpeerinfo | version | |
//! | listbanned | returns string | |
//! | ping | returns nothing | |
Expand Down
28 changes: 28 additions & 0 deletions types/src/v18/network/into.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: CC0-1.0

use bitcoin::address::NetworkUnchecked;
use bitcoin::{address, Address};

use super::{GetNodeAddresses, NodeAddress};
use crate::model;

impl GetNodeAddresses {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::GetNodeAddresses, address::ParseError> {
let nodes = self.0.into_iter().map(|n| n.into_model()).collect::<Result<_, _>>()?;
Ok(model::GetNodeAddresses(nodes))
}
}

impl NodeAddress {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::NodeAddress, address::ParseError> {
let address = self.address.parse::<Address<NetworkUnchecked>>()?;
Ok(model::NodeAddress {
time: self.time,
services: self.services,
address,
port: self.port,
})
}
}
2 changes: 2 additions & 0 deletions types/src/v18/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//!
//! Types for methods found under the `== Network ==` section of the API docs.

mod into;

use serde::{Deserialize, Serialize};

/// Result of JSON-RPC method `getnodeaddresses`.
Expand Down
2 changes: 1 addition & 1 deletion types/src/v19/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
//! | getconnectioncount | returns numeric | |
//! | getnettotals | version | |
//! | getnetworkinfo | version + model | |
//! | getnodeaddresses | version | |
//! | getnodeaddresses | version + model | |
//! | getpeerinfo | version | |
//! | listbanned | returns string | |
//! | ping | returns nothing | |
Expand Down
2 changes: 1 addition & 1 deletion types/src/v20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
//! | getconnectioncount | returns numeric | |
//! | getnettotals | version | |
//! | getnetworkinfo | version + model | |
//! | getnodeaddresses | version | |
//! | getnodeaddresses | version + model | |
//! | getpeerinfo | version | |
//! | listbanned | returns string | |
//! | ping | returns nothing | |
Expand Down
2 changes: 1 addition & 1 deletion types/src/v21/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
//! | getconnectioncount | returns numeric | |
//! | getnettotals | version | |
//! | getnetworkinfo | version + model | |
//! | getnodeaddresses | version | |
//! | getnodeaddresses | version + model | |
//! | getpeerinfo | version | |
//! | listbanned | returns string | |
//! | ping | returns nothing | |
Expand Down
2 changes: 1 addition & 1 deletion types/src/v22/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
//! | getconnectioncount | returns numeric | |
//! | getnettotals | version | |
//! | getnetworkinfo | version + model | |
//! | getnodeaddresses | version | |
//! | getnodeaddresses | version + model | TODO |
//! | getpeerinfo | version | |
//! | listbanned | returns string | |
//! | ping | returns nothing | |
Expand Down
2 changes: 1 addition & 1 deletion types/src/v23/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
//! | getconnectioncount | returns numeric | |
//! | getnettotals | version | |
//! | getnetworkinfo | version + model | |
//! | getnodeaddresses | version | |
//! | getnodeaddresses | version + model | TODO |
//! | getpeerinfo | version | |
//! | listbanned | returns string | |
//! | ping | returns nothing | |
Expand Down
2 changes: 1 addition & 1 deletion types/src/v24/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
//! | getconnectioncount | returns numeric | |
//! | getnettotals | version | |
//! | getnetworkinfo | version + model | |
//! | getnodeaddresses | version | |
//! | getnodeaddresses | version + model | TODO ||
//! | getpeerinfo | version | |
//! | listbanned | returns string | |
//! | ping | returns nothing | |
Expand Down
2 changes: 1 addition & 1 deletion types/src/v25/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
//! | getconnectioncount | returns numeric | |
//! | getnettotals | version | |
//! | getnetworkinfo | version + model | |
//! | getnodeaddresses | version | |
//! | getnodeaddresses | version + model | TODO |
//! | getpeerinfo | version | |
//! | listbanned | returns string | |
//! | ping | returns nothing | |
Expand Down
2 changes: 1 addition & 1 deletion types/src/v26/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
//! | getconnectioncount | returns numeric | |
//! | getnettotals | version | |
//! | getnetworkinfo | version + model | |
//! | getnodeaddresses | version | |
//! | getnodeaddresses | version + model | TODO |
//! | getpeerinfo | version | |
//! | listbanned | returns string | |
//! | ping | returns nothing | |
Expand Down
2 changes: 1 addition & 1 deletion types/src/v27/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
//! | getconnectioncount | returns numeric | |
//! | getnettotals | version | |
//! | getnetworkinfo | version + model | |
//! | getnodeaddresses | version | |
//! | getnodeaddresses | version + model | TODO |
//! | getpeerinfo | version | |
//! | listbanned | returns string | |
//! | ping | returns nothing | |
Expand Down
2 changes: 1 addition & 1 deletion types/src/v28/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
//! | getconnectioncount | returns numeric | |
//! | getnettotals | version | |
//! | getnetworkinfo | version + model | |
//! | getnodeaddresses | version | |
//! | getnodeaddresses | version + model | TODO |
//! | getpeerinfo | version | |
//! | listbanned | returns string | |
//! | ping | returns nothing | |
Expand Down
2 changes: 1 addition & 1 deletion verify/src/method/v18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub const METHODS: &[Method] = &[
Method::new_numeric("getconnectioncount", "get_connection_count"),
Method::new_no_model("getnettotals", "GetNetTotals", "get_net_totals"),
Method::new_modelled("getnetworkinfo", "GetNetworkInfo", "get_network_info"),
Method::new_no_model("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_modelled("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_no_model("getpeerinfo", "GetPeerInfo", "get_peer_info"),
Method::new_string("listbanned", "list_banned"), // v17 docs seem wrong, says no return.
Method::new_nothing("ping", "ping"),
Expand Down
2 changes: 1 addition & 1 deletion verify/src/method/v19.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub const METHODS: &[Method] = &[
Method::new_numeric("getconnectioncount", "get_connection_count"),
Method::new_no_model("getnettotals", "GetNetTotals", "get_net_totals"),
Method::new_modelled("getnetworkinfo", "GetNetworkInfo", "get_network_info"),
Method::new_no_model("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_modelled("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_no_model("getpeerinfo", "GetPeerInfo", "get_peer_info"),
Method::new_string("listbanned", "list_banned"), // v17 docs seem wrong, says no return.
Method::new_nothing("ping", "ping"),
Expand Down
2 changes: 1 addition & 1 deletion verify/src/method/v20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub const METHODS: &[Method] = &[
Method::new_numeric("getconnectioncount", "get_connection_count"),
Method::new_no_model("getnettotals", "GetNetTotals", "get_net_totals"),
Method::new_modelled("getnetworkinfo", "GetNetworkInfo", "get_network_info"),
Method::new_no_model("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_modelled("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_no_model("getpeerinfo", "GetPeerInfo", "get_peer_info"),
Method::new_string("listbanned", "list_banned"), // v17 docs seem wrong, says no return.
Method::new_nothing("ping", "ping"),
Expand Down
2 changes: 1 addition & 1 deletion verify/src/method/v21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub const METHODS: &[Method] = &[
Method::new_numeric("getconnectioncount", "get_connection_count"),
Method::new_no_model("getnettotals", "GetNetTotals", "get_net_totals"),
Method::new_modelled("getnetworkinfo", "GetNetworkInfo", "get_network_info"),
Method::new_no_model("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_modelled("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_no_model("getpeerinfo", "GetPeerInfo", "get_peer_info"),
Method::new_string("listbanned", "list_banned"), // v17 docs seem wrong, says no return.
Method::new_nothing("ping", "ping"),
Expand Down
2 changes: 1 addition & 1 deletion verify/src/method/v22.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub const METHODS: &[Method] = &[
Method::new_numeric("getconnectioncount", "get_connection_count"),
Method::new_no_model("getnettotals", "GetNetTotals", "get_net_totals"),
Method::new_modelled("getnetworkinfo", "GetNetworkInfo", "get_network_info"),
Method::new_no_model("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_modelled("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_no_model("getpeerinfo", "GetPeerInfo", "get_peer_info"),
Method::new_string("listbanned", "list_banned"), // v17 docs seem wrong, says no return.
Method::new_nothing("ping", "ping"),
Expand Down
2 changes: 1 addition & 1 deletion verify/src/method/v23.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub const METHODS: &[Method] = &[
Method::new_numeric("getconnectioncount", "get_connection_count"),
Method::new_no_model("getnettotals", "GetNetTotals", "get_net_totals"),
Method::new_modelled("getnetworkinfo", "GetNetworkInfo", "get_network_info"),
Method::new_no_model("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_modelled("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_no_model("getpeerinfo", "GetPeerInfo", "get_peer_info"),
Method::new_string("listbanned", "list_banned"), // v17 docs seem wrong, says no return.
Method::new_nothing("ping", "ping"),
Expand Down
2 changes: 1 addition & 1 deletion verify/src/method/v24.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub const METHODS: &[Method] = &[
Method::new_numeric("getconnectioncount", "get_connection_count"),
Method::new_no_model("getnettotals", "GetNetTotals", "get_net_totals"),
Method::new_modelled("getnetworkinfo", "GetNetworkInfo", "get_network_info"),
Method::new_no_model("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_modelled("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_no_model("getpeerinfo", "GetPeerInfo", "get_peer_info"),
Method::new_string("listbanned", "list_banned"), // v17 docs seem wrong, says no return.
Method::new_nothing("ping", "ping"),
Expand Down
2 changes: 1 addition & 1 deletion verify/src/method/v25.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub const METHODS: &[Method] = &[
Method::new_numeric("getconnectioncount", "get_connection_count"),
Method::new_no_model("getnettotals", "GetNetTotals", "get_net_totals"),
Method::new_modelled("getnetworkinfo", "GetNetworkInfo", "get_network_info"),
Method::new_no_model("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_modelled("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_no_model("getpeerinfo", "GetPeerInfo", "get_peer_info"),
Method::new_string("listbanned", "list_banned"), // v17 docs seem wrong, says no return.
Method::new_nothing("ping", "ping"),
Expand Down
2 changes: 1 addition & 1 deletion verify/src/method/v26.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub const METHODS: &[Method] = &[
Method::new_numeric("getconnectioncount", "get_connection_count"),
Method::new_no_model("getnettotals", "GetNetTotals", "get_net_totals"),
Method::new_modelled("getnetworkinfo", "GetNetworkInfo", "get_network_info"),
Method::new_no_model("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_modelled("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_no_model("getpeerinfo", "GetPeerInfo", "get_peer_info"),
Method::new_string("listbanned", "list_banned"), // v17 docs seem wrong, says no return.
Method::new_nothing("ping", "ping"),
Expand Down
2 changes: 1 addition & 1 deletion verify/src/method/v27.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub const METHODS: &[Method] = &[
Method::new_numeric("getconnectioncount", "get_connection_count"),
Method::new_no_model("getnettotals", "GetNetTotals", "get_net_totals"),
Method::new_modelled("getnetworkinfo", "GetNetworkInfo", "get_network_info"),
Method::new_no_model("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_modelled("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_no_model("getpeerinfo", "GetPeerInfo", "get_peer_info"),
Method::new_string("listbanned", "list_banned"), // v17 docs seem wrong, says no return.
Method::new_nothing("ping", "ping"),
Expand Down
2 changes: 1 addition & 1 deletion verify/src/method/v28.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub const METHODS: &[Method] = &[
Method::new_numeric("getconnectioncount", "get_connection_count"),
Method::new_no_model("getnettotals", "GetNetTotals", "get_net_totals"),
Method::new_modelled("getnetworkinfo", "GetNetworkInfo", "get_network_info"),
Method::new_no_model("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_modelled("getnodeaddresses", "GetNodeAddresses", "get_node_addresses"),
Method::new_no_model("getpeerinfo", "GetPeerInfo", "get_peer_info"),
Method::new_string("listbanned", "list_banned"), // v17 docs seem wrong, says no return.
Method::new_nothing("ping", "ping"),
Expand Down