-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
85 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use crate::sign::{ChannelSigner, EcdsaChannelSigner}; | ||
|
||
pub(crate) enum ChannelSignerType<ECS: ChannelSigner> { | ||
// in practice, this will only ever be an EcdsaChannelSigner | ||
Ecdsa(ECS) | ||
} | ||
|
||
impl<ECS: EcdsaChannelSigner> ChannelSignerType<ECS> { | ||
pub(crate) fn as_ref(&self) -> &dyn ChannelSigner { | ||
match self { | ||
ChannelSignerType::Ecdsa(cs) => cs.as_channel_signer() | ||
} | ||
} | ||
|
||
pub(crate) fn as_mut(&mut self) -> &mut dyn ChannelSigner { | ||
match self { | ||
ChannelSignerType::Ecdsa(cs) => cs.as_mut_channel_signer() | ||
} | ||
} | ||
|
||
pub(crate) fn as_ecdsa(&self) -> &ECS { | ||
match self { | ||
ChannelSignerType::Ecdsa(ecs) => ecs | ||
} | ||
} | ||
|
||
pub(crate) fn as_mut_ecdsa(&mut self) -> &mut ECS { | ||
match self { | ||
ChannelSignerType::Ecdsa(ecs) => ecs | ||
} | ||
} | ||
} | ||
|
||
/// Helper trait for accessing common channel signer methods between different implementations | ||
pub trait AsChannelSigner { | ||
fn as_channel_signer(&self) -> &dyn ChannelSigner; | ||
fn as_mut_channel_signer(&mut self) -> &mut dyn ChannelSigner; | ||
} | ||
|
||
impl<CS: ChannelSigner> AsChannelSigner for CS { | ||
fn as_channel_signer(&self) -> &dyn ChannelSigner { | ||
self | ||
} | ||
|
||
fn as_mut_channel_signer(&mut self) -> &mut dyn ChannelSigner { | ||
self | ||
} | ||
} |