search_mempool and json_mempool refactored

master
moneroexamples 8 years ago
parent f5f9916b93
commit cf6f6a026f

@ -1198,8 +1198,9 @@ namespace xmreg
cerr << "Cant get tx in blockchain: " << tx_hash cerr << "Cant get tx in blockchain: " << tx_hash
<< ". \n Check mempool now" << endl; << ". \n Check mempool now" << endl;
vector<pair<tx_info, transaction>> found_txs vector<pair<tx_info, transaction>> found_txs;
= search_mempool(tx_hash);
search_mempool(tx_hash, found_txs);
if (!found_txs.empty()) if (!found_txs.empty())
{ {
@ -1518,8 +1519,9 @@ namespace xmreg
cerr << "Cant get tx in blockchain: " << tx_hash cerr << "Cant get tx in blockchain: " << tx_hash
<< ". \n Check mempool now" << endl; << ". \n Check mempool now" << endl;
vector<pair<tx_info, transaction>> found_txs vector<pair<tx_info, transaction>> found_txs;
= search_mempool(tx_hash);
search_mempool(tx_hash, found_txs);
if (!found_txs.empty()) if (!found_txs.empty())
{ {
@ -2823,8 +2825,9 @@ namespace xmreg
}; };
// check in mempool already contains tx to be submited // check in mempool already contains tx to be submited
vector<pair<tx_info, transaction>> found_mempool_txs vector<pair<tx_info, transaction>> found_mempool_txs;
= search_mempool(txd.hash);
search_mempool(txd.hash, found_mempool_txs);
if (!found_mempool_txs.empty()) if (!found_mempool_txs.empty())
{ {
@ -3809,8 +3812,9 @@ namespace xmreg
{ {
// check in mempool if tx_hash not found in the // check in mempool if tx_hash not found in the
// blockchain // blockchain
vector<pair<tx_info, transaction>> found_txs vector<pair<tx_info, transaction>> found_txs;
= search_mempool(tx_hash_pod);
search_mempool(tx_hash_pod, found_txs);
if (!found_txs.empty()) if (!found_txs.empty())
{ {
@ -4280,7 +4284,19 @@ namespace xmreg
uint64_t height = core_storage->get_current_blockchain_height(); uint64_t height = core_storage->get_current_blockchain_height();
vector<pair<tx_info, transaction>> mempool_data = search_mempool(); vector<pair<tx_info, transaction>> 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 each transaction in the memory pool
for (const auto& a_pair: mempool_data) for (const auto& a_pair: mempool_data)
@ -4606,8 +4622,9 @@ namespace xmreg
cerr << "Cant get tx in blockchain: " << tx_hash cerr << "Cant get tx in blockchain: " << tx_hash
<< ". \n Check mempool now" << endl; << ". \n Check mempool now" << endl;
vector<pair<tx_info, transaction>> found_txs vector<pair<tx_info, transaction>> found_txs;
= search_mempool(tx_hash);
search_mempool(tx_hash, found_txs);
if (!found_txs.empty()) if (!found_txs.empty())
{ {
@ -5227,22 +5244,21 @@ namespace xmreg
} }
vector<pair<tx_info, transaction>> bool
search_mempool(crypto::hash tx_hash = null_hash) search_mempool(crypto::hash tx_hash,
vector<pair<tx_info, transaction>>& found_txs)
{ {
// if tx_hash == null_hash then this method // if tx_hash == null_hash then this method
// will just return the vector containing all // will just return the vector containing all
// txs in mempool // txs in mempool
vector<pair<tx_info, transaction>> found_txs;
// get txs in the mempool // get txs in the mempool
std::vector<tx_info> mempool_txs; std::vector<tx_info> mempool_txs;
if (!rpc.get_mempool(mempool_txs)) if (!rpc.get_mempool(mempool_txs))
{ {
cerr << "Getting mempool failed " << endl; cerr << "Getting mempool failed " << endl;
return found_txs; return false;
} }
// if dont have tx_blob member, construct tx // if dont have tx_blob member, construct tx
@ -5286,7 +5302,7 @@ namespace xmreg
} // for (size_t i = 0; i < mempool_txs.size(); ++i) } // for (size_t i = 0; i < mempool_txs.size(); ++i)
return found_txs; return true;
} }
pair<string, string> pair<string, string>

Loading…
Cancel
Save