From 7a37e2cd23ee1d563ad2b21f115d713b15d9e8a0 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Thu, 13 Apr 2023 12:54:04 -0500 Subject: [PATCH] Impl FromStr for NodeId --- lightning/src/routing/gossip.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) 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, -- 2.39.5