diff --git a/src/currency_core/basic_kv_structs.h b/src/currency_core/basic_kv_structs.h new file mode 100644 index 00000000..1ff520c6 --- /dev/null +++ b/src/currency_core/basic_kv_structs.h @@ -0,0 +1,27 @@ +// Copyright (c) 2014-2018 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once + +#include "warnings.h" + +PUSH_VS_WARNINGS +DISABLE_VS_WARNINGS(4100) +DISABLE_VS_WARNINGS(4503) +#include "serialization/keyvalue_serialization.h" +#include "storages/portable_storage_template_helper.h" +POP_VS_WARNINGS + +namespace currency +{ + template + struct struct_with_one_t_type + { + t_type v; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(v) + END_KV_SERIALIZE_MAP() + }; +} diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index b196fbee..e59a8f9d 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -3093,7 +3093,7 @@ bool blockchain_storage::get_est_height_from_date(uint64_t date, uint64_t& res_h return true; } //------------------------------------------------------------------ -bool blockchain_storage::find_blockchain_supplement(const std::list& qblock_ids, std::list > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count, uint64_t minimum_height)const +bool blockchain_storage::find_blockchain_supplement(const std::list& qblock_ids, std::list > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count, uint64_t minimum_height, bool need_global_indexes)const { CRITICAL_REGION_LOCAL(m_read_lock); blocks_direct_container blocks_direct; diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index 48352edf..73c9af2b 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -254,7 +254,7 @@ namespace currency bool get_short_chain_history(std::list& ids)const; bool find_blockchain_supplement(const std::list& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp)const; bool find_blockchain_supplement(const std::list& qblock_ids, uint64_t& starter_offset)const; - bool find_blockchain_supplement(const std::list& qblock_ids, std::list > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count, uint64_t minimum_height = 0)const; + bool find_blockchain_supplement(const std::list& qblock_ids, std::list > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count, uint64_t minimum_height = 0, bool need_global_indexes = false)const; bool find_blockchain_supplement(const std::list& qblock_ids, blocks_direct_container& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count, uint64_t minimum_height = 0)const; //bool find_blockchain_supplement(const std::list& qblock_ids, std::list > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count)const; bool handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NOTIFY_RESPONSE_GET_OBJECTS::request& rsp)const; diff --git a/src/currency_protocol/currency_protocol_defs.h b/src/currency_protocol/currency_protocol_defs.h index 73b85e17..0bb974e0 100644 --- a/src/currency_protocol/currency_protocol_defs.h +++ b/src/currency_protocol/currency_protocol_defs.h @@ -13,6 +13,7 @@ #include "currency_core/connection_context.h" #include "currency_core/blockchain_storage_basic.h" #include "currency_protocol/blobdatatype.h" +#include "currency_core/basic_kv_structs.h" namespace currency { @@ -20,7 +21,7 @@ namespace currency #define BC_COMMANDS_POOL_BASE 2000 - + /************************************************************************/ /* */ /************************************************************************/ @@ -28,9 +29,12 @@ namespace currency { blobdata block; std::list txs; + std::vector > > tx_global_outs; + BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(block) KV_SERIALIZE(txs) + KV_SERIALIZE(tx_global_outs) END_KV_SERIALIZE_MAP() }; diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index a527a484..ae353bc2 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -314,20 +314,31 @@ namespace currency return true; } - std::list > > bs; - if(!m_core.get_blockchain_storage().find_blockchain_supplement(req.block_ids, bs, res.current_height, res.start_height, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT, req.minimum_height)) + blockchain_storage::blocks_direct_container bs; + if (!m_core.get_blockchain_storage().find_blockchain_supplement(req.block_ids, bs, res.current_height, res.start_height, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT, req.minimum_height)) { res.status = API_RETURN_CODE_FAIL; return false; } - BOOST_FOREACH(auto& b, bs) + for (auto& b : bs) { res.blocks.resize(res.blocks.size()+1); - res.blocks.back().block = block_to_blob(b.first); + res.blocks.back().block = block_to_blob(b.first->bl); + if (req.need_global_indexes) + { + res.blocks.back().tx_global_outs.resize(b.second.size()); + } + size_t i = 0; + BOOST_FOREACH(auto& t, b.second) { - res.blocks.back().txs.push_back(tx_to_blob(t)); + res.blocks.back().txs.push_back(tx_to_blob(t->tx)); + if (req.need_global_indexes) + { + res.blocks.back().tx_global_outs[i].v = t->m_global_output_indexes; + } + i++; } } diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 1a0044b5..c2e22bf6 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -109,10 +109,12 @@ namespace currency struct request { + bool need_global_indexes; uint64_t minimum_height; std::list block_ids; //*first 10 blocks id goes sequential, next goes in pow(2,n) offset, like 2, 4, 8, 16, 32, 64 and so on, and the last one is always genesis block */ BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(need_global_indexes) KV_SERIALIZE(minimum_height) KV_SERIALIZE_CONTAINER_POD_AS_BLOB(block_ids) END_KV_SERIALIZE_MAP() diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index 7320b3ed..b46c5ad5 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -19,8 +19,10 @@ DISABLE_VS_WARNINGS(4503) #include "rpc/core_rpc_server_commands_defs.h" #include "wallet/wallet_public_structs_defs.h" #include "currency_core/offers_services_helpers.h" +#include "currency_core/basic_kv_structs.h" #include "currency_core/basic_api_response_codes.h" #include "common/error_codes.h" + POP_VS_WARNINGS //#endif @@ -769,16 +771,6 @@ public: END_KV_SERIALIZE_MAP() }; - template - struct struct_with_one_t_type - { - t_type v; - - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(v) - END_KV_SERIALIZE_MAP() - }; - #define API_MAX_ALIASES_COUNT 10000 struct i_view diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 93070875..687839e0 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -365,6 +365,7 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t pwallet_info->m_block_height = height; pwallet_info->m_block_timestamp = b.timestamp; +#ifndef MOBILE_WALLET_BUILD //good news - got money! take care about it //usually we have only one transfer for user in transaction currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request req = AUTO_VAL_INIT(req); @@ -377,6 +378,7 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t THROW_IF_TRUE_WALLET_EX(res.o_indexes.size() != tx.vout.size(), error::wallet_internal_error, "transactions outputs size=" + std::to_string(tx.vout.size()) + " not match with COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES response size=" + std::to_string(res.o_indexes.size())); +#endif for (size_t i_in_outs = 0; i_in_outs != outs.size(); i_in_outs++) { @@ -455,7 +457,12 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t td.m_ptx_wallet_info = pwallet_info; td.m_internal_output_index = o; td.m_key_image = ki; +#ifdef MOBILE_WALLET_BUILD + td.m_global_output_index = WALLET_GLOBAL_OUTPUT_INDEX_UNDEFINED; +#else td.m_global_output_index = res.o_indexes[o]; +#endif + if (coin_base_tx) { //last out in coinbase tx supposed to be change from coinstake diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index c3e893d1..e02f7138 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -48,7 +48,15 @@ #define WALLET_DEFAULT_POS_MINT_PACKING_SIZE 100 +#define WALLET_TRANSFER_DETAIL_FLAG_SPENT uint32_t(1 << 0) +#define WALLET_TRANSFER_DETAIL_FLAG_BLOCKED uint32_t(1 << 1) +#define WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION uint32_t(1 << 2) +#define WALLET_TRANSFER_DETAIL_FLAG_MINED_TRANSFER uint32_t(1 << 3) +#define WALLET_TRANSFER_DETAIL_FLAG_COLD_SIG_RESERVATION uint32_t(1 << 4) // transfer is reserved for cold-signing (unsigned tx was created and passed for signing) + + const uint64_t WALLET_MINIMUM_HEIGHT_UNSET_CONST = std::numeric_limits::max(); +const uint64_t WALLET_GLOBAL_OUTPUT_INDEX_UNDEFINED = std::numeric_limits::max(); #undef LOG_DEFAULT_CHANNEL #define LOG_DEFAULT_CHANNEL "wallet" @@ -346,11 +354,6 @@ namespace tools m_core_runtime_config = currency::get_default_core_runtime_config(); }; -#define WALLET_TRANSFER_DETAIL_FLAG_SPENT uint32_t(1 << 0) -#define WALLET_TRANSFER_DETAIL_FLAG_BLOCKED uint32_t(1 << 1) -#define WALLET_TRANSFER_DETAIL_FLAG_ESCROW_PROPOSAL_RESERVATION uint32_t(1 << 2) -#define WALLET_TRANSFER_DETAIL_FLAG_MINED_TRANSFER uint32_t(1 << 3) -#define WALLET_TRANSFER_DETAIL_FLAG_COLD_SIG_RESERVATION uint32_t(1 << 4) // transfer is reserved for cold-signing (unsigned tx was created and passed for signing) static std::string transfer_flags_to_str(uint32_t flags); static std::string transform_tx_to_str(const currency::transaction& tx);