1
0
Fork 0
forked from lthn/blockchain

atomic: wallet improvements

This commit is contained in:
cryptozoidberg 2021-02-08 21:31:46 +01:00
parent 7b30823774
commit 52c5c1250f
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
6 changed files with 74 additions and 23 deletions

View file

@ -109,6 +109,20 @@ public: \
template<typename t_uint>
struct uint_mask_selector
{
template<t_uint mask>
inline static bool get_value_of_flag_by_mask(const t_uint& given_flags)
{
return given_flags&mask == 0 ? false : true;
}
};
#define KV_SERIALIZE_EPHEMERAL_BOOL_FROM_FLAG_N(var, mask, val_name) \
KV_SERIALIZE_EPHEMERAL_N(bool, uint_mask_selector<decltype(var)>::get_value_of_flag_by_mask<mask>, val_name)

View file

@ -994,7 +994,29 @@ namespace currency
}
}
//---------------------------------------------------------------
uint64_t get_tx_type(const transaction& tx)
void load_wallet_transfer_info_flags(tools::wallet_public::wallet_transfer_info& x)
{
x.is_service = currency::is_service_tx(x.tx);
x.is_mixing = currency::is_mixin_tx(x.tx);
x.is_mining = currency::is_coinbase(x.tx);
if (!x.is_mining)
x.fee = currency::get_tx_fee(x.tx);
else
x.fee = 0;
x.show_sender = currency::is_showing_sender_addres(x.tx);
tx_out htlc_out = AUTO_VAL_INIT(htlc_out);
txin_htlc htlc_in = AUTO_VAL_INIT(htlc_in);
x.tx_type = get_tx_type_ex(x.tx, htlc_out, htlc_in);
if(x.tx_type == GUI_TX_TYPE_HTLC_DEPOSIT && x.is_income == true)
{
//need to correct amount
x.amount = htlc_out.amount;
}
}
//---------------------------------------------------------------
uint64_t get_tx_type_ex(const transaction& tx, tx_out& htlc_out, txin_htlc& htlc_in)
{
if (is_coinbase(tx))
return GUI_TX_TYPE_COIN_BASE;
@ -1009,7 +1031,7 @@ namespace currency
else
return GUI_TX_TYPE_NEW_ALIAS;
}
// offers
tx_service_attachment a = AUTO_VAL_INIT(a);
if (get_type_in_variant_container(tx.attachment, a))
@ -1024,7 +1046,7 @@ namespace currency
return GUI_TX_TYPE_CANCEL_OFFER;
}
}
// escrow
tx_service_attachment tsa = AUTO_VAL_INIT(tsa);
if (bc_services::get_first_service_attachment_by_id(tx, BC_ESCROW_SERVICE_ID, BC_ESCROW_SERVICE_INSTRUCTION_RELEASE_TEMPLATES, tsa))
@ -1040,9 +1062,31 @@ namespace currency
if (bc_services::get_first_service_attachment_by_id(tx, BC_ESCROW_SERVICE_ID, BC_ESCROW_SERVICE_INSTRUCTION_CANCEL_PROPOSAL, tsa))
return GUI_TX_TYPE_ESCROW_CANCEL_PROPOSAL;
for (auto o : tx.vout)
{
if (o.target.type() == typeid(txout_htlc))
{
htlc_out = o;
return GUI_TX_TYPE_HTLC_DEPOSIT;
}
}
if (get_type_in_variant_container(tx.vin, htlc_in))
{
return GUI_TX_TYPE_HTLC_REDEEM;
}
return GUI_TX_TYPE_NORMAL;
}
//---------------------------------------------------------------
uint64_t get_tx_type(const transaction& tx)
{
tx_out htlc_out = AUTO_VAL_INIT(htlc_out);
txin_htlc htlc_in = AUTO_VAL_INIT(htlc_in);
return get_tx_type_ex(tx, htlc_out, htlc_in);
}
//---------------------------------------------------------------
size_t get_multisig_out_index(const std::vector<tx_out>& outs)
{
size_t n = 0;

View file

@ -28,6 +28,7 @@
#include "currency_format_utils_blocks.h"
#include "currency_format_utils_transactions.h"
#include "core_runtime_config.h"
#include "wallet/wallet_public_structs_defs.h"
// ------ get_tx_type_definition -------------
@ -44,6 +45,8 @@
#define GUI_TX_TYPE_ESCROW_RELEASE_BURN 10
#define GUI_TX_TYPE_ESCROW_CANCEL_PROPOSAL 11
#define GUI_TX_TYPE_ESCROW_RELEASE_CANCEL 12
#define GUI_TX_TYPE_HTLC_DEPOSIT 13
#define GUI_TX_TYPE_HTLC_REDEEM 14
@ -285,7 +288,9 @@ namespace currency
bool decrypt_payload_items(bool is_income, const transaction& tx, const account_keys& acc_keys, std::vector<payload_items_v>& decrypted_items);
void encrypt_attachments(transaction& tx, const account_keys& sender_keys, const account_public_address& destination_addr, const keypair& tx_random_key);
bool is_derivation_used_to_encrypt(const transaction& tx, const crypto::key_derivation& derivation);
void load_wallet_transfer_info_flags(tools::wallet_public::wallet_transfer_info& x);
uint64_t get_tx_type(const transaction& tx);
uint64_t get_tx_type_ex(const transaction& tx, tx_out& htlc_out, txin_htlc& htlc_in);
size_t get_multisig_out_index(const std::vector<tx_out>& outs);
size_t get_multisig_in_index(const std::vector<txin_v>& inputs);

View file

@ -1215,13 +1215,9 @@ void wallet2::prepare_wti(wallet_public::wallet_transfer_info& wti, uint64_t hei
fill_transfer_details(tx, td, wti.td);
wti.unlock_time = get_max_unlock_time_from_receive_indices(tx, td);
wti.timestamp = timestamp;
wti.fee = currency::is_coinbase(tx) ? 0:currency::get_tx_fee(tx);
wti.tx_blob_size = static_cast<uint32_t>(currency::get_object_blobsize(wti.tx));
wti.tx_hash = currency::get_transaction_hash(tx);
wti.is_service = currency::is_service_tx(tx);
wti.is_mixing = currency::is_mixin_tx(tx);
wti.is_mining = currency::is_coinbase(tx);
wti.tx_type = get_tx_type(tx);
load_wallet_transfer_info_flags(wti);
bc_services::extract_market_instructions(wti.srv_attachments, tx.attachment);
// escrow transactions, which are built with TX_FLAG_SIGNATURE_MODE_SEPARATE flag actually encrypt attachments
@ -3090,10 +3086,11 @@ void wallet2::get_recent_transfers_history(std::vector<wallet_public::wallet_tra
{
if (exclude_mining_txs)
{
if(it->is_mining)
if(is_mixin_tx(it->tx))
continue;
}
trs.push_back(*it);
load_wallet_transfer_info_flags(trs.back());
last_item_index = it - m_transfer_history.rbegin();
if (trs.size() >= count)
@ -4410,6 +4407,7 @@ void wallet2::mark_transfers_as_spent(const std::vector<uint64_t>& selected_tran
bool wallet2::extract_offers_from_transfer_entry(size_t i, std::unordered_map<crypto::hash, bc_services::offer_details_ex>& offers_local)
{
//TODO: this code supports only one market(offer) instruction per transaction
load_wallet_transfer_info_flags(m_transfer_history[i]);
switch (m_transfer_history[i].tx_type)
{
case GUI_TX_TYPE_PUSH_OFFER:

View file

@ -1119,20 +1119,6 @@ namespace boost
a & x.selected_indicies;
a & x.srv_attachments;
a & x.unlock_time;
//do not store this items in the file since it's quite easy to restore it from original tx
if (Archive::is_loading::value)
{
x.is_service = currency::is_service_tx(x.tx);
x.is_mixing = currency::is_mixin_tx(x.tx);
x.is_mining = currency::is_coinbase(x.tx);
if (!x.is_mining)
x.fee = currency::get_tx_fee(x.tx);
else
x.fee = 0;
x.show_sender = currency::is_showing_sender_addres(x.tx);
x.tx_type = get_tx_type(x.tx);
}
}
template <class Archive>

View file

@ -84,6 +84,9 @@ namespace wallet_public
};
#define WALLET_TRANSFER_INFO_FLAGS_HTLC_DEPOSIT static_cast<uint16_t>(1 << 0)
struct wallet_transfer_info
{
uint64_t amount;
@ -106,6 +109,7 @@ namespace wallet_public
uint64_t fee;
bool show_sender;
std::vector<escrow_contract_details> contract;
uint16_t extra_flags;
//not included in kv serialization map
currency::transaction tx;