From 985506e7ac1a1b8c829821f87faa7d3b211214c7 Mon Sep 17 00:00:00 2001 From: Jun Luo <4catcode@gmail.com> Date: Thu, 26 Aug 2021 14:58:37 +0800 Subject: [PATCH] fix: fix the jump problem in format_operation_source --- src/stellar_format.c | 36 +++++++++++++++++------- tests/src/test_tx.c | 1 + tests/testcases/txMultiOpWithSource.raw | Bin 0 -> 296 bytes tests/testcases/txMultiOpWithSource.txt | 12 ++++++++ 4 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 tests/testcases/txMultiOpWithSource.raw create mode 100644 tests/testcases/txMultiOpWithSource.txt diff --git a/src/stellar_format.c b/src/stellar_format.c index 2f0c417a..6b7971b1 100644 --- a/src/stellar_format.c +++ b/src/stellar_format.c @@ -92,19 +92,35 @@ static void format_confirm_transaction_details(tx_context_t *txCtx) { format_memo(txCtx); } +static void format_next_operation(tx_context_t *txCtx) { + formatter_stack[formatter_index] = NULL; + set_state_data(true); +} + static void format_operation_source(tx_context_t *txCtx) { - if (txCtx->opDetails.sourceAccountPresent) { - strcpy(detailCaption, "Op Source"); - print_public_key(txCtx->opDetails.sourceAccount, detailValue, 0, 0); - push_to_formatter_stack(&format_confirm_transaction_details); - } else { - if (txCtx->opIdx == txCtx->opCount) { - // last operation: show transaction details + if (txCtx->opIdx == txCtx->opCount) { + // last operation + if (txCtx->opDetails.sourceAccountPresent) { + // If there is a source account, wait for the user to + // enter the next step after displaying the source account + strcpy(detailCaption, "Op Source"); + print_public_key(txCtx->opDetails.sourceAccount, detailValue, 0, 0); + push_to_formatter_stack(&format_confirm_transaction_details); + } else { + // Otherwise, go to the next step and display the transaction information. format_confirm_transaction_details(txCtx); + } + } else { + // more operations + if (txCtx->opDetails.sourceAccountPresent) { + // If there is a source account, wait for the user to + // enter the next step after displaying the source account + strcpy(detailCaption, "Op Source"); + print_public_key(txCtx->opDetails.sourceAccount, detailValue, 0, 0); + push_to_formatter_stack(&format_next_operation); } else { - // more operations: show next operation - formatter_stack[formatter_index] = NULL; - set_state_data(true); + // Otherwise, show the next operation. + format_next_operation(txCtx); } } } diff --git a/tests/src/test_tx.c b/tests/src/test_tx.c index ddc6aa77..14d0b107 100644 --- a/tests/src/test_tx.c +++ b/tests/src/test_tx.c @@ -41,6 +41,7 @@ static const char *testcases[] = { "../testcases/txInflation.raw", "../testcases/txBumpSequence.raw", "../testcases/txManageBuyOffer.raw", + "../testcases/txMultiOpWithSource.raw", NULL, }; diff --git a/tests/testcases/txMultiOpWithSource.raw b/tests/testcases/txMultiOpWithSource.raw new file mode 100644 index 0000000000000000000000000000000000000000..de042c95181b66d5980a81c944ea5b694164db61 GIT binary patch literal 296 zcmX^2z(6;$#n))>sfjU7%y(Tj+wZQsBgrbaxN6^hjW<_{7#J9sfS7?T>UPQA5cA+$ zUtj#;HM!uWEUMnVR4DQ0C*im__X05wppp|HbwB`C52P7^SR}VJrzBH1zd*MUDXwLidbJTzxbu`i>Lbb8I^U5-ajknnbKyv6sUw) Q^Vo?s&nqAjq!er}01Ad=;{X5v literal 0 HcmV?d00001 diff --git a/tests/testcases/txMultiOpWithSource.txt b/tests/testcases/txMultiOpWithSource.txt new file mode 100644 index 00000000..7f36f9b0 --- /dev/null +++ b/tests/testcases/txMultiOpWithSource.txt @@ -0,0 +1,12 @@ +Operation 1 of 2; +Merge Account; GADFVW3UXVKDOU626XUPYDJU2BFCGFJHQ6SREYOZ6IJV4XSHOALEQN2I +Destination; GBMHY2EIEGFHW6G4OIC6QA7I7IUPUDD33PGCJLVC57THODEUQY62KNHD +Op Source; GADFVW3UXVKDOU626XUPYDJU2BFCGFJHQ6SREYOZ6IJV4XSHOALEQN2I +Operation 2 of 2; +Allow Trust; JPY +Account ID; GBMHY2EIEGFHW6G4OIC6QA7I7IUPUDD33PGCJLVC57THODEUQY62KNHD +Op Source; GADFVW3UXVKDOU626XUPYDJU2BFCGFJHQ6SREYOZ6IJV4XSHOALEQN2I +Memo Text; multi-op-with-source +Fee; 0.00002 XLM +Network; Test +Tx Source; GADFVW3UXVKDOU626XUPYDJU2BFCGFJHQ6SREYOZ6IJV4XSHOALEQN2I \ No newline at end of file