From d3a4db9e370308cc3c875bd36274d56432682a0e Mon Sep 17 00:00:00 2001 From: sowle Date: Sun, 7 Jul 2024 20:39:22 +0200 Subject: [PATCH 1/4] set upper limit for the decimal point to to 18 in wallet2::deploy_new_asset() --- src/wallet/wallet2.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index a4d8f950..a8f31327 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5305,6 +5305,8 @@ void wallet2::request_alias_registration(currency::extra_alias_entry& ai, curren //---------------------------------------------------------------------------------------------------- void wallet2::deploy_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector& destinations, currency::transaction& result_tx, crypto::public_key& new_asset_id) { + WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(asset_info.decimal_point <= 18, "too big decimal point: " << asset_info.decimal_point); + asset_descriptor_operation asset_reg_info = AUTO_VAL_INIT(asset_reg_info); asset_reg_info.descriptor = asset_info; asset_reg_info.operation_type = ASSET_DESCRIPTOR_OPERATION_REGISTER; From b844f2ddf809a76b84ae5a12c34fefd438dbf047 Mon Sep 17 00:00:00 2001 From: sowle Date: Sun, 7 Jul 2024 20:40:33 +0200 Subject: [PATCH 2/4] simplewallet: asset_emit and asset_update now uses human-friendly amouts format + minor improvements --- src/simplewallet/simplewallet.cpp | 95 ++++++++++++++++++------------- 1 file changed, 56 insertions(+), 39 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 14f74dec..2a92db5d 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -2162,24 +2162,29 @@ bool simple_wallet::emit_asset(const std::vector &args) bool r = epee::string_tools::parse_tpod_from_hex_string(args[0], asset_id); if (!r) { - fail_msg_writer() << "Failed to load asset_id from: " << args[0]; + fail_msg_writer() << "Failed to load asset id: " << args[0]; + return true; + } + + currency::asset_descriptor_base adb = AUTO_VAL_INIT(adb); + uint32_t asset_flags = 0; + r = m_wallet->get_asset_info(asset_id, adb, asset_flags); + if (!r) + { + fail_msg_writer() << "Unknown asset id: " << args[0]; + return true; + } + if (!(asset_flags & tools::wallet2::aif_own)) + { + fail_msg_writer() << "The wallet appears to have no control over asset " << args[0]; return true; } uint64_t amount = 0; - r = epee::string_tools::get_xtype_from_string(amount, args[1]); + r = parse_amount(args[1], amount, adb.decimal_point); if (!r) { - fail_msg_writer() << "Failed to load amount from: " << args[1]; - return true; - } - - - currency::asset_descriptor_base adb = AUTO_VAL_INIT(adb); - r = m_wallet->daemon_get_asset_info(asset_id, adb); - if (!r) - { - fail_msg_writer() << "Wallet seems to don't have control over asset: " << args[0]; + fail_msg_writer() << "Failed to read amount: " << args[1] << " (assuming decimal point is " << (int)adb.decimal_point << ")"; return true; } @@ -2192,12 +2197,14 @@ bool simple_wallet::emit_asset(const std::vector &args) currency::transaction result_tx = AUTO_VAL_INIT(result_tx); m_wallet->emit_asset(asset_id, destinations, result_tx); - success_msg_writer(true) << "Emitted " << get_transaction_hash(result_tx) << " (unconfirmed) : " << ENDL - << "Asset ID: " << asset_id << ENDL - << "Title: " << adb.full_name << ENDL - << "Ticker: " << adb.ticker << ENDL - << "Emitted: " << print_fixed_decimal_point(amount, adb.decimal_point) << ENDL - << "Max emission: " << print_fixed_decimal_point(adb.total_max_supply, adb.decimal_point) << ENDL + success_msg_writer(true) << "Emitted " << print_money_brief(amount, adb.decimal_point) << " in tx " << get_transaction_hash(result_tx) << " (unconfirmed) : " << ENDL + << "Asset ID: " << asset_id << ENDL + << "Title: " << adb.full_name << ENDL + << "Ticker: " << adb.ticker << ENDL + << "Emitted now: " << print_money_brief(amount, adb.decimal_point) << ENDL + << "Emitted before: " << print_money_brief(adb.current_supply, adb.decimal_point) << ENDL + << "Emitted total: " << print_money_brief(adb.current_supply + amount, adb.decimal_point) << ENDL + << "Max emission: " << print_money_brief(adb.total_max_supply, adb.decimal_point) << ENDL ; SIMPLE_WALLET_CATCH_TRY_ENTRY(); @@ -2217,36 +2224,40 @@ bool simple_wallet::burn_asset(const std::vector &args) bool r = epee::string_tools::parse_tpod_from_hex_string(args[0], asset_id); if (!r) { - fail_msg_writer() << "Failed to load asset_id from: " << args[0]; + fail_msg_writer() << "Failed to load asset id: " << args[0]; return true; } - uint64_t amount = 0; - r = epee::string_tools::get_xtype_from_string(amount, args[1]); - if (!r) - { - fail_msg_writer() << "Failed to load amount from: " << args[1]; - return true; - } - - currency::asset_descriptor_base adb = AUTO_VAL_INIT(adb); - r = m_wallet->daemon_get_asset_info(asset_id, adb); + uint32_t asset_flags = 0; + r = m_wallet->get_asset_info(asset_id, adb, asset_flags); if (!r) { - fail_msg_writer() << "Wallet seems to don't have control over asset: " << args[0]; + fail_msg_writer() << "Unknown asset id: " << args[0]; + return true; + } + + // as this is asset burning, its not necessary for the wallet to own this asset, so we don't check tools::wallet2::aif_own here + + uint64_t amount = 0; + r = parse_amount(args[1], amount, adb.decimal_point); + if (!r) + { + fail_msg_writer() << "Failed to read amount: " << args[1] << " (assuming decimal point is " << (int)adb.decimal_point << ")"; return true; } currency::transaction result_tx = AUTO_VAL_INIT(result_tx); m_wallet->burn_asset(asset_id, amount, result_tx); - success_msg_writer(true) << "Burned " << get_transaction_hash(result_tx) << " (unconfirmed) : " << ENDL - << "Asset ID: " << asset_id << ENDL - << "Title: " << adb.full_name << ENDL - << "Ticker: " << adb.ticker << ENDL - << "Burned: " << print_fixed_decimal_point(amount, adb.decimal_point) << ENDL - << "Max emission: " << print_fixed_decimal_point(adb.total_max_supply, adb.decimal_point) << ENDL + success_msg_writer(true) << "Burned " << print_money_brief(amount, adb.decimal_point) << " in tx " << get_transaction_hash(result_tx) << " (unconfirmed) : " << ENDL + << "Asset ID: " << asset_id << ENDL + << "Title: " << adb.full_name << ENDL + << "Ticker: " << adb.ticker << ENDL + << "Burned now: " << print_money_brief(amount, adb.decimal_point) << ENDL + << "Emitted before: " << print_money_brief(adb.current_supply, adb.decimal_point) << ENDL + << "Current supply: " << print_money_brief(adb.current_supply - amount, adb.decimal_point) << ENDL + << "Max emission: " << print_money_brief(adb.total_max_supply, adb.decimal_point) << ENDL ; SIMPLE_WALLET_CATCH_TRY_ENTRY(); @@ -2280,10 +2291,16 @@ bool simple_wallet::update_asset(const std::vector &args) } currency::asset_descriptor_base adb = AUTO_VAL_INIT(adb); - r = m_wallet->daemon_get_asset_info(asset_id, adb); + uint32_t asset_flags = 0; + r = m_wallet->get_asset_info(asset_id, adb, asset_flags); if (!r) { - fail_msg_writer() << "Wallet seems to don't have control over asset: " << args[0]; + fail_msg_writer() << "Unknown asset id: " << args[0]; + return true; + } + if (!(asset_flags & tools::wallet2::aif_own)) + { + fail_msg_writer() << "The wallet appears to have no control over asset " << args[0]; return true; } @@ -2291,7 +2308,7 @@ bool simple_wallet::update_asset(const std::vector &args) currency::transaction result_tx = AUTO_VAL_INIT(result_tx); m_wallet->update_asset(asset_id, adb, result_tx); - success_msg_writer(true) << "Asset metainfo update tx sent: " << get_transaction_hash(result_tx) << " (unconfirmed) : " << ENDL + success_msg_writer(true) << "Asset metainfo successfully updated in tx " << get_transaction_hash(result_tx) << " (unconfirmed) : " << ENDL << "Asset ID: " << asset_id << ENDL << "Title: " << adb.full_name << ENDL << "Ticker: " << adb.ticker << ENDL From c5d5311121ee9cc3c18eab3af1d9a1e4ceb469d6 Mon Sep 17 00:00:00 2001 From: zano build machine Date: Sun, 7 Jul 2024 22:40:54 +0300 Subject: [PATCH 3/4] === build number: 327 -> 328 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index dd768e84..77ef5f94 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 327 +#define PROJECT_VERSION_BUILD_NO 328 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" From f6400abaeceb26baae3a252a82471ac815b98bda Mon Sep 17 00:00:00 2001 From: zano build machine Date: Mon, 8 Jul 2024 01:47:13 +0300 Subject: [PATCH 4/4] === build number: 328 -> 329 === --- src/version.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/version.h.in b/src/version.h.in index 77ef5f94..26a48cf4 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "0" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 328 +#define PROJECT_VERSION_BUILD_NO 329 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]"