| 1 | // Copyright (c) 2014-2022, The Monero Project |
| 2 | // |
| 3 | // All rights reserved. |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without modification, are |
| 6 | // permitted provided that the following conditions are met: |
| 7 | // |
| 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of |
| 9 | // conditions and the following disclaimer. |
| 10 | // |
| 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list |
| 12 | // of conditions and the following disclaimer in the documentation and/or other |
| 13 | // materials provided with the distribution. |
| 14 | // |
| 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be |
| 16 | // used to endorse or promote products derived from this software without specific |
| 17 | // prior written permission. |
| 18 | // |
| 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY |
| 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | // |
| 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers |
| 30 | |
| 31 | #include "include_base_utils.h" |
| 32 | using namespace epee; |
| 33 | #include "wallet/wallet2.h" |
| 34 | |
| 35 | using namespace cryptonote; |
| 36 | |
| 37 | /* |
| 38 | bool transactions_generation_from_blockchain(std::string& blockchain_folder_path) |
| 39 | { |
| 40 | string_tools::parse_hexstr_to_binbuff() |
| 41 | tx_memory_pool pool; |
| 42 | blockchain_storage bchs(pool); |
| 43 | bool r = bchs.init(blockchain_folder_path); |
| 44 | CHECK_AND_ASSERT_MES(r, false, "failed to load blockchain"); |
| 45 | |
| 46 | //amount = 3000000000000 |
| 47 | //key_offsets = 1,2,3,4,5,10,12,27,31,33,34 |
| 48 | // |
| 49 | } |
| 50 | |
| 51 | tx_source_entry::output_entry make_outptu_entr_for_gindex(size_t i, std::map<crypto::hash, transaction>& txs, std::vector<std::pair<crypto::hash, size_t> >& v) |
| 52 | { |
| 53 | tx_source_entry::output_entry oe; |
| 54 | oe = i; |
| 55 | oe.second = txs[v[i].first].boost::get<txout_to_key>(vout[v[i].second].target).key; |
| 56 | return oe; |
| 57 | } |
| 58 | |
| 59 | bool make_tx(blockchain_storage& bch) |
| 60 | { |
| 61 | std::map<crypto::hash, transaction> txs; |
| 62 | std::vector<std::pair<crypto::hash, size_t> > v; |
| 63 | bch.get_outs_for_amounts(3000000000000, v); |
| 64 | |
| 65 | std::vector<tx_source_entry> sources(11); |
| 66 | sources[0].amount = 3000000000000; |
| 67 | sources[0].outputs.push_back(make_outptu_entr_for_gindex(1, txs, v)); |
| 68 | sources[0].outputs.push_back(make_outptu_entr_for_gindex(2, txs, v)); |
| 69 | sources[0].outputs.push_back(make_outptu_entr_for_gindex(3, txs, v)); |
| 70 | sources[0].outputs.push_back(make_outptu_entr_for_gindex(4, txs, v)); |
| 71 | sources[0].outputs.push_back(make_outptu_entr_for_gindex(5, txs, v)); |
| 72 | sources[0].outputs.push_back(make_outptu_entr_for_gindex(10, txs, v)); |
| 73 | sources[0].outputs.push_back(make_outptu_entr_for_gindex(12, txs, v)); |
| 74 | sources[0].outputs.push_back(make_outptu_entr_for_gindex(27, txs, v)); |
| 75 | sources[0].outputs.push_back(make_outptu_entr_for_gindex(31, txs, v)); |
| 76 | sources[0].outputs.push_back(make_outptu_entr_for_gindex(33, txs, v)); |
| 77 | sources[0].outputs.push_back(make_outptu_entr_for_gindex(34, txs, v)); |
| 78 | sources[0].real_out_tx_key = |
| 79 | |
| 80 | BOOST_FOREACH(transfer_container::iterator it, selected_transfers) |
| 81 | { |
| 82 | sources.resize(sources.size()+1); |
| 83 | cryptonote::tx_source_entry& src = sources.back(); |
| 84 | transfer_details& td = *it; |
| 85 | src.amount = td.m_tx.vout[td.m_internal_output_index].amount; |
| 86 | //paste mixin transaction |
| 87 | if(daemon_resp.outs.size()) |
| 88 | { |
| 89 | daemon_resp.outs[i].outs.sort([](const out_entry& a, const out_entry& b){return a.global_amount_index < b.global_amount_index;}); |
| 90 | BOOST_FOREACH(out_entry& daemon_oe, daemon_resp.outs[i].outs) |
| 91 | { |
| 92 | if(td.m_global_output_index == daemon_oe.global_amount_index) |
| 93 | continue; |
| 94 | tx_output_entry oe; |
| 95 | oe.first = daemon_oe.global_amount_index; |
| 96 | oe.second = daemon_oe.out_key; |
| 97 | src.outputs.push_back(oe); |
| 98 | if(src.outputs.size() >= fake_outputs_count) |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | //paste real transaction to the random index |
| 104 | auto it_to_insert = std::find_if(src.outputs.begin(), src.outputs.end(), [&](const tx_output_entry& a) |
| 105 | { |
| 106 | return a.first >= td.m_global_output_index; |
| 107 | }); |
| 108 | //size_t real_index = src.outputs.size() ? (rand() % src.outputs.size() ):0; |
| 109 | tx_output_entry real_oe; |
| 110 | real_oe.first = td.m_global_output_index; |
| 111 | real_oe.second = boost::get<txout_to_key>(td.m_tx.vout[td.m_internal_output_index].target).key; |
| 112 | auto interted_it = src.outputs.insert(it_to_insert, real_oe); |
| 113 | src.real_out_tx_key = td.m_tx.tx_pub_key; |
| 114 | src.real_output = interted_it - src.outputs.begin(); |
| 115 | src.real_output_in_tx_index = td.m_internal_output_index; |
| 116 | src.rct = false; |
| 117 | ++i; |
| 118 | } |
| 119 | |
| 120 | |
| 121 | if(found_money != needed_money) |
| 122 | { |
| 123 | //lets make last output to odd money |
| 124 | dsts.resize(dsts.size()+1); |
| 125 | cryptonote::tx_destination_entry& destination = dsts.back(); |
| 126 | CHECK_AND_ASSERT_MES(found_money > needed_money, false, "internal error found_money=" << found_money << " !> needed_money=" << needed_money); |
| 127 | destination.amount = found_money - needed_money; |
| 128 | } |
| 129 | |
| 130 | |
| 131 | transaction tx; |
| 132 | bool r = cryptonote::construct_tx(m_account.get_keys(), sources, dsts, tx, unlock_time); |
| 133 | if(!r) |
| 134 | { |
| 135 | std::cout << "transaction construction failed" << std::endl; |
| 136 | } |
| 137 | |
| 138 | COMMAND_RPC_SEND_RAW_TX::request req; |
| 139 | req.tx_as_hex = epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(tx)); |
| 140 | COMMAND_RPC_SEND_RAW_TX::response daemon_send_resp; |
| 141 | r = net_utils::http::invoke_http_json_remote_command(m_daemon_address + "/sendrawtransaction", req, daemon_send_resp, m_http_client); |
| 142 | CHECK_AND_ASSERT_MES(r, false, "failed to send transaction"); |
| 143 | if(daemon_send_resp.status != CORE_RPC_STATUS_OK) |
| 144 | { |
| 145 | std::cout << "daemon failed to accept generated transaction" << ENDL; |
| 146 | return false; |
| 147 | } |
| 148 | |
| 149 | std::cout << "transaction generated ok and sent to daemon" << std::endl; |
| 150 | BOOST_FOREACH(transfer_container::iterator it, selected_transfers) |
| 151 | it->m_spent = true; |
| 152 | |
| 153 | return true; |
| 154 | }*/ |