Skip to content

Commit 7a37e2c

Browse files
committed
Impl FromStr for NodeId
1 parent 5ed6732 commit 7a37e2c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lightning/src/routing/gossip.rs

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use bitcoin::secp256k1;
1616

1717
use bitcoin::hashes::sha256d::Hash as Sha256dHash;
1818
use bitcoin::hashes::Hash;
19+
use bitcoin::hashes::hex::FromHex;
1920
use bitcoin::hash_types::BlockHash;
2021

2122
use bitcoin::network::constants::Network;
@@ -44,6 +45,7 @@ use crate::sync::{RwLock, RwLockReadGuard};
4445
use core::sync::atomic::{AtomicUsize, Ordering};
4546
use crate::sync::Mutex;
4647
use core::ops::{Bound, Deref};
48+
use core::str::FromStr;
4749

4850
#[cfg(feature = "std")]
4951
use std::time::{SystemTime, UNIX_EPOCH};
@@ -150,6 +152,15 @@ impl TryFrom<NodeId> for PublicKey {
150152
}
151153
}
152154

155+
impl FromStr for NodeId {
156+
type Err = bitcoin::hashes::hex::Error;
157+
158+
fn from_str(s: &str) -> Result<Self, Self::Err> {
159+
let data: [u8; PUBLIC_KEY_SIZE] = FromHex::from_hex(s)?;
160+
Ok(NodeId(data))
161+
}
162+
}
163+
153164
/// Represents the network as nodes and channels between them
154165
pub struct NetworkGraph<L: Deref> where L::Target: Logger {
155166
secp_ctx: Secp256k1<secp256k1::VerifyOnly>,

0 commit comments

Comments
 (0)