development of show_pushrawtx started

master
moneroexamples 8 years ago
parent ec77dd8043
commit 57a874c771

@ -214,7 +214,7 @@ int main(int ac, const char* av[]) {
return xmrblocks.show_rawtx(); return xmrblocks.show_rawtx();
}); });
CROW_ROUTE(app, "/checkandpush").methods("POST"_method) CROW_ROUTE(app, "/checkrawtx").methods("POST"_method)
([&](const crow::request& req) { ([&](const crow::request& req) {
map<std::string, std::string> post_body = xmreg::parse_crow_post_data(req.body); map<std::string, std::string> 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 raw_tx_data = post_body["rawtxdata"];
string action = post_body["action"]; 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<std::string, std::string> 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) CROW_ROUTE(app, "/search").methods("GET"_method)
([&](const crow::request& req) { ([&](const crow::request& req) {
return xmrblocks.search(string(req.url_params.get("value"))); return xmrblocks.search(string(req.url_params.get("value")));

@ -1259,7 +1259,7 @@ namespace xmreg {
} }
string string
show_checkandpushtx(string raw_tx_data, string action) show_checkrawtx(string raw_tx_data, string action)
{ {
// remove white characters // remove white characters
boost::trim(raw_tx_data); boost::trim(raw_tx_data);
@ -1610,6 +1610,54 @@ namespace xmreg {
return mstch::render(full_page, context, partials); 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<tools::wallet2::pending_tx> 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 string
search(string search_text) search(string search_text)

Loading…
Cancel
Save