File tree 1 file changed +19
-0
lines changed
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -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,10 @@ impl NodeId {
76
77
pub fn as_slice ( & self ) -> & [ u8 ] {
77
78
& self . 0
78
79
}
80
+
81
+ pub fn as_pubkey ( & self ) -> Result < PublicKey , secp256k1:: Error > {
82
+ PublicKey :: from_slice ( & self . 0 )
83
+ }
79
84
}
80
85
81
86
impl fmt:: Debug for NodeId {
@@ -130,6 +135,20 @@ impl Readable for NodeId {
130
135
}
131
136
}
132
137
138
+ impl From < PublicKey > for NodeId {
139
+ fn from ( pubkey : PublicKey ) -> Self {
140
+ Self :: from_pubkey ( & pubkey)
141
+ }
142
+ }
143
+
144
+ impl TryFrom < NodeId > for PublicKey {
145
+ type Error = secp256k1:: Error ;
146
+
147
+ fn try_from ( node_id : NodeId ) -> Result < Self , Self :: Error > {
148
+ node_id. as_pubkey ( )
149
+ }
150
+ }
151
+
133
152
/// Represents the network as nodes and channels between them
134
153
pub struct NetworkGraph < L : Deref > where L :: Target : Logger {
135
154
secp_ctx : Secp256k1 < secp256k1:: VerifyOnly > ,
You can’t perform that action at this time.
0 commit comments