From: benthecarman Date: Sun, 17 Mar 2024 15:26:27 +0000 (+0000) Subject: Add NodeId::from_slice X-Git-Tag: v0.0.123-beta~40^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=227d73de2b5e23ae5ca63fcbfa44b32addf01d46;p=rust-lightning Add NodeId::from_slice --- 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