From 05d7ac838d95a527f3680e37aefd88fbd0a0ddd7 Mon Sep 17 00:00:00 2001 From: Francois Beutin Date: Thu, 20 Apr 2023 11:58:21 +0200 Subject: [PATCH] Rate must not change from START_NEW_TRANSACTION_COMMAND to UI display --- src/check_asset_in.c | 1 - src/check_refund_address.c | 1 - src/command_dispatcher.c | 19 ++++++++++++------- src/start_new_transaction.c | 1 + 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/check_asset_in.c b/src/check_asset_in.c index 42bea467..985f0379 100644 --- a/src/check_asset_in.c +++ b/src/check_asset_in.c @@ -132,7 +132,6 @@ int check_asset_in(const command_t *cmd) { } G_swap_ctx.state = WAITING_USER_VALIDATION; - G_swap_ctx.rate = cmd->rate; ui_validate_amounts(); diff --git a/src/check_refund_address.c b/src/check_refund_address.c index 5d43af8e..ea4109a1 100644 --- a/src/check_refund_address.c +++ b/src/check_refund_address.c @@ -108,7 +108,6 @@ int check_refund_address(const command_t *cmd) { PRINTF("Fees: %s\n", G_swap_ctx.printable_fees_amount); G_swap_ctx.state = WAITING_USER_VALIDATION; - G_swap_ctx.rate = cmd->rate; ui_validate_amounts(); diff --git a/src/command_dispatcher.c b/src/command_dispatcher.c index 652d1d5b..aa6cbfe2 100644 --- a/src/command_dispatcher.c +++ b/src/command_dispatcher.c @@ -45,32 +45,35 @@ int dispatch_command(const command_t *cmd) { break; case SET_PARTNER_KEY_COMMAND: if (G_swap_ctx.state == WAITING_TRANSACTION && - cmd->subcommand == G_swap_ctx.subcommand) { + cmd->subcommand == G_swap_ctx.subcommand && cmd->rate == G_swap_ctx.rate) { ret = set_partner_key(cmd); valid_command_received = true; } break; case CHECK_PARTNER_COMMAND: - if (G_swap_ctx.state == PROVIDER_SET && cmd->subcommand == G_swap_ctx.subcommand) { + if (G_swap_ctx.state == PROVIDER_SET && cmd->subcommand == G_swap_ctx.subcommand && + cmd->rate == G_swap_ctx.rate) { ret = check_partner(cmd); valid_command_received = true; } break; case PROCESS_TRANSACTION_RESPONSE_COMMAND: - if (G_swap_ctx.state == PROVIDER_CHECKED && cmd->subcommand == G_swap_ctx.subcommand) { + if (G_swap_ctx.state == PROVIDER_CHECKED && cmd->subcommand == G_swap_ctx.subcommand && + cmd->rate == G_swap_ctx.rate) { ret = process_transaction(cmd); valid_command_received = true; } break; case CHECK_TRANSACTION_SIGNATURE_COMMAND: if (G_swap_ctx.state == TRANSACTION_RECEIVED && - cmd->subcommand == G_swap_ctx.subcommand) { + cmd->subcommand == G_swap_ctx.subcommand && cmd->rate == G_swap_ctx.rate) { ret = check_tx_signature(cmd); valid_command_received = true; } break; case CHECK_PAYOUT_ADDRESS: - if (G_swap_ctx.state == SIGNATURE_CHECKED && cmd->subcommand == G_swap_ctx.subcommand) { + if (G_swap_ctx.state == SIGNATURE_CHECKED && cmd->subcommand == G_swap_ctx.subcommand && + cmd->rate == G_swap_ctx.rate) { if (cmd->subcommand == SELL || cmd->subcommand == FUND) { ret = check_asset_in(cmd); } else { @@ -80,13 +83,15 @@ int dispatch_command(const command_t *cmd) { } break; case CHECK_REFUND_ADDRESS: - if (G_swap_ctx.state == TO_ADDR_CHECKED && cmd->subcommand == G_swap_ctx.subcommand) { + if (G_swap_ctx.state == TO_ADDR_CHECKED && cmd->subcommand == G_swap_ctx.subcommand && + cmd->rate == G_swap_ctx.rate) { ret = check_refund_address(cmd); valid_command_received = true; } break; case START_SIGNING_TRANSACTION: - if (G_swap_ctx.state == WAITING_SIGNING && cmd->subcommand == G_swap_ctx.subcommand) { + if (G_swap_ctx.state == WAITING_SIGNING && cmd->subcommand == G_swap_ctx.subcommand && + cmd->rate == G_swap_ctx.rate) { ret = start_signing_transaction(cmd); valid_command_received = true; } diff --git a/src/start_new_transaction.c b/src/start_new_transaction.c index 206c17fc..d035adf8 100644 --- a/src/start_new_transaction.c +++ b/src/start_new_transaction.c @@ -54,6 +54,7 @@ int start_new_transaction(const command_t *cmd) { G_swap_ctx.state = WAITING_TRANSACTION; G_swap_ctx.subcommand = cmd->subcommand; + G_swap_ctx.rate = cmd->rate; return 0; }