From 57a874c771f2baf70a681afb0942152014a93dcd Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Tue, 11 Oct 2016 12:01:46 +0800 Subject: [PATCH] development of show_pushrawtx started --- main.cpp | 21 +++++++++++++++++++-- src/page.h | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index d5f4ad5..b257bf6 100644 --- a/main.cpp +++ b/main.cpp @@ -214,7 +214,7 @@ int main(int ac, const char* av[]) { return xmrblocks.show_rawtx(); }); - CROW_ROUTE(app, "/checkandpush").methods("POST"_method) + CROW_ROUTE(app, "/checkrawtx").methods("POST"_method) ([&](const crow::request& req) { map post_body = xmreg::parse_crow_post_data(req.body); @@ -227,9 +227,26 @@ int main(int ac, const char* av[]) { string raw_tx_data = post_body["rawtxdata"]; string action = post_body["action"]; - return xmrblocks.show_checkandpushtx(raw_tx_data, action); + return xmrblocks.show_checkrawtx(raw_tx_data, action); }); + CROW_ROUTE(app, "/pushrawtx").methods("POST"_method) + ([&](const crow::request& req) { + + map post_body = xmreg::parse_crow_post_data(req.body); + + if (post_body.count("rawtxdata") == 0 || post_body.count("action") == 0) + { + return string("Raw tx data or action not provided"); + } + + string raw_tx_data = post_body["rawtxdata"]; + string action = post_body["action"]; + + return xmrblocks.show_pushrawtx(raw_tx_data, action); + }); + + CROW_ROUTE(app, "/search").methods("GET"_method) ([&](const crow::request& req) { return xmrblocks.search(string(req.url_params.get("value"))); diff --git a/src/page.h b/src/page.h index 40b8fe1..2587bb7 100644 --- a/src/page.h +++ b/src/page.h @@ -1259,7 +1259,7 @@ namespace xmreg { } string - show_checkandpushtx(string raw_tx_data, string action) + show_checkrawtx(string raw_tx_data, string action) { // remove white characters boost::trim(raw_tx_data); @@ -1610,6 +1610,54 @@ namespace xmreg { return mstch::render(full_page, context, partials); } + string + show_pushrawtx(string raw_tx_data, string action) + { + // remove white characters + boost::trim(raw_tx_data); + boost::erase_all(raw_tx_data, "\r\n"); + boost::erase_all(raw_tx_data, "\n"); + + string decoded_raw_tx_data = epee::string_encoding::base64_decode(raw_tx_data); + + const size_t magiclen = strlen(SIGNED_TX_PREFIX); + + if (!strncmp(decoded_raw_tx_data.c_str(), SIGNED_TX_PREFIX, magiclen) != 0) + { + cout << "The data does not appear to be signed raw tx!" << endl; + return string( "The data does not appear to be signed raw tx!"); + } + + ::tools::wallet2::signed_tx_set signed_txs; + + bool r = serialization::parse_binary(std::string( + decoded_raw_tx_data.c_str() + magiclen, + decoded_raw_tx_data.size() - magiclen), + signed_txs); + + if (!r) + { + cerr << "deserialization of signed tx data NOT successful" << endl; + return string("deserialization of signed tx data NOT successful. " + "Maybe its not base64 encoded?"); + } + + std::vector ptx_vector = signed_txs.ptx; + + // actually commit the transactions + while (!ptx_vector.empty()) + { + auto & ptx = ptx_vector.back(); + //m_wallet->commit_tx(ptx); + //success_msg_writer(true) << tr("Money successfully sent, transaction: ") << get_transaction_hash(ptx.tx); + + // if no exception, remove element from vector + ptx_vector.pop_back(); + } + + return string{}; + } + string search(string search_text)