@@ -31,6 +31,23 @@ macro_rules! doc_comment {
31
31
$( $tt) *
32
32
} ;
33
33
}
34
+ macro_rules! basepoint_impl {
35
+ ( $BasepointT: ty) => {
36
+ impl $BasepointT {
37
+ /// Get inner Public Key
38
+ pub fn to_public_key( & self ) -> PublicKey {
39
+ self . 0
40
+ }
41
+ }
42
+
43
+ impl From <PublicKey > for $BasepointT {
44
+ fn from( value: PublicKey ) -> Self {
45
+ Self ( value)
46
+ }
47
+ }
48
+
49
+ }
50
+ }
34
51
macro_rules! key_impl {
35
52
( $BasepointT: ty, $KeyName: expr) => {
36
53
doc_comment! {
@@ -80,24 +97,10 @@ macro_rules! key_read_write {
80
97
81
98
82
99
83
- /// [delayed_payment_basepoint](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation)
84
- /// Used to generate local_delayedpubkey for the latest state of a channel.
100
+ /// Used to generate [`local_delayedpubkey`](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) for the latest state of a channel.
85
101
#[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash ) ]
86
102
pub struct DelayedPaymentBasepoint ( PublicKey ) ;
87
-
88
- impl DelayedPaymentBasepoint {
89
- /// Get inner Public Key
90
- pub fn to_public_key ( & self ) -> PublicKey {
91
- self . 0
92
- }
93
- }
94
-
95
- impl From < PublicKey > for DelayedPaymentBasepoint {
96
- fn from ( value : PublicKey ) -> Self {
97
- Self ( value)
98
- }
99
- }
100
-
103
+ basepoint_impl ! ( DelayedPaymentBasepoint ) ;
101
104
key_read_write ! ( DelayedPaymentBasepoint ) ;
102
105
103
106
/// [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 {
110
113
}
111
114
key_read_write ! ( DelayedPaymentKey ) ;
112
115
113
- /// [payment_basepoint](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation)
114
- /// Used to generate localpubkey for the latest state of a channel.
116
+ /// Used to generate [localpubkey](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) for the latest state of a channel.
115
117
#[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash ) ]
116
118
pub struct PaymentBasepoint ( PublicKey ) ;
117
-
118
- impl PaymentBasepoint {
119
- /// Get inner Public Key
120
- pub fn to_public_key ( & self ) -> PublicKey {
121
- self . 0
122
- }
123
- }
124
-
125
- impl From < PublicKey > for PaymentBasepoint {
126
- fn from ( value : PublicKey ) -> Self {
127
- Self ( value)
128
- }
129
- }
130
-
119
+ basepoint_impl ! ( PaymentBasepoint ) ;
131
120
key_read_write ! ( PaymentBasepoint ) ;
132
121
133
122
@@ -141,24 +130,10 @@ impl PaymentKey {
141
130
}
142
131
key_read_write ! ( PaymentKey ) ;
143
132
144
- /// [htlc_basepoint](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation)
145
- /// Used to generate htlcpubkey for the latest state of a channel.
133
+ /// Used to generate [htlcpubkey](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) for the latest state of a channel.
146
134
#[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash ) ]
147
135
pub struct HtlcBasepoint ( PublicKey ) ;
148
-
149
- impl HtlcBasepoint {
150
- /// Get inner Public Key
151
- pub fn to_public_key ( & self ) -> PublicKey {
152
- self . 0
153
- }
154
- }
155
-
156
- impl From < PublicKey > for HtlcBasepoint {
157
- fn from ( value : PublicKey ) -> Self {
158
- Self ( value)
159
- }
160
- }
161
-
136
+ basepoint_impl ! ( HtlcBasepoint ) ;
162
137
key_read_write ! ( HtlcBasepoint ) ;
163
138
164
139
@@ -187,24 +162,10 @@ fn derive_public_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>, per_commitm
187
162
. 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." )
188
163
}
189
164
190
- /// [revocation_basepoint](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation)
191
- /// Used to generate htlcpubkey for the latest state of a channel.
165
+ /// Used to generate [htlcpubkey](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) for the latest state of a channel.
192
166
#[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash ) ]
193
167
pub struct RevocationBasepoint ( PublicKey ) ;
194
-
195
- impl RevocationBasepoint {
196
- /// Get inner Public Key
197
- pub fn to_public_key ( & self ) -> PublicKey {
198
- self . 0
199
- }
200
- }
201
-
202
- impl From < PublicKey > for RevocationBasepoint {
203
- fn from ( value : PublicKey ) -> Self {
204
- Self ( value)
205
- }
206
- }
207
-
168
+ basepoint_impl ! ( RevocationBasepoint ) ;
208
169
key_read_write ! ( RevocationBasepoint ) ;
209
170
210
171
0 commit comments