From 16835ec144d38c58c6c306fb67a4c3f16c2516b4 Mon Sep 17 00:00:00 2001 From: stoffu Date: Fri, 6 Oct 2017 14:18:16 +0900 Subject: [PATCH] tx-pusher: support hex string of raw tx --- src/page.h | 117 ++++++++++++++++++++++----------------- src/templates/rawtx.html | 5 +- 2 files changed, 71 insertions(+), 51 deletions(-) diff --git a/src/page.h b/src/page.h index 4915dd2..2d8fb36 100644 --- a/src/page.h +++ b/src/page.h @@ -817,7 +817,7 @@ namespace xmreg { // get only first no_of_mempool_tx txs mempool_txs = MempoolStatus::get_mempool_txs(no_of_mempool_tx); - no_of_mempool_tx = std::min(no_of_mempool_tx, mempool_txs.size()); + no_of_mempool_tx = std::min(no_of_mempool_tx, mempool_txs.size()); } // total size of mempool in bytes @@ -945,7 +945,7 @@ namespace xmreg cerr << "rpc.get_alt_blocks(atl_blks_hashes) failed" << endl; } - context.emplace("no_alt_blocks", atl_blks_hashes.size()); + context.emplace("no_alt_blocks", (uint64_t)atl_blks_hashes.size()); for (const string& alt_blk_hash: atl_blks_hashes) { @@ -2774,84 +2774,101 @@ namespace xmreg { clean_post_data(raw_tx_data); - string decoded_raw_tx_data = epee::string_encoding::base64_decode(raw_tx_data); - - const size_t magiclen = strlen(SIGNED_TX_PREFIX); - - string data_prefix = xmreg::make_printable(decoded_raw_tx_data.substr(0, magiclen)); - // initalize page template context map mstch::map context { {"testnet" , testnet}, {"have_raw_tx" , true}, {"has_error" , false}, {"error_msg" , string {}}, - {"data_prefix" , data_prefix}, }; - context.emplace("txs", mstch::array{}); // add header and footer string full_page = template_file["pushrawtx"]; add_css_style(context); - if (strncmp(decoded_raw_tx_data.c_str(), SIGNED_TX_PREFIX, magiclen) != 0) + std::vector ptx_vector; + + // first try reading raw_tx_data as a raw hex string + std::string tx_blob; + cryptonote::transaction parsed_tx; + crypto::hash parsed_tx_hash, parsed_tx_prefixt_hash; + if (epee::string_tools::parse_hexstr_to_binbuff(raw_tx_data, tx_blob) && parse_and_validate_tx_from_blob(tx_blob, parsed_tx, parsed_tx_hash, parsed_tx_prefixt_hash)) + { + ptx_vector.push_back({}); + ptx_vector.back().tx = parsed_tx; + } + // if failed, treat raw_tx_data as base64 encoding of signed_monero_tx + else { - string error_msg = fmt::format("The data does not appear to be signed raw tx! Data prefix: {:s}", - data_prefix); + string decoded_raw_tx_data = epee::string_encoding::base64_decode(raw_tx_data); - context["has_error"] = true; - context["error_msg"] = error_msg; + const size_t magiclen = strlen(SIGNED_TX_PREFIX); - return mstch::render(full_page, context); - } + string data_prefix = xmreg::make_printable(decoded_raw_tx_data.substr(0, magiclen)); - if (this->enable_pusher == false) - { - string error_msg = fmt::format( - "Pushing disabled!\n " - "Run explorer with --enable-pusher flag to enable it."); + context["data_prefix"] = data_prefix; - context["has_error"] = true; - context["error_msg"] = error_msg; + if (strncmp(decoded_raw_tx_data.c_str(), SIGNED_TX_PREFIX, magiclen) != 0) + { + string error_msg = fmt::format("The data does not appear to be signed raw tx! Data prefix: {:s}", + data_prefix); - return mstch::render(full_page, context); - } + context["has_error"] = true; + context["error_msg"] = error_msg; - bool r {false}; + return mstch::render(full_page, context); + } - string s = decoded_raw_tx_data.substr(magiclen); + if (this->enable_pusher == false) + { + string error_msg = fmt::format( + "Pushing disabled!\n " + "Run explorer with --enable-pusher flag to enable it."); - ::tools::wallet2::signed_tx_set signed_txs; + context["has_error"] = true; + context["error_msg"] = error_msg; - try - { - std::istringstream iss(s); - boost::archive::portable_binary_iarchive ar(iss); - ar >> signed_txs; + return mstch::render(full_page, context); + } - r = true; - } - catch (...) - { - cerr << "Failed to parse signed tx data " << endl; - } + bool r {false}; + string s = decoded_raw_tx_data.substr(magiclen); - if (!r) - { - string error_msg = fmt::format("Deserialization of signed tx data NOT successful! " - "Maybe its not base64 encoded?"); + ::tools::wallet2::signed_tx_set signed_txs; - context["has_error"] = true; - context["error_msg"] = error_msg; + try + { + std::istringstream iss(s); + boost::archive::portable_binary_iarchive ar(iss); + ar >> signed_txs; - return mstch::render(full_page, context); + r = true; + } + catch (...) + { + cerr << "Failed to parse signed tx data " << endl; + } + + + if (!r) + { + string error_msg = fmt::format("Deserialization of signed tx data NOT successful! " + "Maybe its not base64 encoded?"); + + context["has_error"] = true; + context["error_msg"] = error_msg; + + return mstch::render(full_page, context); + } + + ptx_vector = signed_txs.ptx; } - mstch::array& txs = boost::get(context["txs"]); + context.emplace("txs", mstch::array{}); - std::vector ptx_vector = signed_txs.ptx; + mstch::array& txs = boost::get(context["txs"]); // actually commit the transactions while (!ptx_vector.empty()) @@ -4724,7 +4741,7 @@ namespace xmreg } // maxium five last blocks - no_of_last_blocks = std::min(no_of_last_blocks, 5ul); + no_of_last_blocks = std::min(no_of_last_blocks, 5ul); if (address_str.empty()) { diff --git a/src/templates/rawtx.html b/src/templates/rawtx.html index b7f65ed..47b2a98 100644 --- a/src/templates/rawtx.html +++ b/src/templates/rawtx.html @@ -8,13 +8,16 @@
- Paste base64 encoded, unsigned or signed transaction data here
+ Paste here either a hex string of raw transaction (the tx_blob response in the wallet RPC, or the raw_monero_tx file saved by the wallet CLI with --do-not-relay option specified),
+ or base64 encoded, unsigned or signed transaction data
(In Linux, can get base64 signed raw tx data: base64 signed_monero_tx | xclip -selection clipboard)
(In Windows, can get base64 signed raw tx data: certutil.exe -encode -f signed_monero_tx encoded.txt & type "encoded.txt" | clip)

Note: data is sent to the server, as the calculations are done on the server side
+ Note: "check" does not work for the hex string of raw transaction +