diff --git a/lightning/src/ln/channel_keys.rs b/lightning/src/ln/channel_keys.rs index e84ff6d6706..a4cb02ae59e 100644 --- a/lightning/src/ln/channel_keys.rs +++ b/lightning/src/ln/channel_keys.rs @@ -31,6 +31,23 @@ macro_rules! doc_comment { $($tt)* }; } +macro_rules! basepoint_impl { + ($BasepointT:ty) => { + impl $BasepointT { + /// Get inner Public Key + pub fn to_public_key(&self) -> PublicKey { + self.0 + } + } + + impl From for $BasepointT { + fn from(value: PublicKey) -> Self { + Self(value) + } + } + + } +} macro_rules! key_impl { ($BasepointT:ty, $KeyName:expr) => { doc_comment! { @@ -80,24 +97,10 @@ macro_rules! key_read_write { -/// [delayed_payment_basepoint](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) -/// Used to generate local_delayedpubkey for the latest state of a channel. +/// Used to generate [`local_delayedpubkey`](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) for the latest state of a channel. #[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)] pub struct DelayedPaymentBasepoint(PublicKey); - -impl DelayedPaymentBasepoint { - /// Get inner Public Key - pub fn to_public_key(&self) -> PublicKey { - self.0 - } -} - -impl From for DelayedPaymentBasepoint { - fn from(value: PublicKey) -> Self { - Self(value) - } -} - +basepoint_impl!(DelayedPaymentBasepoint); key_read_write!(DelayedPaymentBasepoint); /// [delayedpubkey](https://github.com/lightning/bolts/blob/master/03-transactions.md#localpubkey-local_htlcpubkey-remote_htlcpubkey-local_delayedpubkey-and-remote_delayedpubkey-derivation) @@ -110,24 +113,10 @@ impl DelayedPaymentKey { } key_read_write!(DelayedPaymentKey); -/// [payment_basepoint](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) -/// Used to generate localpubkey for the latest state of a channel. +/// Used to generate [localpubkey](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) for the latest state of a channel. #[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)] pub struct PaymentBasepoint(PublicKey); - -impl PaymentBasepoint { - /// Get inner Public Key - pub fn to_public_key(&self) -> PublicKey { - self.0 - } -} - -impl From for PaymentBasepoint { - fn from(value: PublicKey) -> Self { - Self(value) - } -} - +basepoint_impl!(PaymentBasepoint); key_read_write!(PaymentBasepoint); @@ -141,24 +130,10 @@ impl PaymentKey { } key_read_write!(PaymentKey); -/// [htlc_basepoint](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) -/// Used to generate htlcpubkey for the latest state of a channel. +/// Used to generate [htlcpubkey](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) for the latest state of a channel. #[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)] pub struct HtlcBasepoint(PublicKey); - -impl HtlcBasepoint { - /// Get inner Public Key - pub fn to_public_key(&self) -> PublicKey { - self.0 - } -} - -impl From for HtlcBasepoint { - fn from(value: PublicKey) -> Self { - Self(value) - } -} - +basepoint_impl!(HtlcBasepoint); key_read_write!(HtlcBasepoint); @@ -187,24 +162,10 @@ fn derive_public_key(secp_ctx: &Secp256k1, per_commitm .expect("Addition only fails if the tweak is the inverse of the key. This is not possible when the tweak contains the hash of the key.") } -/// [revocation_basepoint](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) -/// Used to generate htlcpubkey for the latest state of a channel. +/// Used to generate [htlcpubkey](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) for the latest state of a channel. #[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)] pub struct RevocationBasepoint(PublicKey); - -impl RevocationBasepoint { - /// Get inner Public Key - pub fn to_public_key(&self) -> PublicKey { - self.0 - } -} - -impl From for RevocationBasepoint { - fn from(value: PublicKey) -> Self { - Self(value) - } -} - +basepoint_impl!(RevocationBasepoint); key_read_write!(RevocationBasepoint); diff --git a/lightning/src/sign/mod.rs b/lightning/src/sign/mod.rs index b45bf4e3666..e73129e8b93 100644 --- a/lightning/src/sign/mod.rs +++ b/lightning/src/sign/mod.rs @@ -1306,7 +1306,7 @@ impl EcdsaChannelSigner for InMemorySigner { &secp_ctx, &HtlcBasepoint::from(counterparty_keys.htlc_basepoint), &per_commitment_point, ); let holder_htlcpubkey = HtlcKey::from_basepoint( - &secp_ctx, &HtlcBasepoint::from(self.pubkeys().htlc_basepoint.to_owned()), &per_commitment_point, + &secp_ctx, &HtlcBasepoint::from(self.pubkeys().htlc_basepoint), &per_commitment_point, ); let chan_type = self.channel_type_features().expect(MISSING_PARAMS_ERR); chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, chan_type, &counterparty_htlcpubkey, &holder_htlcpubkey, &revocation_pubkey) @@ -1337,10 +1337,10 @@ impl EcdsaChannelSigner for InMemorySigner { ); let counterparty_keys = self.counterparty_pubkeys().expect(MISSING_PARAMS_ERR); let counterparty_htlcpubkey = HtlcKey::from_basepoint( - &secp_ctx, &HtlcBasepoint::from(counterparty_keys.htlc_basepoint.to_owned()), &per_commitment_point, + &secp_ctx, &HtlcBasepoint::from(counterparty_keys.htlc_basepoint), &per_commitment_point, ); let htlcpubkey = HtlcKey::from_basepoint( - &secp_ctx, &HtlcBasepoint::from(self.pubkeys().htlc_basepoint.to_owned()), &per_commitment_point, + &secp_ctx, &HtlcBasepoint::from(self.pubkeys().htlc_basepoint), &per_commitment_point, ); let chan_type = self.channel_type_features().expect(MISSING_PARAMS_ERR); let witness_script = chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, chan_type, &counterparty_htlcpubkey, &htlcpubkey, &revocation_pubkey); diff --git a/lightning/src/util/test_channel_signer.rs b/lightning/src/util/test_channel_signer.rs index 5b111b063bf..037c7004d7f 100644 --- a/lightning/src/util/test_channel_signer.rs +++ b/lightning/src/util/test_channel_signer.rs @@ -232,7 +232,7 @@ impl EcdsaChannelSigner for TestChannelSigner { input, &witness_script, htlc_descriptor.htlc.amount_msat / 1000, sighash_type ).unwrap(); let countersignatory_htlc_key = HtlcKey::from_basepoint( - &secp_ctx,&HtlcBasepoint::from(self.inner.counterparty_pubkeys().unwrap().htlc_basepoint.to_owned()), &htlc_descriptor.per_commitment_point, + &secp_ctx,&HtlcBasepoint::from(self.inner.counterparty_pubkeys().unwrap().htlc_basepoint), &htlc_descriptor.per_commitment_point, ); secp_ctx.verify_ecdsa(