From 227d73de2b5e23ae5ca63fcbfa44b32addf01d46 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Sun, 17 Mar 2024 15:26:27 +0000 Subject: [PATCH] Add NodeId::from_slice --- lightning/src/routing/gossip.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index 2fbbcb147..281586edd 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -74,6 +74,16 @@ impl NodeId { NodeId(pubkey.serialize()) } + /// Create a new NodeId from a slice of bytes + pub fn from_slice(bytes: &[u8]) -> Result { + if bytes.len() != PUBLIC_KEY_SIZE { + return Err(DecodeError::InvalidValue); + } + let mut data = [0; PUBLIC_KEY_SIZE]; + data.copy_from_slice(bytes); + Ok(NodeId(data)) + } + /// Get the public key slice from this NodeId pub fn as_slice(&self) -> &[u8] { &self.0 -- 2.39.5