@@ -87,17 +87,23 @@ impl<'a> BitcoinClient {
8787
8888 // Parse app response; if the response is a Response::Error, it is converted to BitcoinClientError::AppError.
8989 async fn parse_response ( response_raw : & ' a [ u8 ] ) -> Result < Response , BitcoinClientError > {
90- let resp: Response = postcard:: from_bytes ( response_raw) . map_err ( |_| {
90+ let mut decoder = minicbor:: Decoder :: new ( response_raw) ;
91+ let resp: Response = decoder. decode ( ) . map_err ( |_| {
9192 BitcoinClientError :: GenericError ( "Failed to parse response" . to_string ( ) )
9293 } ) ?;
93- if let Response :: Error ( e) = resp {
94- return Err ( BitcoinClientError :: AppError ( e) ) ;
94+ if decoder. position ( ) != response_raw. len ( ) {
95+ return Err ( BitcoinClientError :: GenericError (
96+ "Failed to parse response" . to_string ( ) ,
97+ ) ) ;
98+ }
99+ if let Response :: Error { error } = resp {
100+ return Err ( BitcoinClientError :: AppError ( error) ) ;
95101 }
96102 Ok ( resp)
97103 }
98104
99105 pub async fn exit ( & mut self ) -> Result < i32 , BitcoinClientError > {
100- let msg = postcard :: to_allocvec ( & Request :: Exit ) . map_err ( |_| {
106+ let msg = minicbor :: to_vec ( & Request :: Exit ) . map_err ( |_| {
101107 BitcoinClientError :: GenericError ( "Failed to serialize Exit request" . to_string ( ) )
102108 } ) ?;
103109
@@ -123,15 +129,15 @@ impl<'a> BitcoinClient {
123129 & mut self ,
124130 tree : message:: KeyTree ,
125131 ) -> Result < u32 , BitcoinClientError > {
126- let msg = postcard :: to_allocvec ( & Request :: GetMasterFingerprint { tree } ) . map_err ( |_| {
132+ let msg = minicbor :: to_vec ( & Request :: GetMasterFingerprint { tree } ) . map_err ( |_| {
127133 BitcoinClientError :: GenericError (
128134 "Failed to serialize GetMasterFingerprint request" . to_string ( ) ,
129135 )
130136 } ) ?;
131137
132138 let response_raw = self . send_message ( & msg) . await ?;
133139 match Self :: parse_response ( & response_raw) . await ? {
134- Response :: MasterFingerprint ( fpr ) => Ok ( fpr ) ,
140+ Response :: MasterFingerprint { fingerprint } => Ok ( fingerprint ) ,
135141 e => Err ( BitcoinClientError :: InvalidResponse ( format ! (
136142 "Invalid response: {:?}" ,
137143 e
@@ -149,7 +155,7 @@ impl<'a> BitcoinClient {
149155 let path = DerivationPath :: from_str ( bip32_path)
150156 . map_err ( |e| format ! ( "Failed to convert bip32_path: {}" , e) ) ?;
151157
152- let msg = postcard :: to_allocvec ( & Request :: GetExtendedPubkey {
158+ let msg = minicbor :: to_vec ( & Request :: GetExtendedPubkey {
153159 tree,
154160 display,
155161 path : message:: Bip32Path ( path. to_u32_vec ( ) ) ,
@@ -182,7 +188,7 @@ impl<'a> BitcoinClient {
182188 display : bool ,
183189 ) -> Result < [ u8 ; 78 ] , BitcoinClientError > {
184190 let path = common:: identity:: identity_derivation_path ( index) ;
185- let msg = postcard :: to_allocvec ( & Request :: GetExtendedPubkey {
191+ let msg = minicbor :: to_vec ( & Request :: GetExtendedPubkey {
186192 tree : message:: KeyTree :: Standard ,
187193 display,
188194 path : message:: Bip32Path ( path) ,
@@ -222,7 +228,7 @@ impl<'a> BitcoinClient {
222228 ) ,
223229 BitcoinClientError ,
224230 > {
225- let msg = postcard :: to_allocvec ( & Request :: RegisterAccount {
231+ let msg = minicbor :: to_vec ( & Request :: RegisterAccount {
226232 name : name. into ( ) ,
227233 account : account. clone ( ) ,
228234 registered_identities,
@@ -259,7 +265,7 @@ impl<'a> BitcoinClient {
259265 ) ,
260266 BitcoinClientError ,
261267 > {
262- let msg = postcard :: to_allocvec ( & Request :: RegisterIdentityKey {
268+ let msg = minicbor :: to_vec ( & Request :: RegisterIdentityKey {
263269 name : name. into ( ) ,
264270 pubkey : pubkey. to_vec ( ) ,
265271 } )
@@ -291,7 +297,7 @@ impl<'a> BitcoinClient {
291297 display : bool ,
292298 identity_index : Option < u32 > ,
293299 ) -> Result < ( String , Option < IdentitySignature > ) , BitcoinClientError > {
294- let msg = postcard :: to_allocvec ( & Request :: GetAddress {
300+ let msg = minicbor :: to_vec ( & Request :: GetAddress {
295301 display,
296302 name : Some ( name. to_string ( ) ) ,
297303 account : account. clone ( ) ,
@@ -322,7 +328,7 @@ impl<'a> BitcoinClient {
322328 & mut self ,
323329 psbt : & [ u8 ] ,
324330 ) -> Result < Vec < PartialSignature > , BitcoinClientError > {
325- let msg = postcard :: to_allocvec ( & Request :: SignPsbt {
331+ let msg = minicbor :: to_vec ( & Request :: SignPsbt {
326332 psbt : psbt. to_vec ( ) ,
327333 } )
328334 . map_err ( |_| {
@@ -331,7 +337,7 @@ impl<'a> BitcoinClient {
331337
332338 let response_raw = self . send_message ( & msg) . await ?;
333339 match Self :: parse_response ( & response_raw) . await ? {
334- Response :: PsbtSigned ( partial_sigs ) => Ok ( partial_sigs ) ,
340+ Response :: PsbtSigned { signatures } => Ok ( signatures ) ,
335341 e => Err ( BitcoinClientError :: InvalidResponse ( format ! (
336342 "Invalid response: {:?}" ,
337343 e
0 commit comments