@@ -38,6 +38,7 @@ use crate::io;
38
38
use crate :: io_extras:: { copy, sink} ;
39
39
use crate :: prelude:: * ;
40
40
use core:: { cmp, fmt} ;
41
+ use core:: convert:: TryFrom ;
41
42
use crate :: sync:: { RwLock , RwLockReadGuard } ;
42
43
#[ cfg( feature = "std" ) ]
43
44
use core:: sync:: atomic:: { AtomicUsize , Ordering } ;
@@ -76,6 +77,11 @@ impl NodeId {
76
77
pub fn as_slice ( & self ) -> & [ u8 ] {
77
78
& self . 0
78
79
}
80
+
81
+ /// Get the public key from this NodeId
82
+ pub fn as_pubkey ( & self ) -> Result < PublicKey , secp256k1:: Error > {
83
+ PublicKey :: from_slice ( & self . 0 )
84
+ }
79
85
}
80
86
81
87
impl fmt:: Debug for NodeId {
@@ -130,6 +136,20 @@ impl Readable for NodeId {
130
136
}
131
137
}
132
138
139
+ impl From < PublicKey > for NodeId {
140
+ fn from ( pubkey : PublicKey ) -> Self {
141
+ Self :: from_pubkey ( & pubkey)
142
+ }
143
+ }
144
+
145
+ impl TryFrom < NodeId > for PublicKey {
146
+ type Error = secp256k1:: Error ;
147
+
148
+ fn try_from ( node_id : NodeId ) -> Result < Self , Self :: Error > {
149
+ node_id. as_pubkey ( )
150
+ }
151
+ }
152
+
133
153
/// Represents the network as nodes and channels between them
134
154
pub struct NetworkGraph < L : Deref > where L :: Target : Logger {
135
155
secp_ctx : Secp256k1 < secp256k1:: VerifyOnly > ,
0 commit comments