From df57d2b2036b6b9d2842e504549c6aea6af0f404 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Fri, 2 Dec 2016 10:22:49 +0800 Subject: [PATCH] xmreg::make_tx_from_json started --- src/page.h | 29 +++++++++++++++++++++++++++-- src/rpccalls.h | 1 + src/tools.cpp | 20 ++++++++++++++++++++ src/tools.h | 3 +++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/page.h b/src/page.h index e067427..599c7f6 100644 --- a/src/page.h +++ b/src/page.h @@ -4016,9 +4016,34 @@ private: } else { - // @TODO make tx_info from json - // if dont have tx_blob member, construct tx_info + // if dont have tx_blob member, construct tx // from json obtained from the rpc call + + for (size_t i = 0; i < mempool_txs.size(); ++i) + { + // get transaction info of the tx in the mempool + tx_info _tx_info = mempool_txs.at(i); + + crypto::hash mem_tx_hash = null_hash; + + if (hex_to_pod(_tx_info.id_hash, mem_tx_hash)) + { + // @TODO need to make this tx from _tx_info.tx_json + transaction tx; + + if (!xmreg::make_tx_from_json(_tx_info.tx_json, tx)) + { + cerr << "Cant make tx from _tx_info.tx_json" << endl; + continue; + } + + if (tx_hash == mem_tx_hash) + { + found_txs.push_back(make_pair(_tx_info, tx)); + break; + } + } + } } return found_txs; diff --git a/src/rpccalls.h b/src/rpccalls.h index ac92807..82f6436 100644 --- a/src/rpccalls.h +++ b/src/rpccalls.h @@ -101,6 +101,7 @@ namespace xmreg return false; } + mempool_txs = res.transactions; return true; diff --git a/src/tools.cpp b/src/tools.cpp index 4685f1a..919afa3 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -1013,5 +1013,25 @@ get_real_output_for_key_image(const key_image& ki, return false; } + +bool +make_tx_from_json(const string& json_str, transaction& tx) +{ + + json j; + + try + { + j = json::parse(json_str); + } + catch (std::invalid_argument& e) + { + cerr << "make_tx_from_json: cant parse json string: " << e.what() << endl; + return false; + } + + return true; +} + } diff --git a/src/tools.h b/src/tools.h index ec95623..10e52ef 100644 --- a/src/tools.h +++ b/src/tools.h @@ -275,6 +275,9 @@ get_real_output_for_key_image(const key_image& ki, uint64_t output_idx, public_key output_pub_key); +bool +make_tx_from_json(const string& json_str, transaction& tx); + } #endif //XMREG01_TOOLS_H