From 52c5c1250f36aede4139bbab0338b923b1006915 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 8 Feb 2021 21:31:46 +0100 Subject: [PATCH] atomic: wallet improvements --- .../serialization/keyvalue_serialization.h | 14 ++++++ src/currency_core/currency_format_utils.cpp | 50 +++++++++++++++++-- src/currency_core/currency_format_utils.h | 5 ++ src/wallet/wallet2.cpp | 10 ++-- src/wallet/wallet2.h | 14 ------ src/wallet/wallet_public_structs_defs.h | 4 ++ 6 files changed, 74 insertions(+), 23 deletions(-) diff --git a/contrib/epee/include/serialization/keyvalue_serialization.h b/contrib/epee/include/serialization/keyvalue_serialization.h index 88605b78..31a4fb8b 100644 --- a/contrib/epee/include/serialization/keyvalue_serialization.h +++ b/contrib/epee/include/serialization/keyvalue_serialization.h @@ -109,6 +109,20 @@ public: \ + template + struct uint_mask_selector + { + template + 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::get_value_of_flag_by_mask, val_name) + diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index a14bcdcd..bda19214 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -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& outs) { size_t n = 0; diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 0c8ba27a..1d8b6b8d 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -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& 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& outs); size_t get_multisig_in_index(const std::vector& inputs); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 95348f24..7727d3e5 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -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(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::vectoris_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& selected_tran bool wallet2::extract_offers_from_transfer_entry(size_t i, std::unordered_map& 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: diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 21a2e43b..f70f16ba 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -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 diff --git a/src/wallet/wallet_public_structs_defs.h b/src/wallet/wallet_public_structs_defs.h index 55498c7b..60ae06be 100644 --- a/src/wallet/wallet_public_structs_defs.h +++ b/src/wallet/wallet_public_structs_defs.h @@ -84,6 +84,9 @@ namespace wallet_public }; +#define WALLET_TRANSFER_INFO_FLAGS_HTLC_DEPOSIT static_cast(1 << 0) + + struct wallet_transfer_info { uint64_t amount; @@ -106,6 +109,7 @@ namespace wallet_public uint64_t fee; bool show_sender; std::vector contract; + uint16_t extra_flags; //not included in kv serialization map currency::transaction tx;