@@ -38,6 +38,7 @@ use crate::io;
3838use crate :: io_extras:: { copy, sink} ;
3939use crate :: prelude:: * ;
4040use core:: { cmp, fmt} ;
41+ use core:: convert:: TryFrom ;
4142use crate :: sync:: { RwLock , RwLockReadGuard } ;
4243#[ cfg( feature = "std" ) ]
4344use core:: sync:: atomic:: { AtomicUsize , Ordering } ;
@@ -76,6 +77,11 @@ impl NodeId {
7677 pub fn as_slice ( & self ) -> & [ u8 ] {
7778 & self . 0
7879 }
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+ }
7985}
8086
8187impl fmt:: Debug for NodeId {
@@ -130,6 +136,20 @@ impl Readable for NodeId {
130136 }
131137}
132138
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+
133153/// Represents the network as nodes and channels between them
134154pub struct NetworkGraph < L : Deref > where L :: Target : Logger {
135155 secp_ctx : Secp256k1 < secp256k1:: VerifyOnly > ,
0 commit comments