@@ -77,44 +77,7 @@ mod prelude {
7777
7878use crate :: prelude:: * ;
7979
80- /// Interface to write `Fe32`s into a sink
81- pub trait WriteBase32 {
82- /// Write error
83- type Err : fmt:: Debug ;
84-
85- /// Write a `Fe32` slice
86- fn write ( & mut self , data : & Vec < Fe32 > ) -> Result < ( ) , Self :: Err > {
87- for b in data {
88- self . write_fe32 ( * b) ?;
89- }
90- Ok ( ( ) )
91- }
92-
93- /// Write a single `Fe32`
94- fn write_fe32 ( & mut self , data : Fe32 ) -> Result < ( ) , Self :: Err > ;
95- }
96-
97- /// A trait for converting a value to a type `T` that represents a `Fe32` slice.
98- pub trait ToBase32 {
99- /// Convert `Self` to base32 vector
100- fn to_base32 ( & self ) -> Vec < Fe32 > {
101- let mut vec = Vec :: new ( ) ;
102- self . write_base32 ( & mut vec) . unwrap ( ) ;
103- vec
104- }
105-
106- /// Encode as base32 and write it to the supplied writer
107- /// Implementations shouldn't allocate.
108- fn write_base32 < W : WriteBase32 > ( & self , writer : & mut W ) -> Result < ( ) , <W as WriteBase32 >:: Err > ;
109- }
110-
111- /// Interface to calculate the length of the base32 representation before actually serializing
112- pub trait Base32Len : ToBase32 {
113- /// Calculate the base32 serialized length
114- fn base32_len ( & self ) -> usize ;
115- }
116-
117- /// Trait for paring/converting base32 slice. It is the reciprocal of `ToBase32`.
80+ /// Trait for paring/converting base32 slice.
11881pub trait FromBase32 : Sized {
11982 /// The associated error which can be returned from parsing (e.g. because of bad padding).
12083 type Err ;
@@ -347,6 +310,15 @@ pub struct RawHrp {
347310 pub si_prefix : Option < SiPrefix > ,
348311}
349312
313+ impl RawHrp {
314+ /// Convert to bech32::Hrp
315+ pub fn to_hrp ( & self ) -> bech32:: Hrp {
316+ let hrp_str = self . to_string ( ) ;
317+ let s = core:: str:: from_utf8 ( & hrp_str. as_bytes ( ) ) . expect ( "asserted to be ASCII" ) ;
318+ bech32:: Hrp :: parse_unchecked ( s)
319+ }
320+ }
321+
350322/// Data of the [`RawBolt11Invoice`] that is encoded in the data part
351323#[ derive( Eq , PartialEq , Debug , Clone , Hash , Ord , PartialOrd ) ]
352324pub struct RawDataPart {
@@ -1048,9 +1020,11 @@ impl RawBolt11Invoice {
10481020
10491021 /// Calculate the hash of the encoded `RawBolt11Invoice` which should be signed.
10501022 pub fn signable_hash ( & self ) -> [ u8 ; 32 ] {
1023+ use crate :: ser:: Base32Iterable ;
1024+
10511025 RawBolt11Invoice :: hash_from_parts (
10521026 self . hrp . to_string ( ) . as_bytes ( ) ,
1053- & self . data . to_base32 ( )
1027+ & self . data . fe_iter ( ) . collect :: < Vec < Fe32 > > ( ) ,
10541028 )
10551029 }
10561030
0 commit comments