@@ -21,16 +21,17 @@ use bitcoin::blockdata::constants::ChainHash;
2121use bitcoin:: network:: constants:: Network ;
2222use bitcoin:: secp256k1:: PublicKey ;
2323use core:: convert:: TryFrom ;
24+ use core:: str:: FromStr ;
2425use core:: time:: Duration ;
2526use crate :: io;
2627use crate :: ln:: features:: InvoiceRequestFeatures ;
2728use crate :: ln:: msgs:: { DecodeError , MAX_VALUE_MSAT } ;
2829use crate :: offers:: invoice_request:: InvoiceRequestTlvStream ;
2930use crate :: offers:: offer:: OfferTlvStream ;
30- use crate :: offers:: parse:: { ParseError , ParsedMessage , SemanticError } ;
31+ use crate :: offers:: parse:: { Bech32Encode , ParseError , ParsedMessage , SemanticError } ;
3132use crate :: offers:: payer:: { PayerContents , PayerTlvStream } ;
3233use crate :: onion_message:: BlindedPath ;
33- use crate :: util:: ser:: SeekReadable ;
34+ use crate :: util:: ser:: { SeekReadable , WithoutLength , Writeable , Writer } ;
3435use crate :: util:: string:: PrintableString ;
3536
3637use crate :: prelude:: * ;
@@ -143,6 +144,18 @@ impl Refund {
143144 }
144145}
145146
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+
146159type RefundTlvStream = ( PayerTlvStream , OfferTlvStream , InvoiceRequestTlvStream ) ;
147160
148161impl SeekReadable for RefundTlvStream {
@@ -155,6 +168,18 @@ impl SeekReadable for RefundTlvStream {
155168 }
156169}
157170
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+
158183impl TryFrom < Vec < u8 > > for Refund {
159184 type Error = ParseError ;
160185
@@ -239,3 +264,9 @@ impl TryFrom<RefundTlvStream> for RefundContents {
239264 } )
240265 }
241266}
267+
268+ impl core:: fmt:: Display for Refund {
269+ fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
270+ self . fmt_bech32_str ( f)
271+ }
272+ }
0 commit comments