Skip to content

Commit 282b52f

Browse files
authored
Merge pull request #2942 from benthecarman/node-id-slice
Add NodeId::from_slice
2 parents 75822b8 + 227d73d commit 282b52f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lightning/src/routing/gossip.rs

+10
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ impl NodeId {
7474
NodeId(pubkey.serialize())
7575
}
7676

77+
/// Create a new NodeId from a slice of bytes
78+
pub fn from_slice(bytes: &[u8]) -> Result<Self, DecodeError> {
79+
if bytes.len() != PUBLIC_KEY_SIZE {
80+
return Err(DecodeError::InvalidValue);
81+
}
82+
let mut data = [0; PUBLIC_KEY_SIZE];
83+
data.copy_from_slice(bytes);
84+
Ok(NodeId(data))
85+
}
86+
7787
/// Get the public key slice from this NodeId
7888
pub fn as_slice(&self) -> &[u8] {
7989
&self.0

0 commit comments

Comments
 (0)