projects
/
rust-lightning
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
36e434d
)
Add NodeId::from_slice
author
benthecarman
<benthecarman@live.com>
Sun, 17 Mar 2024 15:26:27 +0000
(15:26 +0000)
committer
benthecarman
<benthecarman@live.com>
Sun, 17 Mar 2024 15:26:27 +0000
(15:26 +0000)
lightning/src/routing/gossip.rs
patch
|
blob
|
history
diff --git
a/lightning/src/routing/gossip.rs
b/lightning/src/routing/gossip.rs
index 2fbbcb147d075aa64cf4d5b2fc5ca64aae009c1f..281586edd36591f3bda4227fd70972d87c99a531 100644
(file)
--- 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<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