forked from lthn/blockchain
reverted API to original due to universal implementation, adapted server side to new protocol, implemented one extra API
This commit is contained in:
parent
bf222f18fe
commit
4e0fa49748
12 changed files with 153 additions and 96 deletions
|
|
@ -70,6 +70,8 @@ using namespace currency;
|
|||
#endif
|
||||
#define BLOCK_POS_STRICT_SEQUENCE_LIMIT 20
|
||||
|
||||
#define BLOCKCHAIN_FIRST_BLOCK_TIMESTAMP 1557342384
|
||||
|
||||
|
||||
DISABLE_VS_WARNINGS(4267)
|
||||
|
||||
|
|
@ -2938,29 +2940,67 @@ bool blockchain_storage::find_blockchain_supplement(const std::list<crypto::hash
|
|||
|
||||
return true;
|
||||
}
|
||||
bool blockchain_storage::find_blockchain_supplement_fuzzy(const std::list<epee::pod_pair<uint64_t, crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp)const
|
||||
//------------------------------------------------------------------
|
||||
bool blockchain_storage::get_est_height_from_date(uint64_t date, uint64_t& res_h)const
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_read_lock);
|
||||
// if (!find_blockchain_supplement(qblock_ids, resp.start_height))
|
||||
// return false;
|
||||
//
|
||||
// resp.total_height = get_current_blockchain_size();
|
||||
// size_t count = 0;
|
||||
//
|
||||
// block_context_info* pprevinfo = nullptr;
|
||||
// size_t i = 0;
|
||||
// for (i = resp.start_height; i != m_db_blocks.size() && count < BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT; i++, count++)
|
||||
// {
|
||||
// resp.m_block_ids.push_back(block_context_info());
|
||||
//
|
||||
// if (pprevinfo)
|
||||
// pprevinfo->h = m_db_blocks[i]->bl.prev_id;
|
||||
// resp.m_block_ids.back().cumul_size = m_db_blocks[i]->block_cumulative_size;
|
||||
// pprevinfo = &resp.m_block_ids.back();
|
||||
// }
|
||||
// if (pprevinfo)
|
||||
// pprevinfo->h = get_block_hash(m_db_blocks[--i]->bl);
|
||||
#define GET_EST_HEIGHT_FROM_DATE_THRESHOLD 1440
|
||||
|
||||
if (date < BLOCKCHAIN_FIRST_BLOCK_TIMESTAMP)
|
||||
return false;
|
||||
|
||||
|
||||
uint64_t calculated_estimated_height = (date - BLOCKCHAIN_FIRST_BLOCK_TIMESTAMP) / DIFFICULTY_TOTAL_TARGET;
|
||||
|
||||
if (date > m_db_blocks[m_db_blocks.size() - 1]->bl.timestamp)
|
||||
{
|
||||
//that suspicious but also could be(in case someone just created wallet offline in
|
||||
//console and then got it synchronyzing and last block had a little timestamp shift)
|
||||
//let's just return 1 day behind for safety reasons.
|
||||
if (m_db_blocks.size() > 1440)
|
||||
{
|
||||
res_h = m_db_blocks.size() - 1440;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//likely impossible, but just in case
|
||||
res_h = 1;
|
||||
}
|
||||
|
||||
}
|
||||
if (calculated_estimated_height > m_db_blocks.size() - 1)
|
||||
calculated_estimated_height = m_db_blocks.size() - 1;
|
||||
|
||||
//goal is to get timestamp in window in between 1day+1hour and 1 hour before target(1 hour is just to be sure that
|
||||
//we didn't miss actual wallet start because of timestamp and difficulty fluctuations)
|
||||
uint64_t low_boundary = date - 90000; //1 day + 1 hour
|
||||
uint64_t aim = date - 46800;
|
||||
uint64_t high_boundary = date - 3600; //1 hour
|
||||
|
||||
uint64_t iteration_coun = 0;
|
||||
while (true)
|
||||
{
|
||||
iteration_coun++;
|
||||
uint64_t correction = 0;
|
||||
uint64_t ts = m_db_blocks[calculated_estimated_height]->bl.timestamp;
|
||||
if (ts > high_boundary)
|
||||
{
|
||||
//we moved too much forward
|
||||
calculated_estimated_height -= (ts - aim) / DIFFICULTY_TOTAL_TARGET;
|
||||
}
|
||||
else if (ts < low_boundary)
|
||||
{
|
||||
//we too much in past
|
||||
calculated_estimated_height += (aim - ts) / DIFFICULTY_TOTAL_TARGET;
|
||||
}
|
||||
else
|
||||
{
|
||||
res_h = calculated_estimated_height;
|
||||
break;
|
||||
}
|
||||
}
|
||||
LOG_PRINT_L0("[get_est_height_from_date] returned " << calculated_estimated_height << " with " << iteration_coun << " iterations");
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
|
|
@ -2983,11 +3023,13 @@ bool blockchain_storage::find_blockchain_supplement(const std::list<crypto::hash
|
|||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool blockchain_storage::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)const
|
||||
bool blockchain_storage::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)const
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_read_lock);
|
||||
if (!find_blockchain_supplement(qblock_ids, start_height))
|
||||
return false;
|
||||
if (minimum_height > start_height)
|
||||
start_height = minimum_height;
|
||||
|
||||
total_height = get_current_blockchain_size();
|
||||
size_t count = 0;
|
||||
|
|
|
|||
|
|
@ -252,11 +252,10 @@ namespace currency
|
|||
size_t get_total_transactions()const;
|
||||
bool get_outs(uint64_t amount, std::list<crypto::public_key>& pkeys)const;
|
||||
bool get_short_chain_history(std::list<crypto::hash>& ids)const;
|
||||
bool find_blockchain_supplement_fuzzy(const std::list<epee::pod_pair<uint64_t, crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp)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)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)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;
|
||||
bool handle_get_objects(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res)const;
|
||||
|
|
@ -422,7 +421,7 @@ namespace currency
|
|||
|
||||
template<class archive_t>
|
||||
void serialize(archive_t & ar, const unsigned int version);
|
||||
|
||||
bool get_est_height_from_date(uint64_t date, uint64_t& res_h)const;
|
||||
|
||||
|
||||
//debug functions
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ namespace currency
|
|||
}
|
||||
|
||||
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))
|
||||
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 = CORE_RPC_STATUS_FAILED;
|
||||
return false;
|
||||
|
|
@ -289,35 +289,6 @@ namespace currency
|
|||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_get_blocks_fuzzy_direct(const COMMAND_RPC_GET_BLOCKS_FUZZY_DIRECT::request& req, COMMAND_RPC_GET_BLOCKS_FUZZY_DIRECT::response& res, connection_context& cntx)
|
||||
{
|
||||
CHECK_CORE_READY();
|
||||
|
||||
if (req.block_ids.back() != m_core.get_blockchain_storage().get_block_id_by_height(0))
|
||||
{
|
||||
//genesis mismatch, return specific
|
||||
res.status = CORE_RPC_STATUS_GENESIS_MISMATCH;
|
||||
return true;
|
||||
}
|
||||
|
||||
blockchain_storage::blocks_direct_container bs;
|
||||
if (!m_core.get_blockchain_storage().find_blockchain_supplement2(req.block_ids, bs, res.current_height, res.start_height, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT))
|
||||
{
|
||||
res.status = CORE_RPC_STATUS_FAILED;
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto& b : bs)
|
||||
{
|
||||
res.blocks.resize(res.blocks.size() + 1);
|
||||
res.blocks.back().block_ptr = b.first;
|
||||
res.blocks.back().txs_ptr = std::move(b.second);
|
||||
}
|
||||
|
||||
res.status = CORE_RPC_STATUS_OK;
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res, connection_context& cntx)
|
||||
{
|
||||
CHECK_CORE_READY();
|
||||
|
|
@ -1292,6 +1263,17 @@ namespace currency
|
|||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_get_est_height_from_date(const COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::request& req, COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::response& res, connection_context& cntx)
|
||||
{
|
||||
bool r = m_core.get_blockchain_storage().get_est_height_from_date(req.timestamp, res.h);
|
||||
|
||||
if (r)
|
||||
res.status = CORE_RPC_STATUS_OK;
|
||||
else
|
||||
res.status = CORE_RPC_STATUS_NOT_FOUND;
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_alias_by_address(const COMMAND_RPC_GET_ALIASES_BY_ADDRESS::request& req, COMMAND_RPC_GET_ALIASES_BY_ADDRESS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx)
|
||||
{
|
||||
account_public_address addr = AUTO_VAL_INIT(addr);
|
||||
|
|
|
|||
|
|
@ -90,6 +90,8 @@ namespace currency
|
|||
bool on_get_main_block_details(const COMMAND_RPC_GET_BLOCK_DETAILS::request& req, COMMAND_RPC_GET_BLOCK_DETAILS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
|
||||
bool on_get_alt_block_details(const COMMAND_RPC_GET_BLOCK_DETAILS::request& req, COMMAND_RPC_GET_BLOCK_DETAILS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
|
||||
bool on_get_alt_blocks_details(const COMMAND_RPC_GET_ALT_BLOCKS_DETAILS::request& req, COMMAND_RPC_GET_ALT_BLOCKS_DETAILS::response& res, connection_context& cntx);
|
||||
bool on_get_est_height_from_date(const COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::request& req, COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::response& res, connection_context& cntx);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -135,6 +137,7 @@ namespace currency
|
|||
MAP_JON_RPC_WE("get_alias_details", on_get_alias_details, COMMAND_RPC_GET_ALIAS_DETAILS)
|
||||
MAP_JON_RPC_WE("get_alias_by_address", on_alias_by_address, COMMAND_RPC_GET_ALIASES_BY_ADDRESS)
|
||||
MAP_JON_RPC_WE("get_alias_reward", on_get_alias_reward, COMMAND_RPC_GET_ALIAS_REWARD)
|
||||
MAP_JON_RPC ("get_est_height_from_date", on_get_est_height_from_date, COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE)
|
||||
//block explorer api
|
||||
MAP_JON_RPC ("get_blocks_details", on_rpc_get_blocks_details, COMMAND_RPC_GET_BLOCKS_DETAILS)
|
||||
MAP_JON_RPC_WE("get_tx_details", on_get_tx_details, COMMAND_RPC_GET_TX_DETAILS)
|
||||
|
|
|
|||
|
|
@ -115,9 +115,11 @@ namespace currency
|
|||
|
||||
struct request
|
||||
{
|
||||
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(minimum_height)
|
||||
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(block_ids)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
|
@ -141,38 +143,6 @@ namespace currency
|
|||
typedef COMMAND_RPC_GET_BLOCKS_FAST_T<block_complete_entry> COMMAND_RPC_GET_BLOCKS_FAST;
|
||||
typedef COMMAND_RPC_GET_BLOCKS_FAST_T<block_direct_data_entry> COMMAND_RPC_GET_BLOCKS_DIRECT;
|
||||
|
||||
template<class t_block_complete_entry>
|
||||
struct COMMAND_RPC_GET_BLOCKS_FUZZY_FAST_T
|
||||
{
|
||||
|
||||
struct request
|
||||
{
|
||||
std::list<epee::pod_pair<uint64_t, 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_CONTAINER_POD_AS_BLOB(block_ids)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
std::list<t_block_complete_entry> blocks;
|
||||
uint64_t start_height;
|
||||
uint64_t current_height;
|
||||
std::string status;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(blocks)
|
||||
KV_SERIALIZE(start_height)
|
||||
KV_SERIALIZE(current_height)
|
||||
KV_SERIALIZE(status)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
typedef COMMAND_RPC_GET_BLOCKS_FUZZY_FAST_T<block_complete_entry> COMMAND_RPC_GET_BLOCKS_FUZZY_FAST;
|
||||
typedef COMMAND_RPC_GET_BLOCKS_FUZZY_FAST_T<block_direct_data_entry> COMMAND_RPC_GET_BLOCKS_FUZZY_DIRECT;
|
||||
|
||||
|
||||
//-----------------------------------------------
|
||||
struct COMMAND_RPC_GET_TRANSACTIONS
|
||||
{
|
||||
|
|
@ -199,6 +169,30 @@ namespace currency
|
|||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
//-----------------------------------------------
|
||||
struct COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE
|
||||
{
|
||||
struct request
|
||||
{
|
||||
uint64_t timestamp;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(timestamp)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
uint64_t h;
|
||||
std::string status;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(h)
|
||||
KV_SERIALIZE(status)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
//-----------------------------------------------
|
||||
struct COMMAND_RPC_GET_TX_POOL
|
||||
{
|
||||
|
|
|
|||
|
|
@ -50,6 +50,11 @@ namespace tools
|
|||
return r;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool default_http_core_proxy::call_COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE(const currency::COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::request& rqt, currency::COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::response& rsp)
|
||||
{
|
||||
return invoke_http_json_rpc_update_is_disconnect("get_est_height_from_date", rqt, rsp);
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool default_http_core_proxy::call_COMMAND_RPC_GET_INFO(const currency::COMMAND_RPC_GET_INFO::request& req, currency::COMMAND_RPC_GET_INFO::response& res)
|
||||
{
|
||||
return invoke_http_json_remote_command2_update_is_disconnect("/getinfo", req, res);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ namespace tools
|
|||
bool call_COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES(const currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& rqt, currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& rsp) override;
|
||||
bool call_COMMAND_RPC_GET_BLOCKS_FAST(const currency::COMMAND_RPC_GET_BLOCKS_FAST::request& rqt, currency::COMMAND_RPC_GET_BLOCKS_FAST::response& rsp) override;
|
||||
bool call_COMMAND_RPC_GET_BLOCKS_DIRECT(const currency::COMMAND_RPC_GET_BLOCKS_DIRECT::request& rqt, currency::COMMAND_RPC_GET_BLOCKS_DIRECT::response& rsp) override;
|
||||
bool call_COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE(const currency::COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::request& rqt, currency::COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::response& rsp) override;
|
||||
bool call_COMMAND_RPC_GET_INFO(const currency::COMMAND_RPC_GET_INFO::request& rqt, currency::COMMAND_RPC_GET_INFO::response& rsp) override;
|
||||
bool call_COMMAND_RPC_GET_TX_POOL(const currency::COMMAND_RPC_GET_TX_POOL::request& rqt, currency::COMMAND_RPC_GET_TX_POOL::response& rsp) override;
|
||||
bool call_COMMAND_RPC_GET_ALIASES_BY_ADDRESS(const currency::COMMAND_RPC_GET_ALIASES_BY_ADDRESS::request& rqt, currency::COMMAND_RPC_GET_ALIASES_BY_ADDRESS::response& rsp) override;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ namespace tools
|
|||
{
|
||||
return m_rpc.on_get_blocks_direct(rqt, rsp, m_cntxt_stub);
|
||||
}
|
||||
bool call_COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE(const currency::COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::request& rqt, currency::COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::response& rsp) override
|
||||
{
|
||||
return m_rpc.on_get_est_height_from_date(rqt, rsp, m_cntxt_stub);
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool call_COMMAND_RPC_GET_INFO(const currency::COMMAND_RPC_GET_INFO::request& req, currency::COMMAND_RPC_GET_INFO::response& res) override
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace tools
|
|||
virtual bool call_COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES(const currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& rqt, currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& rsp){ return false; }
|
||||
virtual bool call_COMMAND_RPC_GET_BLOCKS_FAST(const currency::COMMAND_RPC_GET_BLOCKS_FAST::request& rqt, currency::COMMAND_RPC_GET_BLOCKS_FAST::response& rsp){ return false; }
|
||||
virtual bool call_COMMAND_RPC_GET_BLOCKS_DIRECT(const currency::COMMAND_RPC_GET_BLOCKS_DIRECT::request& rqt, currency::COMMAND_RPC_GET_BLOCKS_DIRECT::response& rsp) { return false; }
|
||||
virtual bool call_COMMAND_RPC_GET_BLOCKS_FUZZY_DIRECT(const currency::COMMAND_RPC_GET_BLOCKS_FUZZY_DIRECT::request& rqt, currency::COMMAND_RPC_GET_BLOCKS_FUZZY_DIRECT::response& rsp) { return false; }
|
||||
virtual bool call_COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE(const currency::COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::request& rqt, currency::COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::response& rsp) { return false; }
|
||||
virtual bool call_COMMAND_RPC_GET_INFO(const currency::COMMAND_RPC_GET_INFO::request& rqt, currency::COMMAND_RPC_GET_INFO::response& rsp){ return false; }
|
||||
virtual bool call_COMMAND_RPC_GET_TX_POOL(const currency::COMMAND_RPC_GET_TX_POOL::request& rqt, currency::COMMAND_RPC_GET_TX_POOL::response& rsp){ return false; }
|
||||
virtual bool call_COMMAND_RPC_GET_ALIASES_BY_ADDRESS(const currency::COMMAND_RPC_GET_ALIASES_BY_ADDRESS::request& rqt, currency::COMMAND_RPC_GET_ALIASES_BY_ADDRESS::response& rsp){ return false; }
|
||||
|
|
|
|||
|
|
@ -1211,7 +1211,7 @@ bool wallet2::lookup_item_around(uint64_t i, std::pair<uint64_t, crypto::hash>&
|
|||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::get_short_chain_history(std::list<epee::pod_pair<uint64_t, crypto::hash> >& ids)
|
||||
void wallet2::get_short_chain_history(std::list<crypto::hash>& ids)
|
||||
{
|
||||
ids.clear();
|
||||
uint64_t i = 0;
|
||||
|
|
@ -1222,7 +1222,7 @@ void wallet2::get_short_chain_history(std::list<epee::pod_pair<uint64_t, crypto:
|
|||
//first put last 10
|
||||
for (auto it = m_last_10_blocks.rbegin(); it != m_last_10_blocks.rend(); it++)
|
||||
{
|
||||
ids.push_back({ it->first, it->second });
|
||||
ids.push_back(it->second);
|
||||
i = it->first;
|
||||
}
|
||||
|
||||
|
|
@ -1242,20 +1242,41 @@ void wallet2::get_short_chain_history(std::list<epee::pod_pair<uint64_t, crypto:
|
|||
//readjust item current_back_offset
|
||||
current_back_offset = sz - item.first;
|
||||
|
||||
ids.push_back({ item.first, item.second });
|
||||
ids.push_back(item.second);
|
||||
current_offset_distance *= 2;
|
||||
current_back_offset += current_offset_distance;
|
||||
}
|
||||
ids.push_back({ 0, m_genesis });
|
||||
ids.push_back(m_genesis);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::set_minimum_height(uint64_t h)
|
||||
{
|
||||
m_minimum_height = h;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
uint64_t wallet2::get_wallet_minimum_height()
|
||||
{
|
||||
if (m_minimum_height)
|
||||
return m_minimum_height;
|
||||
|
||||
currency::COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::request req = AUTO_VAL_INIT(req);
|
||||
currency::COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::response res = AUTO_VAL_INIT(res);
|
||||
req.timestamp = m_account.get_createtime();
|
||||
bool r = m_core_proxy->call_COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE(req, res);
|
||||
THROW_IF_FALSE_WALLET_EX(r, error::no_connection_to_daemon, "call_COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE");
|
||||
THROW_IF_FALSE_WALLET_EX(res.status == CORE_RPC_STATUS_OK, error::wallet_runtime_error, "FAILED TO CALL COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE");
|
||||
return res.h;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::pull_blocks(size_t& blocks_added, std::atomic<bool>& stop)
|
||||
{
|
||||
blocks_added = 0;
|
||||
currency::COMMAND_RPC_GET_BLOCKS_FUZZY_DIRECT::request req = AUTO_VAL_INIT(req);
|
||||
currency::COMMAND_RPC_GET_BLOCKS_FUZZY_DIRECT::response res = AUTO_VAL_INIT(res);
|
||||
currency::COMMAND_RPC_GET_BLOCKS_DIRECT::request req = AUTO_VAL_INIT(req);
|
||||
currency::COMMAND_RPC_GET_BLOCKS_DIRECT::response res = AUTO_VAL_INIT(res);
|
||||
|
||||
req.minimum_height = get_wallet_minimum_height();
|
||||
get_short_chain_history(req.block_ids);
|
||||
bool r = m_core_proxy->call_COMMAND_RPC_GET_BLOCKS_FUZZY_DIRECT(req, res);
|
||||
bool r = m_core_proxy->call_COMMAND_RPC_GET_BLOCKS_DIRECT(req, res);
|
||||
if (!r)
|
||||
throw error::no_connection_to_daemon(LOCATION_STR, "getblocks.bin");
|
||||
|
||||
|
|
@ -1353,7 +1374,7 @@ void wallet2::check_if_block_matched(uint64_t i, const crypto::hash& id, bool& b
|
|||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::handle_pulled_blocks(size_t& blocks_added, std::atomic<bool>& stop,
|
||||
currency::COMMAND_RPC_GET_BLOCKS_FUZZY_DIRECT::response& res)
|
||||
currency::COMMAND_RPC_GET_BLOCKS_DIRECT::response& res)
|
||||
{
|
||||
size_t current_index = res.start_height;
|
||||
|
||||
|
|
|
|||
|
|
@ -322,6 +322,7 @@ namespace tools
|
|||
m_do_rise_transfer(false),
|
||||
m_watch_only(false),
|
||||
m_last_pow_block_h(0),
|
||||
m_minimum_height(0),
|
||||
m_pos_mint_packing_size(WALLET_DEFAULT_POS_MINT_PACKING_SIZE)
|
||||
{};
|
||||
public:
|
||||
|
|
@ -336,6 +337,7 @@ namespace tools
|
|||
m_log_prefix("???"),
|
||||
m_watch_only(false),
|
||||
m_last_pow_block_h(0),
|
||||
m_minimum_height(0),
|
||||
m_pos_mint_packing_size(WALLET_DEFAULT_POS_MINT_PACKING_SIZE)
|
||||
{
|
||||
m_core_runtime_config = currency::get_default_core_runtime_config();
|
||||
|
|
@ -503,6 +505,7 @@ namespace tools
|
|||
|
||||
bool set_core_proxy(const std::shared_ptr<i_core_proxy>& proxy);
|
||||
void set_pos_mint_packing_size(uint64_t new_size);
|
||||
void set_minimum_height(uint64_t h);
|
||||
std::shared_ptr<i_core_proxy> get_core_proxy();
|
||||
uint64_t balance() const;
|
||||
uint64_t balance(uint64_t& unloked, uint64_t& awaiting_in, uint64_t& awaiting_out, uint64_t& mined) const;
|
||||
|
|
@ -895,9 +898,10 @@ private:
|
|||
void check_and_throw_if_self_directed_tx_with_payment_id_requested(const construct_tx_param& ctp);
|
||||
void push_new_block_id(const crypto::hash& id, uint64_t height);
|
||||
bool lookup_item_around(uint64_t i, std::pair<uint64_t, crypto::hash>& result);
|
||||
void get_short_chain_history(std::list<epee::pod_pair<uint64_t, crypto::hash> >& ids);
|
||||
void get_short_chain_history(std::list<crypto::hash>& ids);
|
||||
void check_if_block_matched(uint64_t i, const crypto::hash& id, bool& block_found, bool& block_matched, bool& full_reset_needed);
|
||||
uint64_t detach_from_block_ids(uint64_t height);
|
||||
uint64_t get_wallet_minimum_height();
|
||||
|
||||
currency::account_base m_account;
|
||||
bool m_watch_only;
|
||||
|
|
@ -911,6 +915,7 @@ private:
|
|||
std::map<uint64_t, crypto::hash> m_last_144_blocks_every_10; //1 day
|
||||
std::map<uint64_t, crypto::hash> m_last_144_blocks_every_100; //10 days
|
||||
std::map<uint64_t, crypto::hash> m_last_144_blocks_every_1000; //100 days
|
||||
uint64_t m_minimum_height;
|
||||
|
||||
std::atomic<uint64_t> m_local_bc_size; //temporary workaround
|
||||
std::atomic<uint64_t> m_last_bc_timestamp;
|
||||
|
|
|
|||
|
|
@ -841,6 +841,7 @@ std::string wallets_manager::generate_wallet(const std::wstring& path, const std
|
|||
try
|
||||
{
|
||||
w->generate(path, password);
|
||||
w->set_minimum_height(m_last_daemon_height);
|
||||
owr.seed = w->get_account().get_restore_braindata();
|
||||
}
|
||||
catch (const tools::error::file_exists&)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue