mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 23:08:36 +01:00
Implement to and from for PublicKey and NodeId
This commit is contained in:
parent
157af6ec1c
commit
5ed6732b87
1 changed files with 20 additions and 0 deletions
|
@ -38,6 +38,7 @@ use crate::io;
|
||||||
use crate::io_extras::{copy, sink};
|
use crate::io_extras::{copy, sink};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use core::{cmp, fmt};
|
use core::{cmp, fmt};
|
||||||
|
use core::convert::TryFrom;
|
||||||
use crate::sync::{RwLock, RwLockReadGuard};
|
use crate::sync::{RwLock, RwLockReadGuard};
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use core::sync::atomic::{AtomicUsize, Ordering};
|
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
@ -76,6 +77,11 @@ impl NodeId {
|
||||||
pub fn as_slice(&self) -> &[u8] {
|
pub fn as_slice(&self) -> &[u8] {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the public key from this NodeId
|
||||||
|
pub fn as_pubkey(&self) -> Result<PublicKey, secp256k1::Error> {
|
||||||
|
PublicKey::from_slice(&self.0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for NodeId {
|
impl fmt::Debug for NodeId {
|
||||||
|
@ -130,6 +136,20 @@ impl Readable for NodeId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<PublicKey> for NodeId {
|
||||||
|
fn from(pubkey: PublicKey) -> Self {
|
||||||
|
Self::from_pubkey(&pubkey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<NodeId> for PublicKey {
|
||||||
|
type Error = secp256k1::Error;
|
||||||
|
|
||||||
|
fn try_from(node_id: NodeId) -> Result<Self, Self::Error> {
|
||||||
|
node_id.as_pubkey()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents the network as nodes and channels between them
|
/// Represents the network as nodes and channels between them
|
||||||
pub struct NetworkGraph<L: Deref> where L::Target: Logger {
|
pub struct NetworkGraph<L: Deref> where L::Target: Logger {
|
||||||
secp_ctx: Secp256k1<secp256k1::VerifyOnly>,
|
secp_ctx: Secp256k1<secp256k1::VerifyOnly>,
|
||||||
|
|
Loading…
Add table
Reference in a new issue