mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 23:08:36 +01:00
Merge pull request #2942 from benthecarman/node-id-slice
Add NodeId::from_slice
This commit is contained in:
commit
282b52f7bd
1 changed files with 10 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue