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