From a057da13f696647868a968e471a7e97b278ed5b4 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Fri, 16 Jun 2017 14:01:06 +0800 Subject: [PATCH] get_alt_blocks added --- src/page.h | 17 +++++++-------- src/rpccalls.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ src/rpccalls.h | 3 +++ 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/src/page.h b/src/page.h index c2ad44d..c2f62ed 100644 --- a/src/page.h +++ b/src/page.h @@ -425,18 +425,15 @@ namespace xmreg {"show_cache_times" , show_cache_times} }; - std::list atl_blks; + vector atl_blks; - if (core_storage->get_alternative_blocks(atl_blks)) - { - for (const block& alt_blk: atl_blks) - { - cout << "alt_blk tx: " << alt_blk.tx_hashes.size() << endl; - } - } - else + rpc.get_alt_blocks(atl_blks); + + cout << "atl_blks.size(): " << atl_blks.size() << endl; + + for (const block_complete_entry& alt_blk: atl_blks) { - cerr << "get_alternative_blocks(atl_blks) returned false" << endl; + cout << "alt_blk tx: " << alt_blk.txs.size() << endl; } context.emplace("txs", mstch::array()); // will keep tx to show diff --git a/src/rpccalls.cpp b/src/rpccalls.cpp index b366bb3..cd34f7c 100644 --- a/src/rpccalls.cpp +++ b/src/rpccalls.cpp @@ -208,6 +208,60 @@ rpccalls::get_network_info(COMMAND_RPC_GET_INFO::response& response) return true; } +bool +rpccalls::get_alt_blocks(vector& alt_blocks) +{ + bool r {false}; + + COMMAND_RPC_GET_ALT_BLOCKS::request req; + COMMAND_RPC_GET_ALT_BLOCKS::response resp; + + { + std::lock_guard guard(m_daemon_rpc_mutex); + + if (!connect_to_monero_deamon()) + { + cerr << "get_mempool: not connected to deamon" << endl; + return false; + } + + r = epee::net_utils::invoke_http_bin("/getaltblocks.bin", + req, resp, + m_http_client); + } + + string err; + + if (r) + { + if (resp.status == CORE_RPC_STATUS_BUSY) + { + err = "daemon is busy. Please try again later."; + } + else if (resp.status != CORE_RPC_STATUS_OK) + { + err = "daemon rpc failed. Please try again later."; + } + + if (!err.empty()) + { + cerr << "Error connecting to Monero deamon due to " + << err << endl; + return false; + } + } + else + { + cerr << "Error connecting to Monero deamon at " + << deamon_url << endl; + return false; + } + + alt_blocks = resp.blocks; + + return true; +} + bool rpccalls::get_dynamic_per_kb_fee_estimate( diff --git a/src/rpccalls.h b/src/rpccalls.h index f0aefbc..f33c01c 100644 --- a/src/rpccalls.h +++ b/src/rpccalls.h @@ -52,6 +52,9 @@ public: bool get_network_info(COMMAND_RPC_GET_INFO::response& info); + bool + get_alt_blocks(vector& alt_blocks); + bool get_dynamic_per_kb_fee_estimate( uint64_t grace_blocks,