1
0
Fork 0
forked from lthn/blockchain

transfer refactoring - inital code

This commit is contained in:
cryptozoidberg 2022-09-17 22:52:26 +02:00
parent 1c76d0d325
commit ff0d32fa20
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
3 changed files with 19 additions and 63 deletions

View file

@ -76,8 +76,8 @@ namespace currency
//if this struct is present, then creating htlc out, expiration -> number of blocks that htlc proposal is active
struct destination_option_htlc_out
{
uint64_t expiration;
crypto::hash htlc_hash;
uint64_t expiration = 0;
crypto::hash htlc_hash = crypto::null_hash;
BEGIN_SERIALIZE_OBJECT()
FIELD(expiration)
@ -90,16 +90,17 @@ namespace currency
{
uint64_t amount; //money
std::list<account_public_address> addr; //destination address, in case of 1 address - txout_to_key, in case of more - txout_multisig
size_t minimum_sigs; //if txout_multisig: minimum signatures that are required to spend this output (minimum_sigs <= addr.size()) IF txout_to_key - not used
uint64_t amount_to_provide; //amount money that provided by initial creator of tx, used with partially created transactions
uint64_t unlock_time;
destination_option_htlc_out htlc_options; //htlc options
size_t minimum_sigs = 0; //if txout_multisig: minimum signatures that are required to spend this output (minimum_sigs <= addr.size()) IF txout_to_key - not used
uint64_t amount_to_provide = 0; //amount money that provided by initial creator of tx, used with partially created transactions
uint64_t unlock_time = 0;
destination_option_htlc_out htlc_options; //htlc options
crypto::hash asset_id = crypto::null_hash;
tx_destination_entry() : amount(0), minimum_sigs(0), amount_to_provide(0), unlock_time(0), htlc_options(destination_option_htlc_out()){}
tx_destination_entry(uint64_t a, const account_public_address& ad) : amount(a), addr(1, ad), minimum_sigs(0), amount_to_provide(0), unlock_time(0), htlc_options(destination_option_htlc_out()) {}
tx_destination_entry(uint64_t a, const account_public_address& ad, uint64_t ut) : amount(a), addr(1, ad), minimum_sigs(0), amount_to_provide(0), unlock_time(ut), htlc_options(destination_option_htlc_out()) {}
tx_destination_entry(uint64_t a, const std::list<account_public_address>& addr) : amount(a), addr(addr), minimum_sigs(addr.size()), amount_to_provide(0), unlock_time(0), htlc_options(destination_option_htlc_out()) {}
tx_destination_entry() = default;
tx_destination_entry(uint64_t a, const account_public_address& ad) : amount(a), addr(1, ad) {}
tx_destination_entry(uint64_t a, const account_public_address& ad, uint64_t ut) : amount(a), addr(1, ad), unlock_time(ut) {}
tx_destination_entry(uint64_t a, const std::list<account_public_address>& addr) : amount(a), addr(addr), minimum_sigs(addr.size()) {}
BEGIN_SERIALIZE_OBJECT()
FIELD(amount)

View file

@ -4894,9 +4894,10 @@ bool wallet2::prepare_tx_sources_htlc(crypto::hash htlc_tx_id, const std::string
}
//----------------------------------------------------------------------------------------------------------------
uint64_t wallet2::get_needed_money(uint64_t fee, const std::vector<currency::tx_destination_entry>& dsts)
std::unordered_map<crypto::hash, uint64_t>&& wallet2::get_needed_money(uint64_t fee, const std::vector<currency::tx_destination_entry>& dsts)
{
uint64_t needed_money = fee;
std::unordered_map<crypto::hash, uint64_t> amounts_map;
amounts_map[currency::null_hash] = fee;
BOOST_FOREACH(auto& dt, dsts)
{
THROW_IF_TRUE_WALLET_EX(0 == dt.amount, error::zero_destination);
@ -4904,10 +4905,10 @@ uint64_t wallet2::get_needed_money(uint64_t fee, const std::vector<currency::tx_
if (dt.amount_to_provide)
money_to_add = dt.amount_to_provide;
needed_money += money_to_add;
amounts_map[dt.asset_id] += money_to_add;
THROW_IF_TRUE_WALLET_EX(needed_money < money_to_add, error::tx_sum_overflow, dsts, fee);
}
return needed_money;
return amounts_map;
}
//----------------------------------------------------------------------------------------------------------------
void wallet2::set_disable_tor_relay(bool disable)
@ -5536,7 +5537,8 @@ void wallet2::prepare_tx_destinations(uint64_t needed_money,
void wallet2::prepare_transaction(construct_tx_param& ctp, currency::finalize_tx_param& ftp, const currency::transaction& tx_for_mode_separate /* = currency::transaction() */)
{
TIME_MEASURE_START_MS(get_needed_money_time);
uint64_t needed_money = get_needed_money(ctp.fee, ctp.dsts);
std::unordered_map<crypto::hash, uint64_t> needed_money_map;
uint64_t needed_money_map = get_needed_money(ctp.fee, ctp.dsts);
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");

View file

@ -295,53 +295,6 @@ namespace tools
bool perform_packing = false;
};
// struct currency::finalize_tx_param
// {
// uint64_t unlock_time;
// std::vector<currency::extra_v> extra;
// std::vector<currency::attachment_v> attachments;
// currency::account_public_address crypt_address;
// uint8_t tx_outs_attr;
// bool shuffle;
// uint8_t flags;
// crypto::hash multisig_id;
// std::vector<currency::tx_source_entry> sources;
// std::vector<uint64_t> selected_transfers;
// std::vector<currency::tx_destination_entry> prepared_destinations;
//
// crypto::public_key spend_pub_key; // only for validations
//
// BEGIN_SERIALIZE_OBJECT()
// FIELD(unlock_time)
// FIELD(extra)
// FIELD(attachments)
// FIELD(crypt_address)
// FIELD(tx_outs_attr)
// FIELD(shuffle)
// FIELD(flags)
// FIELD(multisig_id)
// FIELD(sources)
// FIELD(selected_transfers)
// FIELD(prepared_destinations)
// FIELD(spend_pub_key)
// END_SERIALIZE()
// };
//
// struct currency::finalized_tx
// {
// currency::transaction tx;
// crypto::secret_key one_time_key;
// currency::finalize_tx_param ftp;
// std::vector<serializable_pair<uint64_t, crypto::key_image>> outs_key_images; // pairs (out_index, key_image) for each change output
//
// BEGIN_SERIALIZE_OBJECT()
// FIELD(tx)
// FIELD(one_time_key)
// FIELD(ftp)
// FIELD(outs_key_images)
// END_SERIALIZE()
// };
class wallet2: public tools::tor::t_transport_state_notifier
{
@ -1002,7 +955,7 @@ private:
bool prepare_tx_sources_htlc(crypto::hash htlc_tx_id, const std::string& origin, std::vector<currency::tx_source_entry>& sources, uint64_t& found_money);
bool prepare_tx_sources_for_packing(uint64_t items_to_pack, size_t fake_outputs_count, std::vector<currency::tx_source_entry>& sources, std::vector<uint64_t>& selected_indicies, uint64_t& found_money);
void prefetch_global_indicies_if_needed(std::vector<uint64_t>& selected_indicies);
uint64_t get_needed_money(uint64_t fee, const std::vector<currency::tx_destination_entry>& dsts);
std::unordered_map<crypto::hash, uint64_t>&& get_needed_money(uint64_t fee, const std::vector<currency::tx_destination_entry>& dsts);
void prepare_tx_destinations(uint64_t needed_money,
uint64_t found_money,
detail::split_strategy_id_t destination_split_strategy_id,