From 0898c707d97f03416d9a0d070f4c2c81dabca6da Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sat, 20 Dec 2014 20:55:32 +0100 Subject: [PATCH] move change logic before confirmation --- firmware/signing.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/firmware/signing.c b/firmware/signing.c index 80643432d2..e71b208b5e 100644 --- a/firmware/signing.c +++ b/firmware/signing.c @@ -322,7 +322,26 @@ void signing_txack(TransactionType *tx) return; case STAGE_REQUEST_3_OUTPUT: layoutProgress("Signing", 1000 * progress / progress_total, progress); progress++; - co = compile_output(coin, root, tx->outputs, &bin_output, idx1i == 0); + bool is_change = false; + if (idx1i == 0) { + if (tx->outputs[0].has_multisig) { + is_change = false; // TODO: detect when not needed + } else + if (tx->outputs[0].address_n_count > 0) { // address_n set -> change address + is_change = true; + } + if (is_change) { + if (change_spend == 0) { // not set + change_spend = tx->outputs[0].amount; + } else { + fsm_sendFailure(FailureType_Failure_Other, "Only one change output allowed"); + signing_abort(); + return; + } + } + spending += tx->outputs[0].amount; + } + co = compile_output(coin, root, tx->outputs, &bin_output, idx1i == 0 && !is_change); layoutProgress("Signing", 1000 * progress / progress_total, progress); progress++; if (co < 0) { fsm_sendFailure(FailureType_Failure_Other, "Signing cancelled by user"); @@ -343,18 +362,6 @@ void signing_txack(TransactionType *tx) signing_abort(); return; } - if (idx1i == 0) { - if (tx->outputs[0].address_n_count > 0) { // address_n set -> change address - if (change_spend == 0) { // not set - change_spend = tx->outputs[0].amount; - } else { - fsm_sendFailure(FailureType_Failure_Other, "Only one change output allowed"); - signing_abort(); - return; - } - } - spending += tx->outputs[0].amount; - } if (idx3o < outputs_count - 1) { idx3o++; send_req_3_output();