From 4213694a84b1b4a8c853c9c64078085acbf25c88 Mon Sep 17 00:00:00 2001 From: Roman Khlopkov <roman.khlopkov@demlabs.net> Date: Thu, 21 Dec 2023 13:09:25 +0000 Subject: [PATCH] hotfix-10122+ --- .../xchange/dap_chain_net_srv_xchange.c | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/service/xchange/dap_chain_net_srv_xchange.c b/modules/service/xchange/dap_chain_net_srv_xchange.c index c35e86862e..66ff3ee56c 100644 --- a/modules/service/xchange/dap_chain_net_srv_xchange.c +++ b/modules/service/xchange/dap_chain_net_srv_xchange.c @@ -567,13 +567,18 @@ static dap_chain_datum_tx_t *s_xchange_tx_create_exchange(dap_chain_net_srv_xcha return NULL; } bool l_pay_with_native = !dap_strcmp(a_price->token_sell, l_native_ticker); + bool l_buy_with_native = !dap_strcmp(a_price->token_buy, l_native_ticker); if (!l_pay_with_native) { - l_list_fee_out = dap_ledger_get_list_tx_outs_with_val(l_ledger, l_native_ticker, - &l_buyer_addr, l_total_fee, &l_fee_transfer); - if (!l_list_fee_out) { - dap_list_free_full(l_list_used_out, NULL); - log_it(L_WARNING, "Not enough funds to pay fee"); - return NULL; + if (l_buy_with_native) + SUM_256_256(l_value_need, l_total_fee, &l_value_need); + else { + l_list_fee_out = dap_ledger_get_list_tx_outs_with_val(l_ledger, l_native_ticker, + &l_buyer_addr, l_total_fee, &l_fee_transfer); + if (!l_list_fee_out) { + dap_list_free_full(l_list_used_out, NULL); + log_it(L_WARNING, "Not enough funds to pay fee"); + return NULL; + } } } @@ -589,7 +594,7 @@ static dap_chain_datum_tx_t *s_xchange_tx_create_exchange(dap_chain_net_srv_xcha log_it(L_ERROR, "Can't compose the transaction input"); return NULL; } - if (!l_pay_with_native) { + if (!l_pay_with_native && !l_buy_with_native) { // add 'in' items to fee uint256_t l_value_fee_items = dap_chain_datum_tx_add_in_item_list(&l_tx, l_list_fee_out); dap_list_free_full(l_list_fee_out, NULL); @@ -725,7 +730,7 @@ static dap_chain_datum_tx_t *s_xchange_tx_create_exchange(dap_chain_net_srv_xcha debug_if(s_debug_more, L_NOTICE, "l_value_transfer = %s", dap_chain_balance_to_coins(l_value_transfer)); debug_if(s_debug_more, L_NOTICE, "l_value_back = %s", dap_chain_balance_to_coins(l_value_back)); // fee back - if (!l_pay_with_native) { + if (!l_pay_with_native && !l_buy_with_native) { SUBTRACT_256_256(l_fee_transfer, l_total_fee, &l_value_back); if (!IS_ZERO_256(l_value_back)) { if (dap_chain_datum_tx_add_out_ext_item(&l_tx, &l_buyer_addr, l_value_back, l_native_ticker) == -1) { -- GitLab