From: benthecarman Date: Thu, 13 Apr 2023 17:54:04 +0000 (-0500) Subject: Impl FromStr for NodeId X-Git-Tag: v0.0.115~23^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=7a37e2cd23ee1d563ad2b21f115d713b15d9e8a0;p=rust-lightning Impl FromStr for NodeId --- diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index 4f5b4f202..866fdc5ca 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -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 for PublicKey { } } +impl FromStr for NodeId { + type Err = bitcoin::hashes::hex::Error; + + fn from_str(s: &str) -> Result { + 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 where L::Target: Logger { secp_ctx: Secp256k1,