fixing RPC API for burn

This commit is contained in:
cryptozoidberg 2024-10-15 17:54:50 +04:00
parent e58b20ae5b
commit ca51bd4886
No known key found for this signature in database
GPG key ID: 2E10CC61CAC8F36D
4 changed files with 33 additions and 10 deletions

View file

@ -5543,7 +5543,7 @@ void wallet2::transfer_asset_ownership(const crypto::public_key& asset_id, const
result_tx = ft.tx;
}
//----------------------------------------------------------------------------------------------------
void wallet2::burn_asset(const crypto::public_key& asset_id, uint64_t amount_to_burn, currency::finalized_tx& ft)
void wallet2::burn_asset(const crypto::public_key& asset_id, uint64_t amount_to_burn, currency::finalized_tx& ft, const std::vector<currency::tx_service_attachment>& service_entries, const std::string& address_to_point/* = const std::string()*/, uint64_t native_amount_to_point/* = 0*/)
{
currency::asset_descriptor_base last_adb{};
bool r = this->daemon_get_asset_info(asset_id, last_adb);
@ -5565,14 +5565,30 @@ void wallet2::burn_asset(const crypto::public_key& asset_id, uint64_t amount_to_
ctp.need_at_least_1_zc = true;
ctp.dsts.push_back(dst_to_burn);
ctp.tx_meaning_for_logs = "asset burn";
if (service_entries.size())
{
//put it to extra
ctp.extra.insert(ctp.extra.end(), service_entries.begin(), service_entries.end());
}
if (address_to_point.size())
{
currency::account_public_address addr = AUTO_VAL_INIT(addr);
bool r = currency::get_account_address_from_str(addr, address_to_point);
CHECK_AND_ASSERT_THROW_MES(r, "WRONG_ADDRESS");
currency::tx_destination_entry dst_to_point = AUTO_VAL_INIT(dst_to_point);
dst_to_point.asset_id = native_coin_asset_id;
dst_to_point.amount = native_amount_to_point;
dst_to_point.addr.push_back(addr);
ctp.dsts.push_back(dst_to_point);
}
this->transfer(ctp, ft, true, nullptr);
}
//----------------------------------------------------------------------------------------------------
void wallet2::burn_asset(const crypto::public_key& asset_id, uint64_t amount_to_burn, currency::transaction& result_tx)
void wallet2::burn_asset(const crypto::public_key& asset_id, uint64_t amount_to_burn, currency::transaction& result_tx, const std::vector<currency::tx_service_attachment>& service_entries, const std::string& address_to_point/* = const std::string()*/, uint64_t native_amount_to_point /*= 0*/)
{
finalized_tx ft{};
burn_asset(asset_id, amount_to_burn, ft);
burn_asset(asset_id, amount_to_burn, ft, service_entries, address_to_point, native_amount_to_point);
result_tx = ft.tx;
}
//----------------------------------------------------------------------------------------------------

View file

@ -422,13 +422,13 @@ namespace tools
void deploy_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector<currency::tx_destination_entry>& destinations, currency::transaction& result_tx, crypto::public_key& new_asset_id);
void emit_asset(const crypto::public_key& asset_id, std::vector<currency::tx_destination_entry>& destinations, currency::transaction& result_tx);
void update_asset(const crypto::public_key& asset_id, const currency::asset_descriptor_base new_descriptor, currency::transaction& result_tx);
void burn_asset(const crypto::public_key& asset_id, uint64_t amount_to_burn, currency::transaction& result_tx);
void burn_asset(const crypto::public_key& asset_id, uint64_t amount_to_burn, currency::transaction& result_tx, const std::vector<currency::tx_service_attachment>& service_entries = std::vector<currency::tx_service_attachment>(), const std::string& address_to_point = std::string(), uint64_t native_amount_to_point = 0);
void transfer_asset_ownership(const crypto::public_key& asset_id, const currency::asset_owner_pub_key_v& new_owner_v, currency::transaction& result_tx);
void deploy_new_asset(const currency::asset_descriptor_base& asset_info, const std::vector<currency::tx_destination_entry>& destinations, currency::finalized_tx& ft, crypto::public_key& new_asset_id);
void emit_asset(const crypto::public_key& asset_id, const std::vector<currency::tx_destination_entry>& destinations, currency::finalized_tx& ft);
void update_asset(const crypto::public_key& asset_id, const currency::asset_descriptor_base& new_descriptor, currency::finalized_tx& ft);
void burn_asset(const crypto::public_key& asset_id, uint64_t amount_to_burn, currency::finalized_tx& ft);
void burn_asset(const crypto::public_key& asset_id, uint64_t amount_to_burn, currency::finalized_tx& ft, const std::vector<currency::tx_service_attachment>& service_entries = std::vector<currency::tx_service_attachment>(), const std::string& address_to_point = std::string(), uint64_t native_amount_to_point = 0);
void transfer_asset_ownership(const crypto::public_key& asset_id, const currency::asset_owner_pub_key_v& new_owner_v, currency::finalized_tx& ft);
bool daemon_get_asset_info(const crypto::public_key& asset_id, currency::asset_descriptor_base& adb);
@ -960,7 +960,7 @@ private:
uint64_t m_last_known_daemon_height = 0;
//this needed to access wallets state in coretests, for creating abnormal blocks and tranmsactions
//this needed to access wallets state in coretests, for creating abnormal blocks and transactions
friend class test_generator;
}; // class wallet2

View file

@ -153,8 +153,8 @@ namespace wallet_public
std::vector<currency::tx_service_attachment> service_entries;
std::vector<std::string> remote_addresses; //optional
std::vector<std::string> remote_aliases; //optional, describe only if there only one remote address
std::vector<wallet_sub_transfer_info> subtransfers;
boost::optional<currency::asset_descriptor_operation> data_for_external_signing;
//not included in streaming serialization
uint64_t fee = 0;
@ -2087,12 +2087,19 @@ namespace wallet_public
struct request
{
crypto::public_key asset_id;
uint64_t burn_amount;
crypto::public_key asset_id = currency::null_pkey;
uint64_t burn_amount = 0;
//optional params
std::string point_tx_to_address;
uint64_t native_amount = 0;
std::vector<currency::tx_service_attachment> service_entries;
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
KV_SERIALIZE(point_tx_to_address) DOC_DSCR("Optional, if we need this transaction to be seen by particular wallet") DOC_EXMP("ZxBvJDuQjMG9R2j4WnYUhBYNrwZPwuyXrC7FHdVmWqaESgowDvgfWtiXeNGu8Px9B24pkmjsA39fzSSiEQG1ekB225ZnrMTBp") DOC_END
KV_SERIALIZE(native_amount) DOC_DSCR("Optional, if we need this transaction to be seen by particular wallet") DOC_EXMP(0) DOC_END
KV_SERIALIZE(service_entries) DOC_DSCR("Optional, if we need to include service entries for burn transaction") DOC_EXMP_AUTO(1) DOC_END
END_KV_SERIALIZE_MAP()
};

View file

@ -1388,7 +1388,7 @@ namespace tools
WALLET_RPC_BEGIN_TRY_ENTRY();
currency::finalized_tx ft{};
w.get_wallet()->burn_asset(req.asset_id, req.burn_amount, ft);
w.get_wallet()->burn_asset(req.asset_id, req.burn_amount, ft, req.service_entries, req.point_tx_to_address, req.native_amount);
res.tx_id = ft.tx_id;
return true;