File tree 1 file changed +13
-1
lines changed
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -38,12 +38,14 @@ 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
+ use core:: convert:: { TryFrom , TryInto } ;
42
42
use crate :: sync:: { RwLock , RwLockReadGuard } ;
43
43
#[ cfg( feature = "std" ) ]
44
44
use core:: sync:: atomic:: { AtomicUsize , Ordering } ;
45
45
use crate :: sync:: Mutex ;
46
46
use core:: ops:: { Bound , Deref } ;
47
+ use core:: str:: FromStr ;
48
+ use hex:: { decode, FromHexError } ;
47
49
48
50
#[ cfg( feature = "std" ) ]
49
51
use std:: time:: { SystemTime , UNIX_EPOCH } ;
@@ -149,6 +151,16 @@ impl TryFrom<NodeId> for PublicKey {
149
151
}
150
152
}
151
153
154
+ impl FromStr for NodeId {
155
+ type Err = FromHexError ;
156
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
157
+ let bytes = decode ( s) ?;
158
+ let data: [ u8 ; PUBLIC_KEY_SIZE ] =
159
+ bytes[ ..] . try_into ( ) . map_err ( |_| FromHexError :: InvalidStringLength ) ?;
160
+ Ok ( NodeId ( data) )
161
+ }
162
+ }
163
+
152
164
/// Represents the network as nodes and channels between them
153
165
pub struct NetworkGraph < L : Deref > where L :: Target : Logger {
154
166
secp_ctx : Secp256k1 < secp256k1:: VerifyOnly > ,
You can’t perform that action at this time.
0 commit comments