77//! 3. Derive macros don't provide significant simplification for this structure
88
99use bitcoin:: psbt:: Psbt as BdkPsbt ;
10+ use cove_util:: ResultExt as _;
1011use foundation_ur:: { UR , bytewords} ;
1112use minicbor:: { Decoder , Encoder , data:: Tag } ;
1213
@@ -35,7 +36,7 @@ impl CryptoPsbt {
3536 /// Returns error if PSBT deserialization fails
3637 pub fn from_bytes ( psbt_bytes : & [ u8 ] ) -> Result < Self > {
3738 let psbt = BdkPsbt :: deserialize ( psbt_bytes)
38- . map_err ( |e| UrError :: CborDecodeError ( format ! ( "Invalid PSBT: {e}" ) ) ) ?;
39+ . map_err_prefix ( "Invalid PSBT" , UrError :: CborDecodeError ) ?;
3940 Ok ( Self { psbt } )
4041 }
4142
@@ -63,10 +64,10 @@ impl CryptoPsbt {
6364 let mut encoder = Encoder :: new ( & mut buffer) ;
6465
6566 // write tag 310
66- encoder. tag ( Tag :: new ( CRYPTO_PSBT ) ) . map_err ( |e| UrError :: CborEncodeError ( e . to_string ( ) ) ) ?;
67+ encoder. tag ( Tag :: new ( CRYPTO_PSBT ) ) . map_err_str ( UrError :: CborEncodeError ) ?;
6768
6869 // write PSBT as byte string
69- encoder. bytes ( & psbt_bytes) . map_err ( |e| UrError :: CborEncodeError ( e . to_string ( ) ) ) ?;
70+ encoder. bytes ( & psbt_bytes) . map_err_str ( UrError :: CborEncodeError ) ?;
7071
7172 Ok ( buffer)
7273 }
@@ -95,7 +96,7 @@ impl CryptoPsbt {
9596
9697 // deserialize PSBT
9798 let psbt = BdkPsbt :: deserialize ( & psbt_bytes)
98- . map_err ( |e| UrError :: CborDecodeError ( format ! ( "Invalid PSBT: {e}" ) ) ) ?;
99+ . map_err_prefix ( "Invalid PSBT" , UrError :: CborDecodeError ) ?;
99100
100101 Ok ( Self { psbt } )
101102 }
@@ -115,7 +116,7 @@ impl CryptoPsbt {
115116 /// # Errors
116117 /// Returns error if UR parsing or CBOR decoding fails
117118 pub fn from_ur_string ( ur : & str ) -> Result < Self > {
118- let ur = UR :: parse ( ur) . map_err ( |e| UrError :: UrParseError ( e . to_string ( ) ) ) ?;
119+ let ur = UR :: parse ( ur) . map_err_str ( UrError :: UrParseError ) ?;
119120
120121 // verify UR type
121122 if ur. as_type ( ) != "crypto-psbt" {
@@ -130,7 +131,7 @@ impl CryptoPsbt {
130131 UR :: SinglePart { message, .. } => {
131132 // decode bytewords to bytes (UR uses minimal style)
132133 bytewords:: decode ( message, bytewords:: Style :: Minimal )
133- . map_err ( |e| UrError :: UrParseError ( format ! ( "Bytewords decode error: {e}" ) ) ) ?
134+ . map_err_prefix ( "Bytewords decode error" , UrError :: UrParseError ) ?
134135 }
135136 UR :: SinglePartDeserialized { message, .. } => {
136137 // already deserialized
0 commit comments