File tree 1 file changed +15
-3
lines changed
1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -38,11 +38,13 @@ 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 } ;
44
45
use crate :: sync:: Mutex ;
45
46
use core:: ops:: { Bound , Deref } ;
47
+ use core:: str:: FromStr ;
46
48
47
49
#[ cfg( feature = "std" ) ]
48
50
use std:: time:: { SystemTime , UNIX_EPOCH } ;
@@ -136,9 +138,19 @@ impl From<PublicKey> for NodeId {
136
138
}
137
139
}
138
140
139
- impl From < NodeId > for PublicKey {
140
- fn from ( node_id : NodeId ) -> PublicKey {
141
- PublicKey :: from_slice ( & node_id. 0 ) . unwrap ( )
141
+ impl TryFrom < NodeId > for PublicKey {
142
+ type Error = secp256k1:: Error ;
143
+
144
+ fn try_from ( node_id : NodeId ) -> Result < Self , Self :: Error > {
145
+ PublicKey :: from_slice ( & node_id. 0 )
146
+ }
147
+ }
148
+
149
+ impl FromStr for NodeId {
150
+ type Err = secp256k1:: Error ;
151
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
152
+ let pubkey = PublicKey :: from_str ( s) ?;
153
+ Ok ( NodeId :: from_pubkey ( & pubkey) )
142
154
}
143
155
}
144
156
You can’t perform that action at this time.
0 commit comments