From 0eabc7b69ebcd8f9bb3a6cf1aea327c304301e77 Mon Sep 17 00:00:00 2001 From: sowle Date: Sat, 6 Jul 2024 17:15:56 +0200 Subject: [PATCH] fixed non-standard decimal point handlinig in wallets_manager::transfer() --- src/common/error_codes.h | 1 + src/wallet/wallets_manager.cpp | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/common/error_codes.h b/src/common/error_codes.h index a1278d4b..1e3dc2ef 100644 --- a/src/common/error_codes.h +++ b/src/common/error_codes.h @@ -19,6 +19,7 @@ #define API_RETURN_CODE_BAD_ARG_WRONG_FEE "BAD_ARG_WRONG_FEE" #define API_RETURN_CODE_BAD_ARG_INVALID_ADDRESS "BAD_ARG_INVALID_ADDRESS" #define API_RETURN_CODE_BAD_ARG_WRONG_AMOUNT "BAD_ARG_WRONG_AMOUNT" +#define API_RETURN_CODE_BAD_ARG_UNKNOWN_DECIMAL_POINT "BAD_ARG_UNKNOWN_DECIMAL_POINT" #define API_RETURN_CODE_BAD_ARG_WRONG_PAYMENT_ID "BAD_ARG_WRONG_PAYMENT_ID" #define API_RETURN_CODE_WRONG_PASSWORD "WRONG_PASSWORD" #define API_RETURN_CODE_WALLET_WRONG_ID "WALLET_WRONG_ID" diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 7f3ee253..3a08b448 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1495,11 +1495,12 @@ std::string wallets_manager::request_alias_update(const currency::alias_rpc_deta std::string wallets_manager::transfer(uint64_t wallet_id, const view::transfer_params& tp, currency::transaction& res_tx) { - std::vector dsts; if(!tp.destinations.size()) return API_RETURN_CODE_BAD_ARG_EMPTY_DESTINATIONS; + GET_WALLET_BY_ID(wallet_id, w); + uint64_t fee = tp.fee; //payment_id std::vector attachments; @@ -1538,8 +1539,13 @@ std::string wallets_manager::transfer(uint64_t wallet_id, const view::transfer_p return API_RETURN_CODE_BAD_ARG_INVALID_ADDRESS; } - - if(!currency::parse_amount(d.amount, dsts.back().amount)) + size_t decimal_point = 0; + if (!w->get()->get_asset_decimal_point(d.asset_id, &decimal_point)) + { + return API_RETURN_CODE_BAD_ARG_UNKNOWN_DECIMAL_POINT; + } + + if(!currency::parse_amount(d.amount, dsts.back().amount, decimal_point)) { return API_RETURN_CODE_BAD_ARG_WRONG_AMOUNT; } @@ -1552,8 +1558,6 @@ std::string wallets_manager::transfer(uint64_t wallet_id, const view::transfer_p dsts.back().asset_id = d.asset_id; } - GET_WALLET_BY_ID(wallet_id, w); - if (payment_id.size()) { if (!currency::is_payment_id_size_ok(payment_id))