Skip to content

Commit 9330b07

Browse files
committed
Impl FromStr for NodeId
1 parent e1b50cf commit 9330b07

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lightning/src/routing/gossip.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use crate::sync::{RwLock, RwLockReadGuard};
4343
use core::sync::atomic::{AtomicUsize, Ordering};
4444
use crate::sync::Mutex;
4545
use core::ops::{Bound, Deref};
46+
use core::str::FromStr;
4647

4748
#[cfg(feature = "std")]
4849
use std::time::{SystemTime, UNIX_EPOCH};
@@ -142,6 +143,14 @@ impl From<NodeId> for PublicKey {
142143
}
143144
}
144145

146+
impl FromStr for NodeId {
147+
type Err = secp256k1::Error;
148+
fn from_str(s: &str) -> Result<Self, Self::Err> {
149+
let pubkey = PublicKey::from_str(s)?;
150+
Ok(NodeId::from_pubkey(&pubkey))
151+
}
152+
}
153+
145154
/// Represents the network as nodes and channels between them
146155
pub struct NetworkGraph<L: Deref> where L::Target: Logger {
147156
secp_ctx: Secp256k1<secp256k1::VerifyOnly>,

0 commit comments

Comments
 (0)