1515 * limitations under the License.
1616 *****************************************************************************/
1717
18- use alloc:: vec:: Vec ;
18+ use alloc:: {
19+ vec:: Vec ,
20+ boxed:: Box ,
21+ } ;
1922
2023use crate :: {
2124 app_ui:: sign:: {
@@ -28,7 +31,7 @@ use crate::{
2831use messages:: {
2932 encode_as_compact, encode_to,
3033 mlcp:: { CoinType as PCoinType , SighashInputCommitment , TxOutput , H256 } ,
31- CoinType , Encode , InputAddressPath , Response , SignTxReq , Signature , TxInputReq ,
34+ CoinType , Encode , InputAddressPath , Response , SignTxReq , SignatureResponse , TxInputReq ,
3235 TxInputSignatureResponse , TxMetadataReq , TxMetadataV1Req , TxMetadataVersionReq , TxOutputReq ,
3336} ;
3437
@@ -120,9 +123,9 @@ pub struct TxParsingInputCommitmentsContext {
120123}
121124
122125impl TxParsingInputCommitmentsContext {
123- fn advance_next_input_additional_info_step < ' a > (
126+ fn advance_next_input_additional_info_step (
124127 mut self ,
125- review : & ' a NbglStreamingReview ,
128+ review : & NbglStreamingReview ,
126129 ) -> Result < TxParsingContext , StatusWord > {
127130 let finished_with_inputs = self . num_inputs_parsed >= ( self . metadata . num_inputs - 1 ) ;
128131
@@ -164,17 +167,22 @@ impl TxParsingInputCommitmentsContext {
164167 } ) ;
165168 Ok ( new_context)
166169 } else {
167- self . num_inputs_parsed = self . num_inputs_parsed + 1 ;
170+ self . num_inputs_parsed += 1 ;
168171 Ok ( TxParsingContext :: ParsingInputCommitments ( self ) )
169172 }
170173 }
171174}
172175
173176impl TxParsingInputsContext {
174177 fn advance_next_input_step ( mut self ) -> Result < TxParsingContext , StatusWord > {
175- let finished_with_inputs = self . num_inputs_parsed >= ( self . metadata . num_inputs - 1 ) ;
178+ self . num_inputs_parsed += 1 ;
179+ let finished_with_inputs = self . num_inputs_parsed >= self . metadata . num_inputs ;
176180
177181 if finished_with_inputs {
182+ if self . inputs . is_empty ( ) {
183+ return Err ( StatusWord :: NothingToSign ) ;
184+ }
185+
178186 // Update hash for input commitments and proceed with outputs
179187 self . tx_hasher
180188 . update ( & self . metadata . num_inputs . to_le_bytes ( ) )
@@ -198,7 +206,6 @@ impl TxParsingInputsContext {
198206 } ,
199207 ) )
200208 } else {
201- self . num_inputs_parsed = self . num_inputs_parsed + 1 ;
202209 Ok ( TxParsingContext :: ParsingInputs ( self ) )
203210 }
204211 }
@@ -226,13 +233,13 @@ impl TxParsingOutputsContext {
226233 & self . summary
227234 }
228235
229- fn advance_next_output_state < ' a > (
236+ fn advance_next_output_state (
230237 mut self ,
231- review : & ' a NbglStreamingReview ,
238+ review : & NbglStreamingReview ,
232239 output : & TxOutput ,
233240 ) -> Result < TxParsingContext , StatusWord > {
234241 if self . num_outputs_parsed < ( self . metadata . num_outputs - 1 ) {
235- self . num_outputs_parsed = self . num_outputs_parsed + 1 ;
242+ self . num_outputs_parsed += 1 ;
236243 Ok ( TxParsingContext :: ParsingOutputs ( self ) )
237244 } else {
238245 // Finalize the tx hash for signing
@@ -284,7 +291,7 @@ impl TxSigningContext {
284291 let private_key = Secp256k1 :: derive_from_path ( & addr) ;
285292 let sig = schnorr_sign ( & private_key, self . tx_hash . as_bytes ( ) ) ?;
286293
287- let signature = Signature ( sig) ;
294+ let signature = SignatureResponse ( sig) ;
288295 let input_idx = address. input_idx ;
289296 let multisig_idx = address. multisig_idx ;
290297
@@ -298,7 +305,7 @@ impl TxSigningContext {
298305 } ;
299306
300307 let new_ctx = if has_next {
301- self . num_inputs_signed = self . num_inputs_signed + 1 ;
308+ self . num_inputs_signed += 1 ;
302309 TxParsingContext :: Signing ( self )
303310 } else {
304311 TxParsingContext :: Finished
@@ -382,10 +389,7 @@ impl TxParsingContext {
382389 }
383390
384391 pub fn finished ( & self ) -> bool {
385- match self {
386- Self :: Finished => true ,
387- _ => false ,
388- }
392+ matches ! ( self , Self :: Finished )
389393 }
390394}
391395
@@ -396,7 +400,7 @@ pub fn setup_sign_tx(req: TxMetadataReq) -> Result<DataContext, StatusWord> {
396400
397401 tx_ctx. show_spinner ( ) ;
398402
399- Ok ( DataContext :: TxContext ( tx_ctx, ui_new_streaming_review ( ) ) )
403+ Ok ( DataContext :: TxContext ( Box :: new ( tx_ctx) , ui_new_streaming_review ( ) ) )
400404}
401405
402406fn handle_input_req (
@@ -419,20 +423,20 @@ fn handle_input_req(
419423 ctx. advance_next_input_step ( )
420424}
421425
422- fn handle_input_commitment_req < ' a > (
426+ fn handle_input_commitment_req (
423427 req : SighashInputCommitment ,
424428 mut ctx : TxParsingInputCommitmentsContext ,
425- review : & ' a NbglStreamingReview ,
429+ review : & NbglStreamingReview ,
426430) -> Result < TxParsingContext , StatusWord > {
427431 update_hash ( & req, & mut ctx. input_commitments_hasher ) ?;
428432 update_hash ( & req, & mut ctx. tx_hasher ) ?;
429433 ctx. advance_next_input_additional_info_step ( review)
430434}
431435
432- fn handle_output_req < ' a > (
436+ fn handle_output_req (
433437 req : TxOutputReq ,
434438 mut ctx : TxParsingOutputsContext ,
435- review : & ' a NbglStreamingReview ,
439+ review : & NbglStreamingReview ,
436440) -> Result < TxParsingContext , StatusWord > {
437441 if ui_streaming_review_show_output ( review, & req. out , ctx. metadata . coin ) ? {
438442 ctx. summary . process_output ( & req. out ) ?;
@@ -464,7 +468,7 @@ pub fn handle_sign_tx(
464468 ( SignTxReq :: NextSignature , TxParsingContext :: Finished ) => {
465469 return Err ( StatusWord :: TxAlreadyFinished )
466470 }
467- _ => return Err ( StatusWord :: WrongP1P2 ) ,
471+ _ => return Err ( StatusWord :: WrongContext ) ,
468472 } ;
469473
470474 let new_ctx = match new_ctx {
0 commit comments