1
0
Fork 0
forked from lthn/blockchain

extended api for fetching blocks/txs, started work on implementing deferred fetching of global output indexes

This commit is contained in:
cryptozoidberg 2020-06-10 23:56:14 +02:00
parent aecd66c346
commit 267053964d
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
9 changed files with 69 additions and 23 deletions

View file

@ -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<typename t_type>
struct struct_with_one_t_type
{
t_type v;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(v)
END_KV_SERIALIZE_MAP()
};
}

View file

@ -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<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& 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<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& 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;

View file

@ -254,7 +254,7 @@ namespace currency
bool get_short_chain_history(std::list<crypto::hash>& ids)const;
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp)const;
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, uint64_t& starter_offset)const;
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& 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<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& 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<crypto::hash>& 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<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& 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;

View file

@ -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<blobdata> txs;
std::vector<struct_with_one_t_type<std::vector<uint64_t> > > tx_global_outs;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(block)
KV_SERIALIZE(txs)
KV_SERIALIZE(tx_global_outs)
END_KV_SERIALIZE_MAP()
};

View file

@ -314,20 +314,31 @@ namespace currency
return true;
}
std::list<std::pair<block, std::list<transaction> > > 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++;
}
}

View file

@ -109,10 +109,12 @@ namespace currency
struct request
{
bool need_global_indexes;
uint64_t minimum_height;
std::list<crypto::hash> 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()

View file

@ -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<typename t_type>
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

View file

@ -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

View file

@ -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<uint64_t>::max();
const uint64_t WALLET_GLOBAL_OUTPUT_INDEX_UNDEFINED = std::numeric_limits<uint64_t>::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);