1
0
Fork 0
forked from lthn/blockchain

asset emission: 1) fixed simplewallet's emit_asset command; 2) wallet2:emit_asset() now fix destinations for asset emission ad-hoc (null_pkey); 3) typos corrected

This commit is contained in:
sowle 2024-03-26 19:57:31 +01:00
parent c2fa968835
commit e1d7ea6302
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
4 changed files with 17 additions and 11 deletions

View file

@ -2113,11 +2113,11 @@ bool simple_wallet::emit_asset(const std::vector<std::string> &args)
tx_destination_entry td = AUTO_VAL_INIT(td);
td.addr.push_back(m_wallet->get_account().get_public_address());
td.amount = amount;
td.asset_id = asset_id;
td.asset_id = currency::null_pkey;
std::vector<currency::tx_destination_entry> destinations;
destinations.push_back(td);
currency::transaction result_tx = AUTO_VAL_INIT(result_tx);
m_wallet->emmit_asset(asset_id, destinations, 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

View file

@ -4954,7 +4954,7 @@ void wallet2::deploy_new_asset(const currency::asset_descriptor_base& asset_info
m_custom_assets[new_asset_id] = ado.descriptor;
}
//----------------------------------------------------------------------------------------------------
void wallet2::emmit_asset(const crypto::public_key asset_id, std::vector<currency::tx_destination_entry>& destinations, currency::transaction& result_tx)
void wallet2::emit_asset(const crypto::public_key asset_id, std::vector<currency::tx_destination_entry>& destinations, currency::transaction& result_tx)
{
auto own_asset_entry_it = m_own_asset_descriptors.find(asset_id);
@ -4976,6 +4976,12 @@ void wallet2::emmit_asset(const crypto::public_key asset_id, std::vector<currenc
ctp.ado_current_asset_owner = rsp.asset_descriptor.owner;
//ctp.asset_deploy_control_key = own_asset_entry_it->second.control_key;
for(auto& dst : ctp.dsts)
{
if (dst.asset_id == asset_id)
dst.asset_id = null_pkey; // emit operation requires null_pkey for emitting asset outputs, fix it ad-hoc here
}
finalized_tx ft = AUTO_VAL_INIT(ft);
this->transfer(ctp, ft, true, nullptr);
result_tx = ft.tx;

View file

@ -394,7 +394,7 @@ namespace tools
bool check_available_sources(std::list<uint64_t>& amounts);
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 emmit_asset(const crypto::public_key asset_id, std::vector<currency::tx_destination_entry>& destinations, currency::transaction& result_tx);
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 transfer_asset_ownership(const crypto::public_key asset_id, const crypto::public_key& new_owner, currency::transaction& result_tx);

View file

@ -142,9 +142,9 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v
CHECK_AND_ASSERT_MES(asset_info2.meta_info == asset_info.meta_info, false, "Failed to find needed asset in result balances");
//test emmit function
//test emit function
//use same destinations as we used before
miner_wlt->emmit_asset(asset_id, destinations, tx);
miner_wlt->emit_asset(asset_id, destinations, tx);
r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed");
@ -252,13 +252,13 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v
//miner_wlt->refresh();
// check emmit_asset() with modified 'current_supply'
// check emit_asset() with modified 'current_supply'
miner_wlt->get_debug_events_dispatcher().SUBSCIRBE_DEBUG_EVENT<wde_construct_tx_handle_asset_descriptor_operation_before_seal>([&](const wde_construct_tx_handle_asset_descriptor_operation_before_seal& o)
{
o.pado->descriptor.current_supply += 1000000;
});
//test emmit function but re-adjust current_supply to wrong amount
miner_wlt->emmit_asset(asset_id, destinations, tx);
//test emit function but re-adjust current_supply to wrong amount
miner_wlt->emit_asset(asset_id, destinations, tx);
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Unexpected number of txs in the pool: " << c.get_pool_transactions_count());
r = mine_next_pow_block_in_playtime(miner_wlt->get_account().get_public_address(), c);
CHECK_AND_ASSERT_MES(!r, false, "block with a bad tx was unexpectedly mined");
@ -305,7 +305,7 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v
uint64_t balance_alice_asset = alice_wlt->balance(asset_id);
uint64_t balance_miner_asset = miner_wlt->balance(asset_id);
alice_wlt->emmit_asset(asset_id, destinations, tx);
alice_wlt->emit_asset(asset_id, destinations, tx);
r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed");
@ -315,7 +315,7 @@ bool multiassets_basic_test::c1(currency::core& c, size_t ev_index, const std::v
CHECK_AND_ASSERT_MES(miner_wlt->balance(asset_id) == balance_miner_asset + destinations[0].amount, false, "Miner balance wrong");
CHECK_AND_ASSERT_MES(alice_wlt->balance(asset_id) == balance_alice_asset + destinations[1].amount, false, "Alice balance wrong");
//TODO: attempt to emmmit from old key, attempt to emmit from more then max supply
//TODO: attempt to emmmit from old key, attempt to emit from more then max supply
return true;
}