Make ChannelKeys an API and template Channel with it.
[rust-lightning] / lightning / src / util / enforcing_trait_impls.rs
1 use chain::keysinterface::{ChannelKeys, InMemoryChannelKeys};
2
3 use secp256k1::key::SecretKey;
4
5 /// Enforces some rules on ChannelKeys calls. Eventually we will probably want to expose a variant
6 /// of this which would essentially be what you'd want to run on a hardware wallet.
7 pub struct EnforcingChannelKeys {
8         pub inner: InMemoryChannelKeys,
9 }
10
11 impl EnforcingChannelKeys {
12         pub fn new(inner: InMemoryChannelKeys) -> Self {
13                 Self {
14                         inner,
15                 }
16         }
17 }
18 impl ChannelKeys for EnforcingChannelKeys {
19         fn funding_key(&self) -> &SecretKey { self.inner.funding_key() }
20         fn revocation_base_key(&self) -> &SecretKey { self.inner.revocation_base_key() }
21         fn payment_base_key(&self) -> &SecretKey { self.inner.payment_base_key() }
22         fn delayed_payment_base_key(&self) -> &SecretKey { self.inner.delayed_payment_base_key() }
23         fn htlc_base_key(&self) -> &SecretKey { self.inner.htlc_base_key() }
24         fn commitment_seed(&self) -> &[u8; 32] { self.inner.commitment_seed() }
25 }
26
27 impl_writeable!(EnforcingChannelKeys, 0, {
28         inner
29 });