-
Notifications
You must be signed in to change notification settings - Fork 40
Add model for getnodeaddresses #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
| 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } | ||
|
|
||
| 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, | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do?
There was a problem hiding this comment.
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.