Skip to content

Commit

Permalink
f docs
Browse files Browse the repository at this point in the history
  • Loading branch information
devrandom committed Apr 24, 2024
1 parent 9392b72 commit 02a856c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions lightning/src/sign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ impl HTLCDescriptor {
/// A trait to handle Lightning channel key material without concretizing the channel type or
/// the signature mechanism.
pub trait ChannelSigner {
/// Returns the commitment seed for the channel.
fn commitment_seed(&self) -> [u8; 32];
/// Returns the counterparty's pubkeys.
///
Expand Down
19 changes: 16 additions & 3 deletions lightning/src/util/dyn_signer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::any::Any;
use std::io::Read;
//! A dynamically dispatched signer

use core::any::Any;
use crate::io::Read;

use delegate::delegate;

Expand Down Expand Up @@ -35,17 +37,22 @@ use crate::util::test_utils::OnlyReadsKeysInterface;

/// Helper to allow DynSigner to clone itself
pub trait InnerSign: EcdsaChannelSigner + Send + Sync {
/// Clone into a Box
fn box_clone(&self) -> Box<dyn InnerSign>;
/// Cast to Any for runtime type checking
fn as_any(&self) -> &dyn Any;
/// Serialize the signer
fn vwrite(&self, writer: &mut Vec<u8>) -> Result<(), std::io::Error>;
}

/// A ChannelSigner derived struct allowing run-time selection of a signer
pub struct DynSigner {
/// The inner signer
pub inner: Box<dyn InnerSign>,
}

impl DynSigner {
/// Create a new DynSigner
pub fn new<S: InnerSign + 'static>(inner: S) -> Self {
DynSigner { inner: Box::new(inner) }
}
Expand Down Expand Up @@ -189,11 +196,14 @@ impl InnerSign for InMemorySigner {
}
}

/// A convenience wrapper for DynKeysInterfaceTrait
pub struct DynKeysInterface {
/// The inner dyn keys interface
pub inner: Box<dyn DynKeysInterfaceTrait<EcdsaSigner = DynSigner>>,
}

impl DynKeysInterface {
/// Create a new DynKeysInterface
pub fn new(inner: Box<dyn DynKeysInterfaceTrait<EcdsaSigner = DynSigner>>) -> Self {
DynKeysInterface { inner }
}
Expand Down Expand Up @@ -264,15 +274,17 @@ impl OutputSpender for DynKeysInterface {
}
}

// A supertrait for all the traits that a keys interface implements
/// A supertrait for all the traits that a keys interface implements
pub trait DynKeysInterfaceTrait: NodeSigner + OutputSpender + SignerProvider<EcdsaSigner=DynSigner> + EntropySource + Send + Sync {
}

/// A dyn wrapper for PhantomKeysManager
pub struct DynPhantomKeysInterface {
inner: PhantomKeysManager,
}

impl DynPhantomKeysInterface {
/// Create a new DynPhantomKeysInterface
pub fn new(inner: PhantomKeysManager) -> Self {
DynPhantomKeysInterface { inner }
}
Expand Down Expand Up @@ -350,6 +362,7 @@ impl OutputSpender for DynPhantomKeysInterface {

impl DynKeysInterfaceTrait for DynPhantomKeysInterface {}

#[cfg(feature = "std")]
impl ReadableArgs<&DynKeysInterface> for DynSigner {
fn read<R: Read>(_reader: &mut R, _params: &DynKeysInterface) -> Result<Self, DecodeError> {
todo!()
Expand Down

0 comments on commit 02a856c

Please sign in to comment.