@@ -21,16 +21,17 @@ use bitcoin::blockdata::constants::ChainHash;
21
21
use bitcoin:: network:: constants:: Network ;
22
22
use bitcoin:: secp256k1:: PublicKey ;
23
23
use core:: convert:: TryFrom ;
24
+ use core:: str:: FromStr ;
24
25
use core:: time:: Duration ;
25
26
use crate :: io;
26
27
use crate :: ln:: features:: InvoiceRequestFeatures ;
27
28
use crate :: ln:: msgs:: DecodeError ;
28
29
use crate :: offers:: invoice_request:: InvoiceRequestTlvStream ;
29
30
use crate :: offers:: offer:: OfferTlvStream ;
30
- use crate :: offers:: parse:: { ParseError , ParsedMessage , SemanticError } ;
31
+ use crate :: offers:: parse:: { Bech32Encode , ParseError , ParsedMessage , SemanticError } ;
31
32
use crate :: offers:: payer:: { PayerContents , PayerTlvStream } ;
32
33
use crate :: onion_message:: BlindedPath ;
33
- use crate :: util:: ser:: SeekReadable ;
34
+ use crate :: util:: ser:: { SeekReadable , WithoutLength , Writeable , Writer } ;
34
35
use crate :: util:: string:: PrintableString ;
35
36
36
37
use crate :: prelude:: * ;
@@ -143,6 +144,18 @@ impl Refund {
143
144
}
144
145
}
145
146
147
+ impl AsRef < [ u8 ] > for Refund {
148
+ fn as_ref ( & self ) -> & [ u8 ] {
149
+ & self . bytes
150
+ }
151
+ }
152
+
153
+ impl Writeable for Refund {
154
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
155
+ WithoutLength ( & self . bytes ) . write ( writer)
156
+ }
157
+ }
158
+
146
159
type RefundTlvStream = ( PayerTlvStream , OfferTlvStream , InvoiceRequestTlvStream ) ;
147
160
148
161
impl SeekReadable for RefundTlvStream {
@@ -155,6 +168,18 @@ impl SeekReadable for RefundTlvStream {
155
168
}
156
169
}
157
170
171
+ impl Bech32Encode for Refund {
172
+ const BECH32_HRP : & ' static str = "lnr" ;
173
+ }
174
+
175
+ impl FromStr for Refund {
176
+ type Err = ParseError ;
177
+
178
+ fn from_str ( s : & str ) -> Result < Self , <Self as FromStr >:: Err > {
179
+ Refund :: from_bech32_str ( s)
180
+ }
181
+ }
182
+
158
183
impl TryFrom < Vec < u8 > > for Refund {
159
184
type Error = ParseError ;
160
185
@@ -236,3 +261,9 @@ impl TryFrom<RefundTlvStream> for RefundContents {
236
261
} )
237
262
}
238
263
}
264
+
265
+ impl core:: fmt:: Display for Refund {
266
+ fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
267
+ self . fmt_bech32_str ( f)
268
+ }
269
+ }
0 commit comments