@@ -31,6 +31,23 @@ macro_rules! doc_comment {
3131        $( $tt) * 
3232    } ; 
3333} 
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+ } 
3451macro_rules!  key_impl { 
3552    ( $BasepointT: ty,  $KeyName: expr)  => { 
3653        doc_comment! { 
@@ -80,24 +97,10 @@ macro_rules! key_read_write {
8097
8198
8299
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. 
85101#[ derive( PartialEq ,  Eq ,  Clone ,  Copy ,  Debug ,  Hash ) ]  
86102pub  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 ) ; 
101104key_read_write ! ( DelayedPaymentBasepoint ) ; 
102105
103106/// [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 {
110113} 
111114key_read_write ! ( DelayedPaymentKey ) ; 
112115
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. 
115117#[ derive( PartialEq ,  Eq ,  Clone ,  Copy ,  Debug ,  Hash ) ]  
116118pub  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 ) ; 
131120key_read_write ! ( PaymentBasepoint ) ; 
132121
133122
@@ -141,24 +130,10 @@ impl PaymentKey {
141130} 
142131key_read_write ! ( PaymentKey ) ; 
143132
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. 
146134#[ derive( PartialEq ,  Eq ,  Clone ,  Copy ,  Debug ,  Hash ) ]  
147135pub  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 ) ; 
162137key_read_write ! ( HtlcBasepoint ) ; 
163138
164139
@@ -187,24 +162,10 @@ fn derive_public_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>, per_commitm
187162		. 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." ) 
188163} 
189164
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. 
192166#[ derive( PartialEq ,  Eq ,  Clone ,  Copy ,  Debug ,  Hash ) ]  
193167pub  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 ) ; 
208169key_read_write ! ( RevocationBasepoint ) ; 
209170
210171
0 commit comments