54 std::vector<std::pair<std::pair<blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, blobdata> > > >
blocks;
59 res.error_details =
"core::find_blockchain_supplement() returned false";
76 res.output_indices.clear();
78 res.error_details =
"failed retrieving a requested block";
85 res.output_indices.clear();
87 res.error_details =
"incorrect number of transactions retrieved for block";
99 res.error_details =
"core::get_tx_outputs_gindexs() returned false";
102 indices.push_back(std::move(tx_indices));
107 for (
const auto& blob : it->second)
113 res.output_indices.clear();
115 res.error_details =
"failed retrieving a requested transaction";
120 if (!m_core.get_tx_outputs_gindexs(*hash_it, tx_indices))
123 res.error_details =
"core::get_tx_outputs_gindexs() returned false";
127 indices.push_back(std::move(tx_indices));
156 std::vector<cryptonote::transaction> found_txs_vec;
157 std::vector<crypto::hash> missed_vec;
159 bool r = m_core.get_transactions(req.tx_hashes, found_txs_vec, missed_vec);
165 res.error_details =
"core::get_transactions() returned false (exception caught there)";
169 size_t num_found = found_txs_vec.size();
171 std::vector<uint64_t> heights(num_found);
172 std::vector<bool> in_pool(num_found,
false);
173 std::vector<crypto::hash> found_hashes(num_found);
175 for (
size_t i=0; i < num_found; i++)
178 heights[i] = m_core.get_blockchain_storage().get_db().get_tx_block_height(found_hashes[i]);
182 if (!missed_vec.empty())
184 std::vector<cryptonote::transaction> pool_txs;
186 m_core.get_pool_transactions(pool_txs);
188 for (
const auto& tx : pool_txs)
192 auto itr = std::find(missed_vec.begin(), missed_vec.end(), h);
194 if (itr != missed_vec.end())
196 found_hashes.push_back(h);
197 found_txs_vec.push_back(tx);
198 heights.push_back(std::numeric_limits<uint64_t>::max());
199 in_pool.push_back(
true);
200 missed_vec.erase(itr);
205 for (
size_t i=0; i < found_hashes.size(); i++)
208 info.height = heights[i];
209 info.in_pool = in_pool[i];
210 info.transaction = std::move(found_txs_vec[i]);
212 res.txs.emplace(found_hashes[i], std::move(
info));
215 res.missed_hashes = std::move(missed_vec);
221 res.spent_status.resize(req.key_images.size(), KeyImagesSpent::STATUS::UNSPENT);
223 std::vector<bool> chain_spent_status;
224 std::vector<bool> pool_spent_status;
226 m_core.are_key_images_spent(req.key_images, chain_spent_status);
227 m_core.are_key_images_spent_in_pool(req.key_images, pool_spent_status);
229 if ((chain_spent_status.size() != req.key_images.size()) || (pool_spent_status.size() != req.key_images.size()))
232 res.error_details =
"tx_pool::have_key_images_as_spent() gave vectors of wrong size(s).";
236 for(
size_t i=0; i < req.key_images.size(); i++)
238 if ( chain_spent_status[i] )
240 res.spent_status[i] = KeyImagesSpent::STATUS::SPENT_IN_BLOCKCHAIN;
242 else if ( pool_spent_status[i] )
244 res.spent_status[i] = KeyImagesSpent::STATUS::SPENT_IN_POOL;
450 res.info.height = m_core.get_current_blockchain_height();
452 res.info.target_height = m_core.get_target_blockchain_height();
454 if (
res.info.height >
res.info.target_height)
456 res.info.target_height =
res.info.height;
459 auto& chain = m_core.get_blockchain_storage();
461 res.info.wide_difficulty = chain.get_difficulty_for_next_block();
462 res.info.difficulty = (
res.info.wide_difficulty & 0xffffffffffffffff).convert_to<uint64_t>();
464 res.info.target = chain.get_difficulty_target();
466 res.info.tx_count = chain.get_total_transactions() -
res.info.height;
468 res.info.tx_pool_size = m_core.get_pool_transactions_count();
470 res.info.alt_blocks_count = chain.get_alternative_blocks_count();
472 uint64_t total_conn = m_p2p.get_public_connections_count();
473 res.info.outgoing_connections_count = m_p2p.get_public_outgoing_connections_count();
474 res.info.incoming_connections_count = total_conn -
res.info.outgoing_connections_count;
476 res.info.white_peerlist_size = m_p2p.get_public_white_peers_count();
478 res.info.grey_peerlist_size = m_p2p.get_public_gray_peers_count();
480 res.info.mainnet = m_core.get_nettype() ==
MAINNET;
481 res.info.testnet = m_core.get_nettype() ==
TESTNET;
482 res.info.stagenet = m_core.get_nettype() ==
STAGENET;
483 res.info.wide_cumulative_difficulty = m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(
res.info.height - 1);
484 res.info.cumulative_difficulty = (
res.info.wide_cumulative_difficulty & 0xffffffffffffffff).convert_to<uint64_t>();
485 res.info.block_size_limit =
res.info.block_weight_limit = m_core.get_blockchain_storage().get_current_cumulative_block_weight_limit();
486 res.info.block_size_median =
res.info.block_weight_median = m_core.get_blockchain_storage().get_current_cumulative_block_weight_median();
487 res.info.start_time = (
uint64_t)m_core.get_start_time();
491 res.error_details =
"";
724 std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t> > histogram;
727 histogram = m_core.get_blockchain_storage().get_output_histogram(req.amounts, req.unlocked, req.recent_cutoff);
729 catch (
const std::exception &e)
732 res.error_details = e.what();
736 res.histogram.clear();
737 res.histogram.reserve(histogram.size());
738 for (
const auto &i: histogram)
740 if (std::get<0>(i.second) >= req.min_count && (std::get<0>(i.second) <= req.max_count || req.max_count == 0))
741 res.histogram.emplace_back(
output_amount_count{i.first, std::get<0>(i.second), std::get<1>(i.second), std::get<2>(i.second)});
798 res.distributions.reserve(req.amounts.size());
800 const uint64_t req_to_height = req.to_height ? req.to_height : (m_core.get_current_blockchain_height() - 1);
801 for (std::uint64_t amount : req.amounts)
803 auto data =
rpc::RpcHandler::get_output_distribution([
this](
uint64_t amount,
uint64_t from,
uint64_t to,
uint64_t &start_height, std::vector<uint64_t> &distribution,
uint64_t &base) {
return m_core.get_output_distribution(amount, from, to, start_height, distribution, base); }, amount, req.from_height, req_to_height, [
this](
uint64_t height) {
return m_core.get_blockchain_storage().get_db().get_block_hash_from_height(
height); }, req.cumulative, m_core.get_current_blockchain_height());
806 res.distributions.clear();
808 res.error_details =
"Failed to get output distribution";
815 catch (
const std::exception& e)
817 res.distributions.clear();
819 res.error_details = e.what();
861 MDEBUG(
"Handling RPC request: " << request);
869 rapidjson::Value& req_json = req_full.
getMessage();
903 if (resp_message == NULL)
910 const std::string response = resp_full.
getJson();
914 MDEBUG(
"Returning RPC response: " << response);
918 catch (
const std::exception& e)