Electroneum
wallet_tools Class Reference

#include <wallet_tools.h>

Static Public Member Functions

static void gen_tx_src (size_t mixin, uint64_t cur_height, const tools::wallet2::transfer_details &td, cryptonote::tx_source_entry &src, block_tracker &bt)
 
static void gen_block_data (block_tracker &bt, const cryptonote::block *bl, const map_hash2tx_t &mtx, cryptonote::block_complete_entry &bche, tools::wallet2::parsed_block &parsed_block, uint64_t &height)
 
static void compute_subaddresses (std::unordered_map< crypto::public_key, cryptonote::subaddress_index > &subaddresses, cryptonote::account_base &creds, size_t account, size_t minors)
 
static void process_transactions (tools::wallet2 *wallet, const std::vector< test_event_entry > &events, const cryptonote::block &blk_head, block_tracker &bt, const boost::optional< crypto::hash > &blk_tail=boost::none)
 
static void process_transactions (tools::wallet2 *wallet, const std::vector< const cryptonote::block *> &blockchain, const map_hash2tx_t &mtx, block_tracker &bt)
 
static bool fill_tx_sources (tools::wallet2 *wallet, std::vector< cryptonote::tx_source_entry > &sources, size_t mixin, const boost::optional< size_t > &num_utxo, const boost::optional< uint64_t > &min_amount, block_tracker &bt, std::vector< size_t > &selected, uint64_t cur_height, ssize_t offset=0, int step=1, const boost::optional< fnc_accept_tx_source_t > &fnc_accept=boost::none)
 

Detailed Description

Definition at line 60 of file wallet_tools.h.

Member Function Documentation

◆ compute_subaddresses()

void wallet_tools::compute_subaddresses ( std::unordered_map< crypto::public_key, cryptonote::subaddress_index > &  subaddresses,
cryptonote::account_base creds,
size_t  account,
size_t  minors 
)
static

Definition at line 241 of file wallet_tools.cpp.

242 {
243  auto &hwdev = hw::get_device("default");
244  const std::vector<crypto::public_key> pkeys = hwdev.get_subaddress_spend_public_keys(creds.get_keys(), account, 0, minors);
245 
246  for(uint32_t c = 0; c < pkeys.size(); ++c){
247  cryptonote::subaddress_index sidx{(uint32_t)account, c};
248  subaddresses[pkeys[c]] = sidx;
249  }
250 }
const account_keys & get_keys() const
Definition: account.cpp:264
unsigned int uint32_t
Definition: stdint.h:126
device & get_device(const std::string &device_descriptor)
Definition: device.cpp:95
Here is the call graph for this function:

◆ fill_tx_sources()

bool wallet_tools::fill_tx_sources ( tools::wallet2 wallet,
std::vector< cryptonote::tx_source_entry > &  sources,
size_t  mixin,
const boost::optional< size_t > &  num_utxo,
const boost::optional< uint64_t > &  min_amount,
block_tracker bt,
std::vector< size_t > &  selected,
uint64_t  cur_height,
ssize_t  offset = 0,
int  step = 1,
const boost::optional< fnc_accept_tx_source_t > &  fnc_accept = boost::none 
)
static

Definition at line 77 of file wallet_tools.cpp.

78 {
79  CHECK_AND_ASSERT_THROW_MES(step != 0, "Step is zero");
80  sources.clear();
81 
82  auto & transfers = wallet_accessor_test::get_transfers(wallet);
83  std::unordered_set<size_t> selected_idx;
84  std::unordered_set<crypto::key_image> selected_kis;
85  const size_t ntrans = wallet->get_num_transfer_details();
86  size_t roffset = offset >= 0 ? offset : ntrans - offset - 1;
87  size_t iters = 0;
88  uint64_t sum = 0;
89  size_t cur_utxo = 0;
90  bool abort = false;
91  unsigned brk_cond = 0;
92  unsigned brk_thresh = num_utxo && min_amount ? 2 : (num_utxo || min_amount ? 1 : 0);
93 
94 #define EVAL_BRK_COND() do { \
95  brk_cond = 0; \
96  if (num_utxo && num_utxo.get() <= cur_utxo) \
97  brk_cond += 1; \
98  if (min_amount && min_amount.get() <= sum) \
99  brk_cond += 1; \
100  } while(0)
101 
102  for(ssize_t i = roffset; iters < ntrans && !abort; i += step, ++iters)
103  {
104  EVAL_BRK_COND();
105  if (brk_cond >= brk_thresh)
106  break;
107 
108  i = i < 0 ? (i + ntrans) : i % ntrans;
109  auto & td = transfers[i];
110  if (td.m_spent)
111  continue;
112  if (td.m_block_height + CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW > cur_height)
113  continue;
114  if (selected_idx.find((size_t)i) != selected_idx.end()){
115  MERROR("Should not happen (selected_idx not found): " << i);
116  continue;
117  }
118  if (selected_kis.find(td.m_key_image) != selected_kis.end()){
119  MERROR("Should not happen (selected KI): " << i << "ki: " << dump_keys(td.m_key_image.data));
120  continue;
121  }
122 
123  try {
125  wallet_tools::gen_tx_src(mixin, cur_height, td, src, bt);
126 
127  // Acceptor function
128  if (fnc_accept){
129  tx_source_info_crate_t c_info{.td=&td, .src=&src, .selected_idx=&selected_idx, .selected_kis=&selected_kis,
130  .ntrans=ntrans, .iters=iters, .sum=sum, .cur_utxo=cur_utxo};
131 
132  bool take_it = (fnc_accept.get())(c_info, abort);
133  if (!take_it){
134  continue;
135  }
136  }
137 
138  MDEBUG("Selected " << i << " from tx: " << dump_keys(td.m_txid.data)
139  << " ki: " << dump_keys(td.m_key_image.data)
140  << " amnt: " << td.amount()
141  << " rct: " << td.is_rct()
142  << " glob: " << td.m_global_output_index);
143 
144  sum += td.amount();
145  cur_utxo += 1;
146 
147  sources.emplace_back(src);
148  selected.push_back((size_t)i);
149  selected_idx.insert((size_t)i);
150  selected_kis.insert(td.m_key_image);
151 
152  } catch(const std::exception &e){
153  MTRACE("Output " << i << ", from: " << dump_keys(td.m_txid.data)
154  << ", amnt: " << td.amount() << ", rct: " << td.is_rct()
155  << ", glob: " << td.m_global_output_index << " is not applicable: " << e.what());
156  }
157  }
158 
159  EVAL_BRK_COND();
160  return brk_cond >= brk_thresh;
161 #undef EVAL_BRK_COND
162 }
#define CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
#define MERROR(x)
Definition: misc_log_ex.h:73
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
#define MTRACE(x)
Definition: misc_log_ex.h:77
#define EVAL_BRK_COND()
#define MDEBUG(x)
Definition: misc_log_ex.h:76
unsigned __int64 uint64_t
Definition: stdint.h:136
tools::wallet2::transfer_details * td
Definition: wallet_tools.h:37
size_t get_num_transfer_details() const
Definition: wallet2.h:1155
static void gen_tx_src(size_t mixin, uint64_t cur_height, const tools::wallet2::transfer_details &td, cryptonote::tx_source_entry &src, block_tracker &bt)
std::string dump_keys(T *buff32)
Definition: chaingen.h:271
static tools::wallet2::transfer_container & get_transfers(tools::wallet2 *wallet)
Definition: wallet_tools.h:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_block_data()

void wallet_tools::gen_block_data ( block_tracker bt,
const cryptonote::block bl,
const map_hash2tx_t mtx,
cryptonote::block_complete_entry bche,
tools::wallet2::parsed_block parsed_block,
uint64_t height 
)
static

Definition at line 206 of file wallet_tools.cpp.

207 {
208  vector<const transaction*> vtx;
209  vtx.push_back(&(bl->miner_tx));
210  height = boost::get<txin_gen>(*bl->miner_tx.vin.begin()).height;
211 
212  BOOST_FOREACH(const crypto::hash &h, bl->tx_hashes) {
213  const map_hash2tx_t::const_iterator cit = mtx.find(h);
214  CHECK_AND_ASSERT_THROW_MES(mtx.end() != cit, "block contains an unknown tx hash @ " << height << ", " << h);
215  vtx.push_back(cit->second);
216  }
217 
218  bche.block = "NA";
219  bche.txs.resize(bl->tx_hashes.size());
220 
221  parsed_block.error = false;
222  parsed_block.hash = get_block_hash(*bl);
223  parsed_block.block = *bl;
224  parsed_block.txes.reserve(bl->tx_hashes.size());
225 
226  auto & o_indices = parsed_block.o_indices.indices;
227  o_indices.reserve(bl->tx_hashes.size() + 1);
228 
229  size_t cur = 0;
230  BOOST_FOREACH(const transaction *tx, vtx){
231  cur += 1;
232  o_indices.emplace_back();
233  bt.process(bl, tx, cur - 1);
234  bt.global_indices(tx, o_indices.back().indices);
235 
236  if (cur > 1) // miner not included
237  parsed_block.txes.push_back(*tx);
238  }
239 }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
std::vector< crypto::hash > tx_hashes
void global_indices(const cryptonote::transaction *tx, std::vector< uint64_t > &indices)
Definition: chaingen.cpp:535
uint64_t height
Definition: blockchain.cpp:91
std::vector< cryptonote::transaction > txes
Definition: wallet2.h:568
std::vector< blobdata > txs
cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices o_indices
Definition: wallet2.h:569
blobdata block
cryptonote::block block
Definition: wallet2.h:567
void process(const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx)
Definition: chaingen.cpp:472
crypto::hash get_block_hash(uint64_t height)
POD_CLASS hash
Definition: hash.h:50
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gen_tx_src()

void wallet_tools::gen_tx_src ( size_t  mixin,
uint64_t  cur_height,
const tools::wallet2::transfer_details td,
cryptonote::tx_source_entry src,
block_tracker bt 
)
static

Definition at line 164 of file wallet_tools.cpp.

165 {
166  src.amount = td.amount();
167  src.rct = td.is_rct();
168 
169  std::vector<tools::wallet2::get_outs_entry> outs;
170  bt.get_fake_outs(mixin, td.is_rct() ? 0 : td.amount(), td.m_global_output_index, cur_height, outs);
171 
172  for (size_t n = 0; n < mixin; ++n)
173  {
175  oe.first = std::get<0>(outs[n]);
176  oe.second.dest = rct::pk2rct(std::get<1>(outs[n]));
177  oe.second.mask = std::get<2>(outs[n]);
178  src.outputs.push_back(oe);
179  }
180 
181  size_t real_idx = crypto::rand<size_t>() % mixin;
182 
183  cryptonote::tx_source_entry::output_entry &real_oe = src.outputs[real_idx];
184  real_oe.first = td.m_global_output_index;
185  real_oe.second.dest = rct::pk2rct(boost::get<txout_to_key>(td.m_tx.vout[td.m_internal_output_index].target).key);
186  real_oe.second.mask = rct::commit(td.amount(), td.m_mask);
187 
188  std::sort(src.outputs.begin(), src.outputs.end(), [&](const cryptonote::tx_source_entry::output_entry i0, const cryptonote::tx_source_entry::output_entry i1) {
189  return i0.first < i1.first;
190  });
191 
192  for (size_t i = 0; i < src.outputs.size(); ++i){
193  if (src.outputs[i].first == td.m_global_output_index){
194  src.real_output = i;
195  break;
196  }
197  }
198 
199  src.mask = td.m_mask;
204 }
crypto::public_key real_out_tx_key
key commit(etn_amount amount, const key &mask)
Definition: rctOps.cpp:336
void get_fake_outs(size_t num_outs, uint64_t amount, uint64_t global_index, uint64_t cur_height, std::vector< get_outs_entry > &outs)
Definition: chaingen.cpp:547
bool rct
uint64_t amount
size_t real_output
crypto::public_key get_tx_pub_key_from_extra(const std::vector< uint8_t > &tx_extra, size_t pk_index)
cryptonote::transaction_prefix m_tx
Definition: wallet2.h:304
rct::multisig_kLRki multisig_kLRki
std::vector< crypto::public_key > real_out_additional_tx_keys
size_t real_output_in_tx_index
std::vector< output_entry > outputs
std::pair< uint64_t, rct::ctkey > output_entry
std::vector< crypto::public_key > get_additional_tx_pub_keys_from_extra(const std::vector< uint8_t > &tx_extra)
key zero()
Definition: rctOps.h:70
rct::key mask
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_transactions() [1/2]

void wallet_tools::process_transactions ( tools::wallet2 wallet,
const std::vector< test_event_entry > &  events,
const cryptonote::block blk_head,
block_tracker bt,
const boost::optional< crypto::hash > &  blk_tail = boost::none 
)
static

Definition at line 40 of file wallet_tools.cpp.

41 {
42  map_hash2tx_t mtx;
43  std::vector<const cryptonote::block*> blockchain;
44  find_block_chain(events, blockchain, mtx, get_block_hash(blk_head));
45 
46  if (blk_tail){
47  trim_block_chain(blockchain, blk_tail.get());
48  }
49 
50  process_transactions(wallet, blockchain, mtx, bt);
51 }
bool find_block_chain(const std::vector< test_event_entry > &events, std::vector< cryptonote::block > &blockchain, map_hash2tx_t &mtx, const crypto::hash &head)
Definition: chaingen.cpp:1072
bool trim_block_chain(std::vector< cryptonote::block > &blockchain, const crypto::hash &tail)
Definition: chaingen.cpp:1004
std::unordered_map< crypto::hash, const cryptonote::transaction * > map_hash2tx_t
Definition: chaingen.h:163
static void process_transactions(tools::wallet2 *wallet, const std::vector< test_event_entry > &events, const cryptonote::block &blk_head, block_tracker &bt, const boost::optional< crypto::hash > &blk_tail=boost::none)
crypto::hash get_block_hash(uint64_t height)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_transactions() [2/2]

void wallet_tools::process_transactions ( tools::wallet2 wallet,
const std::vector< const cryptonote::block *> &  blockchain,
const map_hash2tx_t mtx,
block_tracker bt 
)
static

Definition at line 53 of file wallet_tools.cpp.

54 {
55  uint64_t start_height=0, blocks_added=0;
56  std::vector<cryptonote::block_complete_entry> v_bche;
57  std::vector<tools::wallet2::parsed_block> v_parsed_block;
58 
59  v_bche.reserve(blockchain.size());
60  v_parsed_block.reserve(blockchain.size());
61 
62  size_t idx = 0;
63  for(auto bl : blockchain)
64  {
65  idx += 1;
67  v_bche.emplace_back();
68  v_parsed_block.emplace_back();
69 
70  wallet_tools::gen_block_data(bt, bl, mtx, v_bche.back(), v_parsed_block.back(), idx == 1 ? start_height : height);
71  }
72 
73  if (wallet)
74  wallet_accessor_test::process_parsed_blocks(wallet, start_height, v_bche, v_parsed_block, blocks_added);
75 }
static void process_parsed_blocks(tools::wallet2 *wallet, uint64_t start_height, const std::vector< cryptonote::block_complete_entry > &blocks, const std::vector< tools::wallet2::parsed_block > &parsed_blocks, uint64_t &blocks_added)
uint64_t height
Definition: blockchain.cpp:91
unsigned __int64 uint64_t
Definition: stdint.h:136
static void gen_block_data(block_tracker &bt, const cryptonote::block *bl, const map_hash2tx_t &mtx, cryptonote::block_complete_entry &bche, tools::wallet2::parsed_block &parsed_block, uint64_t &height)
Here is the call graph for this function:

The documentation for this class was generated from the following files: