]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add NodeId::from_slice
authorbenthecarman <benthecarman@live.com>
Sun, 17 Mar 2024 15:26:27 +0000 (15:26 +0000)
committerbenthecarman <benthecarman@live.com>
Sun, 17 Mar 2024 15:26:27 +0000 (15:26 +0000)
lightning/src/routing/gossip.rs

index 2fbbcb147d075aa64cf4d5b2fc5ca64aae009c1f..281586edd36591f3bda4227fd70972d87c99a531 100644 (file)
@@ -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<Self, DecodeError> {
+               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