1
0
Fork 0
forked from lthn/blockchain

Merge branch 'cryptoassets' into multiassets

This commit is contained in:
cryptozoidberg 2023-05-02 16:18:18 +02:00
commit 32fca807c3
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
5 changed files with 62 additions and 63 deletions

View file

@ -3264,7 +3264,7 @@ bool blockchain_storage::get_est_height_from_date(uint64_t date, uint64_t& res_h
//we moved too much forward
current_height_boundary = calculated_estimated_height;
CHECK_AND_ASSERT_MES(current_height_boundary > current_low_boundary, true,
CHECK_AND_ASSERT_MES(current_height_boundary >= current_low_boundary, true,
"Internal error: current_hight_boundary(" << current_height_boundary << ") > current_low_boundary("<< current_low_boundary << ")");
uint64_t offset = (current_height_boundary - current_low_boundary)/2;
if (offset <= 2)
@ -3282,7 +3282,7 @@ bool blockchain_storage::get_est_height_from_date(uint64_t date, uint64_t& res_h
{
//we too much in past
current_low_boundary = calculated_estimated_height;
CHECK_AND_ASSERT_MES(current_height_boundary > current_low_boundary, true,
CHECK_AND_ASSERT_MES(current_height_boundary >= current_low_boundary, true,
"Internal error: current_hight_boundary(" << current_height_boundary << ") > current_low_boundary(" << current_low_boundary << ")");
uint64_t offset = (current_height_boundary - current_low_boundary) / 2;
if (offset <= 2)

View file

@ -937,6 +937,7 @@ void wallet2::accept_proposal(const crypto::hash& contract_id, uint64_t b_accept
construct_tx_param construct_param = AUTO_VAL_INIT(construct_param);
construct_param.fee = b_acceptance_fee;
mode_separate_context msc = AUTO_VAL_INIT(msc);
msc.escrow = true;
msc.tx_for_mode_separate = contr_it->second.proposal.tx_template;
currency::transaction& tx = msc.tx_for_mode_separate;
crypto::secret_key one_time_key = contr_it->second.proposal.tx_onetime_secret_key;
@ -3248,6 +3249,7 @@ bool wallet2::balance(std::list<wallet_public::asset_balance_entry>& balances, u
auto it_local = m_whitelisted_assets.find(item.first);
if(it_local == m_whitelisted_assets.end())
{
WLT_LOG_YELLOW("WARNING: unknown asset " << item.first << " found and skipped; it's NOT included in balance", LOG_LEVEL_0);
continue;
}
else
@ -5275,6 +5277,7 @@ bool wallet2::accept_ionic_swap_proposal(const wallet_public::ionic_swap_proposa
construct_param.crypt_address = m_account.get_public_address();
construct_param.flags = TX_FLAG_SIGNATURE_MODE_SEPARATE;
construct_param.mark_tx_as_complete = true;
construct_param.need_at_least_1_zc = true;
//build transaction
currency::finalize_tx_param ftp = AUTO_VAL_INIT(ftp);
@ -6088,46 +6091,6 @@ bool wallet2::select_transfers(assets_selection_context& needed_money_map, size_
return select_indices_for_transfer(needed_money_map, fake_outputs_count, selected_indicies);
}
//----------------------------------------------------------------------------------------------------
bool wallet2::read_money_transfer2_details_from_tx(const transaction& tx, const std::vector<currency::tx_destination_entry>& splitted_dsts,
wallet_public::wallet_transfer_info_details& wtd)
{
PROFILE_FUNC("wallet2::read_money_transfer2_details_from_tx");
for (auto& d : splitted_dsts)
{
if (d.addr.size() && d.addr.back().spend_public_key == m_account.get_keys().account_address.spend_public_key &&
d.addr.back().view_public_key == m_account.get_keys().account_address.view_public_key)
wtd.rcv.push_back(d.amount);
}
//scan key images
for (auto& i : tx.vin)
{
if (i.type() == typeid(currency::txin_to_key))
{
const currency::txin_to_key& in_to_key = boost::get<currency::txin_to_key>(i);
if (m_key_images.count(in_to_key.k_image))
{
wtd.spn.push_back(in_to_key.amount);
}
}
else if (i.type() == typeid(currency::txin_zc_input))
{
const currency::txin_zc_input& in_zc = boost::get<currency::txin_zc_input>(i);
//should we panic if image not found?
//@zoidberg: nope!
if (m_key_images.count(in_zc.k_image))
{
auto it = m_key_images.find(in_zc.k_image);
WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(it != m_key_images.end(), "[read_money_transfer2_details_from_tx]Unknown key image in tx: " << get_transaction_hash(tx));
WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(it->second < m_transfers.size(), "[read_money_transfer2_details_from_tx]Index out of range for key image in tx: " << get_transaction_hash(tx));
wtd.spn.push_back(m_transfers[it->second].amount());
}
}
}
return true;
}
//----------------------------------------------------------------------------------------------------
void wallet2::add_sent_unconfirmed_tx(const currency::transaction& tx,
const std::vector<std::string>& recipients,
const std::vector<uint64_t>& selected_indicies,
@ -6142,17 +6105,50 @@ void wallet2::add_sent_unconfirmed_tx(const currency::transaction& tx,
unconfirmed_wti.remote_aliases.push_back(get_alias_for_address(addr));
unconfirmed_wti.is_income = false;
unconfirmed_wti.selected_indicies = selected_indicies;
/*TODO: add selected_indicies to read_money_transfer2_details_from_tx in case of performance problems*/
read_money_transfer2_details_from_tx(tx, splitted_dsts, unconfirmed_wti.td);
uint64_t change_amount = 0;
uint64_t inputs_amount = 0;
for (auto i : unconfirmed_wti.td.rcv)
change_amount += i;
for (auto i : unconfirmed_wti.td.spn)
inputs_amount += i;
unconfirmed_wti.asset_id = null_pkey;
prepare_wti(unconfirmed_wti, 0, m_core_runtime_config.get_core_time(), tx, inputs_amount - (change_amount + get_tx_fee(tx)), money_transfer2_details());
uint64_t native_coin_change_amount = 0;
uint64_t native_coin_inputs_amount = 0;
// TODO @#@# potential issue: one tx may have different asset_id's in INs or OUTs
// but only one asset_id is associated with a transfer atm
// possible solution: make a transfer item for each asset_id in tx -- sowle
for (auto& d : splitted_dsts)
{
if (d.addr.size() &&
d.addr.back().spend_public_key == m_account.get_keys().account_address.spend_public_key &&
d.addr.back().view_public_key == m_account.get_keys().account_address.view_public_key)
{
unconfirmed_wti.td.rcv.push_back(d.amount);
WLT_CHECK_AND_ASSERT_MES(unconfirmed_wti.asset_id == null_pkey || unconfirmed_wti.asset_id == d.asset_id, (void)0, "TODO: BAD case with asset_id");
unconfirmed_wti.asset_id = d.asset_id;
if (d.asset_id == native_coin_asset_id)
native_coin_change_amount += d.amount;
}
}
//scan key images
for (auto& i : tx.vin)
{
crypto::key_image ki{};
if (get_key_image_from_txin_v(i, ki))
{
if (m_key_images.count(ki))
{
auto it = m_key_images.find(ki);
WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(it != m_key_images.end(), "[read_money_transfer2_details_from_tx]Unknown key image in tx: " << get_transaction_hash(tx));
WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(it->second < m_transfers.size(), "[read_money_transfer2_details_from_tx]Index out of range for key image in tx: " << get_transaction_hash(tx));
unconfirmed_wti.td.spn.push_back(m_transfers[it->second].amount());
WLT_CHECK_AND_ASSERT_MES(unconfirmed_wti.asset_id == null_pkey || unconfirmed_wti.asset_id == m_transfers[it->second].get_asset_id(), (void)0, "TODO: BAD case with asset_id");
unconfirmed_wti.asset_id = m_transfers[it->second].get_asset_id();
if (unconfirmed_wti.asset_id == native_coin_asset_id)
native_coin_inputs_amount += m_transfers[it->second].amount();
}
}
}
prepare_wti(unconfirmed_wti, 0, m_core_runtime_config.get_core_time(), tx, native_coin_inputs_amount - (native_coin_change_amount + get_tx_fee(tx)), money_transfer2_details());
rise_on_transfer2(unconfirmed_wti);
}
//----------------------------------------------------------------------------------------------------
@ -6373,16 +6369,16 @@ void wallet2::prepare_tx_destinations(uint64_t needed_money,
}
}
//----------------------------------------------------------------------------------------------------
void wallet2::prepare_transaction(construct_tx_param& ctp, currency::finalize_tx_param& ftp, const mode_separate_context& mode_separatemode_separate)
void wallet2::prepare_transaction(construct_tx_param& ctp, currency::finalize_tx_param& ftp, const mode_separate_context& msc)
{
SET_CONTEXT_OBJ_FOR_SCOPE(pconstruct_tx_param, ctp);
SET_CONTEXT_OBJ_FOR_SCOPE(pfinalize_tx_param, ftp);
SET_CONTEXT_OBJ_FOR_SCOPE(pmode_separate_context, mode_separatemode_separate);
SET_CONTEXT_OBJ_FOR_SCOPE(pmode_separate_context, msc);
TIME_MEASURE_START_MS(get_needed_money_time);
const currency::transaction& tx_for_mode_separate = mode_separatemode_separate.tx_for_mode_separate;
const currency::transaction& tx_for_mode_separate = msc.tx_for_mode_separate;
assets_selection_context needed_money_map = get_needed_money(ctp.fee, ctp.dsts);
//
@ -6391,11 +6387,14 @@ void wallet2::prepare_transaction(construct_tx_param& ctp, currency::finalize_tx
if (ctp.flags & TX_FLAG_SIGNATURE_MODE_SEPARATE && tx_for_mode_separate.vout.size() )
{
WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(get_tx_flags(tx_for_mode_separate) & TX_FLAG_SIGNATURE_MODE_SEPARATE, "tx_param.flags differs from tx.flags");
for (const auto& el : mode_separatemode_separate.proposal_info.to_alice)
if (ftp.tx_version > TRANSACTION_VERSION_PRE_HF4)
{
needed_money_map[el.asset_id].needed_amount += el.amount;
for (const auto& el : msc.proposal_info.to_alice)
needed_money_map[el.asset_id].needed_amount += el.amount;
}
ctp.need_at_least_1_zc = true;
if (msc.escrow)
needed_money_map[currency::native_coin_asset_id].needed_amount += (currency::get_outs_money_amount(tx_for_mode_separate) - get_inputs_money_amount(tx_for_mode_separate));
}
TIME_MEASURE_FINISH_MS(get_needed_money_time);
@ -6425,7 +6424,7 @@ void wallet2::prepare_transaction(construct_tx_param& ctp, currency::finalize_tx
{
//multisig
//@#@ need to do refactoring over this part to support hidden amounts and asset_id
prepare_tx_sources(ctp.multisig_id, ftp.sources, needed_money_map[currency::null_pkey].found_amount);
prepare_tx_sources(ctp.multisig_id, ftp.sources, needed_money_map[currency::native_coin_asset_id].found_amount);
}
else
{

View file

@ -307,6 +307,7 @@ namespace tools
{
currency::transaction tx_for_mode_separate;
view::ionic_swap_proposal_info proposal_info;
bool escrow = false;
};
@ -1010,9 +1011,6 @@ private:
const std::vector<std::string>& recipients,
const std::vector<uint64_t>& selected_indicies,
const std::vector<currency::tx_destination_entry>& splitted_dsts);
bool read_money_transfer2_details_from_tx(const currency::transaction& tx,
const std::vector<currency::tx_destination_entry>& splitted_dsts,
wallet_public::wallet_transfer_info_details& wtd);
void update_current_tx_limit();
void prepare_wti(wallet_public::wallet_transfer_info& wti, uint64_t height, uint64_t timestamp, const currency::transaction& tx, uint64_t amount, const money_transfer2_details& td);

View file

@ -1653,7 +1653,8 @@ bool construct_tx_to_key(const currency::hard_forks_descriptor& hf,
if (!fill_tx_sources(sources, events, blk_head, from.get_keys(), spending_amount, nmix, check_for_spends, check_for_unlocktime, use_ref_by_id))
return false;
uint64_t tx_version = currency::get_tx_version(get_block_height(blk_head), hf);
uint64_t tx_expected_block_height = get_block_height(blk_head) + 1;
uint64_t tx_version = currency::get_tx_version(tx_expected_block_height, hf);
boost::multiprecision::int128_t change = get_sources_total_amount(sources);
change -= spending_amount;
if (change < 0)

View file

@ -5,6 +5,7 @@
#pragma once
#include "currency_core/currency_core.h"
#include "currency_core/currency_format_utils.h"
#include "currency_core/miner.h"
#include "wallet/wallet2.h"
#include "test_core_time.h"