From cf6f6a026f781ea58eed448d66da87047150a459 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Thu, 4 May 2017 08:52:52 +0800 Subject: [PATCH] search_mempool and json_mempool refactored --- src/page.h | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/page.h b/src/page.h index 707c549..491b2c0 100644 --- a/src/page.h +++ b/src/page.h @@ -1198,8 +1198,9 @@ namespace xmreg cerr << "Cant get tx in blockchain: " << tx_hash << ". \n Check mempool now" << endl; - vector> found_txs - = search_mempool(tx_hash); + vector> found_txs; + + search_mempool(tx_hash, found_txs); if (!found_txs.empty()) { @@ -1518,8 +1519,9 @@ namespace xmreg cerr << "Cant get tx in blockchain: " << tx_hash << ". \n Check mempool now" << endl; - vector> found_txs - = search_mempool(tx_hash); + vector> found_txs; + + search_mempool(tx_hash, found_txs); if (!found_txs.empty()) { @@ -2823,8 +2825,9 @@ namespace xmreg }; // check in mempool already contains tx to be submited - vector> found_mempool_txs - = search_mempool(txd.hash); + vector> found_mempool_txs; + + search_mempool(txd.hash, found_mempool_txs); if (!found_mempool_txs.empty()) { @@ -3809,8 +3812,9 @@ namespace xmreg { // check in mempool if tx_hash not found in the // blockchain - vector> found_txs - = search_mempool(tx_hash_pod); + vector> found_txs; + + search_mempool(tx_hash_pod, found_txs); if (!found_txs.empty()) { @@ -4280,7 +4284,19 @@ namespace xmreg uint64_t height = core_storage->get_current_blockchain_height(); - vector> mempool_data = search_mempool(); + vector> mempool_data; + + crypto::hash tx_hash_dummy = null_hash; + + if (!search_mempool(tx_hash_dummy, mempool_data)) + { + j_response["status"] = "error"; + j_response["message"] = fmt::format("Cant connect to the mempool"); + + return j_response; + } + + (void) tx_hash_dummy; // for each transaction in the memory pool for (const auto& a_pair: mempool_data) @@ -4606,8 +4622,9 @@ namespace xmreg cerr << "Cant get tx in blockchain: " << tx_hash << ". \n Check mempool now" << endl; - vector> found_txs - = search_mempool(tx_hash); + vector> found_txs; + + search_mempool(tx_hash, found_txs); if (!found_txs.empty()) { @@ -5227,22 +5244,21 @@ namespace xmreg } - vector> - search_mempool(crypto::hash tx_hash = null_hash) + bool + search_mempool(crypto::hash tx_hash, + vector>& found_txs) { // if tx_hash == null_hash then this method // will just return the vector containing all // txs in mempool - vector> found_txs; - // get txs in the mempool std::vector mempool_txs; if (!rpc.get_mempool(mempool_txs)) { cerr << "Getting mempool failed " << endl; - return found_txs; + return false; } // if dont have tx_blob member, construct tx @@ -5286,7 +5302,7 @@ namespace xmreg } // for (size_t i = 0; i < mempool_txs.size(); ++i) - return found_txs; + return true; } pair