From 1ea5c1aa53739263ae2db251c2d0af976c6fae1c Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 5 Jul 2024 18:23:09 +0400 Subject: [PATCH 1/4] implemented burn assets API + fixed deploy asset API --- src/gui/qt-daemon/application/mainwindow.cpp | 8 +++++++ src/wallet/wallet_public_structs_defs.h | 24 ++++++++++++++++++++ src/wallet/wallet_rpc_server.cpp | 17 ++++++++++++++ src/wallet/wallet_rpc_server.h | 4 +++- 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 40758a4a..90f3b422 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -1767,6 +1767,14 @@ QString MainWindow::validate_address(const QString& param) LOG_API_TIMING(); view::address_validation_response ar = AUTO_VAL_INIT(ar); ar.error_code = m_backend.validate_address(param.toStdString(), ar.payment_id); + + //@#@ +//#ifdef _DEBUG +// std::string json_body; +// bool r = epee::file_io_utils::load_file_to_string("C:\\Users\\roky\\home\\temp\\deploy_test.json", json_body); +// async_call_2a("call_wallet_rpc", "0", json_body.c_str()); +//#endif + return MAKE_RESPONSE(ar); CATCH_ENTRY_FAIL_API_RESPONCE(); } diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index b9a5ddb9..49a5d288 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -2058,6 +2058,30 @@ namespace wallet_public }; }; + struct COMMAND_ASSETS_BURN + { + DOC_COMMAND("Burn some owned amount of the coins for the given asset."); + + struct request + { + crypto::public_key asset_id; + uint64_t burn_amount; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE_POD_AS_HEX_STRING(asset_id) DOC_DSCR("Id of the asset to burn") DOC_EXMP("40fa6db923728b38962718c61b4dc3af1acaa1967479c73703e260dc3609c58d") DOC_END + KV_SERIALIZE(burn_amount) DOC_DSCR("Amount to burn") DOC_EXMP(10000000) DOC_END + END_KV_SERIALIZE_MAP() + }; + + struct response + { + crypto::hash result_tx; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE_POD_AS_HEX_STRING(result_tx) DOC_DSCR("Id of transaction that carries asset burn operation") DOC_EXMP("f74bb56a5b4fa562e679ccaadd697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END + END_KV_SERIALIZE_MAP() + }; + }; } // namespace wallet_rpc } // namespace tools diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 9efaf197..192c642a 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -1282,9 +1282,16 @@ namespace tools bool wallet_rpc_server::on_assets_deploy(const wallet_public::COMMAND_ASSETS_DEPLOY::request& req, wallet_public::COMMAND_ASSETS_DEPLOY::response& res, epee::json_rpc::error& er, connection_context& cntx) { WALLET_RPC_BEGIN_TRY_ENTRY(); + currency::transaction result_tx; std::vector currency_destinations; rpc_destinations_to_currency_destination(req.destinations, currency_destinations); + //fix for default asset_id + for (auto& d : currency_destinations) + { + d.asset_id = currency::null_pkey; + } + w.get_wallet()->deploy_new_asset(req.asset_descriptor, currency_destinations, result_tx, res.new_asset_id); res.result_tx = currency::get_transaction_hash(result_tx); return true; @@ -1316,6 +1323,16 @@ namespace tools WALLET_RPC_CATCH_TRY_ENTRY(); } //------------------------------------------------------------------------------------------------------------------------------ + bool wallet_rpc_server::on_assets_burn(const wallet_public::COMMAND_ASSETS_BURN::request& req, wallet_public::COMMAND_ASSETS_BURN::response& res, epee::json_rpc::error& er, connection_context& cntx) + { + WALLET_RPC_BEGIN_TRY_ENTRY(); + currency::transaction result_tx; + w.get_wallet()->burn_asset(req.asset_id, req.burn_amount, result_tx); + res.result_tx = currency::get_transaction_hash(result_tx); + return true; + WALLET_RPC_CATCH_TRY_ENTRY(); + } + //------------------------------------------------------------------------------------------------------------------------------ bool wallet_rpc_server::on_mw_get_wallets(const wallet_public::COMMAND_MW_GET_WALLETS::request& req, wallet_public::COMMAND_MW_GET_WALLETS::response& res, epee::json_rpc::error& er, connection_context& cntx) { WALLET_RPC_BEGIN_TRY_ENTRY(); diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h index 9ea31394..4eac9211 100644 --- a/src/wallet/wallet_rpc_server.h +++ b/src/wallet/wallet_rpc_server.h @@ -149,6 +149,8 @@ namespace tools MAP_JON_RPC_WE("deploy_asset", on_assets_deploy, wallet_public::COMMAND_ASSETS_DEPLOY) MAP_JON_RPC_WE("emit_asset", on_assets_emit, wallet_public::COMMAND_ASSETS_EMIT) MAP_JON_RPC_WE("update_asset", on_assets_update, wallet_public::COMMAND_ASSETS_UPDATE) + MAP_JON_RPC_WE("burn_asset", on_assets_burn, wallet_public::COMMAND_ASSETS_BURN) + //MULTIWALLET APIs MAP_JON_RPC_WE("mw_get_wallets", on_mw_get_wallets, wallet_public::COMMAND_MW_GET_WALLETS) @@ -219,7 +221,7 @@ namespace tools bool on_assets_deploy(const wallet_public::COMMAND_ASSETS_DEPLOY::request& req, wallet_public::COMMAND_ASSETS_DEPLOY::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_assets_emit(const wallet_public::COMMAND_ASSETS_EMIT::request& req, wallet_public::COMMAND_ASSETS_EMIT::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_assets_update(const wallet_public::COMMAND_ASSETS_UPDATE::request& req, wallet_public::COMMAND_ASSETS_UPDATE::response& res, epee::json_rpc::error& er, connection_context& cntx); - + bool on_assets_burn(const wallet_public::COMMAND_ASSETS_BURN::request& req, wallet_public::COMMAND_ASSETS_BURN::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_mw_get_wallets(const wallet_public::COMMAND_MW_GET_WALLETS::request& req, wallet_public::COMMAND_MW_GET_WALLETS::response& res, epee::json_rpc::error& er, connection_context& cntx); bool on_mw_select_wallet(const wallet_public::COMMAND_MW_SELECT_WALLET::request& req, wallet_public::COMMAND_MW_SELECT_WALLET::response& res, epee::json_rpc::error& er, connection_context& cntx); From 9973546472b63378e0fc79eff4fbc0b8f8968369 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 5 Jul 2024 17:19:37 +0200 Subject: [PATCH 2/4] wallet RPC: enforce null asset id in destinations for asset emit operation --- src/wallet/wallet_rpc_server.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 192c642a..39c75e27 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -1304,6 +1304,11 @@ namespace tools currency::transaction result_tx; std::vector currency_destinations; rpc_destinations_to_currency_destination(req.destinations, currency_destinations); + //fix for default asset_id + for (auto& d : currency_destinations) + { + d.asset_id = currency::null_pkey; + } w.get_wallet()->emit_asset(req.asset_id, currency_destinations, result_tx); res.result_tx = currency::get_transaction_hash(result_tx); From 07c525644047c94bbf4f7d35f11ed762ebf80a06 Mon Sep 17 00:00:00 2001 From: sowle Date: Fri, 5 Jul 2024 18:00:22 +0200 Subject: [PATCH 3/4] using of asset id clarified for docs --- src/wallet/wallet_public_structs_defs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 49a5d288..c71cb2d2 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -1989,7 +1989,7 @@ namespace wallet_public currency::asset_descriptor_base asset_descriptor; BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(destinations) DOC_DSCR("Addresses where to receive emitted coins. Asset id in destinations should be set to 0000000000000000000000000000000000000000000000000000000000000000") DOC_EXMP_AUTO(1) DOC_END + KV_SERIALIZE(destinations) DOC_DSCR("Addresses where to receive emitted coins. Asset id in the destinations is irreleant and can be omitted.") DOC_EXMP_AUTO(1) DOC_END KV_SERIALIZE(asset_descriptor) DOC_DSCR("Descriptor that holds all information about asset - ticker, emission, description etc") DOC_END END_KV_SERIALIZE_MAP() }; @@ -2018,7 +2018,7 @@ namespace wallet_public BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE_POD_AS_HEX_STRING(asset_id) DOC_DSCR("Id of the asset to emit more coins") DOC_EXMP("40fa6db923728b38962718c61b4dc3af1acaa1967479c73703e260dc3609c58d") DOC_END - KV_SERIALIZE(destinations) DOC_DSCR("Addresses where to receive emitted coins. Asset id in destinations should be set to 0000000000000000000000000000000000000000000000000000000000000000") DOC_EXMP_AUTO(1) DOC_END + KV_SERIALIZE(destinations) DOC_DSCR("Addresses where to receive emitted coins. Asset id in the destinations is irreleant and can be omitted.") DOC_EXMP_AUTO(1) DOC_END END_KV_SERIALIZE_MAP() }; From 4d4e362c61dd5aba92fb651faa712287b345048a Mon Sep 17 00:00:00 2001 From: zano build machine Date: Fri, 5 Jul 2024 19:01:13 +0300 Subject: [PATCH 4/4] === build number: 324 -> 325 === --- 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 26d965ed..e42e8a83 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 324 +#define PROJECT_VERSION_BUILD_NO 325 #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 "]"