]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Impl FromStr for NodeId
authorbenthecarman <benthecarman@live.com>
Thu, 13 Apr 2023 17:54:04 +0000 (12:54 -0500)
committerbenthecarman <benthecarman@live.com>
Thu, 13 Apr 2023 19:53:23 +0000 (14:53 -0500)
lightning/src/routing/gossip.rs

index 4f5b4f202c1c08dc7f3d1e534e46ce5b1be167d5..866fdc5caa7df9ec647fa11853c5b2a0a6694332 100644 (file)
@@ -16,6 +16,7 @@ use bitcoin::secp256k1;
 
 use bitcoin::hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::hashes::Hash;
+use bitcoin::hashes::hex::FromHex;
 use bitcoin::hash_types::BlockHash;
 
 use bitcoin::network::constants::Network;
@@ -44,6 +45,7 @@ use crate::sync::{RwLock, RwLockReadGuard};
 use core::sync::atomic::{AtomicUsize, Ordering};
 use crate::sync::Mutex;
 use core::ops::{Bound, Deref};
+use core::str::FromStr;
 
 #[cfg(feature = "std")]
 use std::time::{SystemTime, UNIX_EPOCH};
@@ -150,6 +152,15 @@ impl TryFrom<NodeId> for PublicKey {
        }
 }
 
+impl FromStr for NodeId {
+       type Err = bitcoin::hashes::hex::Error;
+
+       fn from_str(s: &str) -> Result<Self, Self::Err> {
+               let data: [u8; PUBLIC_KEY_SIZE] = FromHex::from_hex(s)?;
+               Ok(NodeId(data))
+       }
+}
+
 /// Represents the network as nodes and channels between them
 pub struct NetworkGraph<L: Deref> where L::Target: Logger {
        secp_ctx: Secp256k1<secp256k1::VerifyOnly>,