]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Expose ReadOnlyNetworkGraph::get_addresses to C by cloning result 2021-10-expose-addr-vec
authorMatt Corallo <git@bluematt.me>
Mon, 11 Oct 2021 23:46:51 +0000 (23:46 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 13 Oct 2021 01:18:43 +0000 (01:18 +0000)
We cannot expose ReadOnlyNetworkGraph::get_addresses as is in C as
it returns a list of references to an enum, which the bindings
dont support. Instead, we simply clone the result so that it
doesn't contain references.

lightning/src/routing/network_graph.rs

index 2a8c45c3bb47618cd3cec78c4be2d5e00a13b08c..acf51e535d2f682463a15b5119385d05e987377f 100644 (file)
@@ -1213,12 +1213,10 @@ impl ReadOnlyNetworkGraph<'_> {
        /// Get network addresses by node id.
        /// Returns None if the requested node is completely unknown,
        /// or if node announcement for the node was never received.
-       ///
-       /// (C-not exported) as there is no practical way to track lifetimes of returned values.
-       pub fn get_addresses(&self, pubkey: &PublicKey) -> Option<&Vec<NetAddress>> {
+       pub fn get_addresses(&self, pubkey: &PublicKey) -> Option<Vec<NetAddress>> {
                if let Some(node) = self.nodes.get(&NodeId::from_pubkey(&pubkey)) {
                        if let Some(node_info) = node.announcement_info.as_ref() {
-                               return Some(&node_info.addresses)
+                               return Some(node_info.addresses.clone())
                        }
                }
                None