Make ChannelKeys an API and template Channel with it.
[rust-lightning] / lightning / src / util / enforcing_trait_impls.rs
diff --git a/lightning/src/util/enforcing_trait_impls.rs b/lightning/src/util/enforcing_trait_impls.rs
new file mode 100644 (file)
index 0000000..728caed
--- /dev/null
@@ -0,0 +1,29 @@
+use chain::keysinterface::{ChannelKeys, InMemoryChannelKeys};
+
+use secp256k1::key::SecretKey;
+
+/// Enforces some rules on ChannelKeys calls. Eventually we will probably want to expose a variant
+/// of this which would essentially be what you'd want to run on a hardware wallet.
+pub struct EnforcingChannelKeys {
+       pub inner: InMemoryChannelKeys,
+}
+
+impl EnforcingChannelKeys {
+       pub fn new(inner: InMemoryChannelKeys) -> Self {
+               Self {
+                       inner,
+               }
+       }
+}
+impl ChannelKeys for EnforcingChannelKeys {
+       fn funding_key(&self) -> &SecretKey { self.inner.funding_key() }
+       fn revocation_base_key(&self) -> &SecretKey { self.inner.revocation_base_key() }
+       fn payment_base_key(&self) -> &SecretKey { self.inner.payment_base_key() }
+       fn delayed_payment_base_key(&self) -> &SecretKey { self.inner.delayed_payment_base_key() }
+       fn htlc_base_key(&self) -> &SecretKey { self.inner.htlc_base_key() }
+       fn commitment_seed(&self) -> &[u8; 32] { self.inner.commitment_seed() }
+}
+
+impl_writeable!(EnforcingChannelKeys, 0, {
+       inner
+});