Electroneum
Loading...
Searching...
No Matches
chaingen.cpp File Reference
#include <vector>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <array>
#include <random>
#include <fstream>
#include "include_base_utils.h"
#include "console_handler.h"
#include "p2p/net_node.h"
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/cryptonote_basic_impl.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "cryptonote_basic/miner.h"
#include "chaingen.h"
#include "device/device.hpp"
Include dependency graph for chaingen.cpp:

Go to the source code of this file.

Functions

bool init_output_indices (map_output_idx_t &outs, std::map< uint64_t, std::vector< size_t > > &outs_mine, const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx, const cryptonote::account_base &from)
bool init_spent_output_indices (map_output_idx_t &outs, map_output_t &outs_mine, const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx, const cryptonote::account_base &from)
bool fill_output_entries (std::vector< output_index > &out_indices, size_t sender_out, size_t nmix, size_t &real_entry_idx, std::vector< tx_source_entry::output_entry > &output_entries)
bool fill_tx_sources (std::vector< tx_source_entry > &sources, const std::vector< test_event_entry > &events, const block &blk_head, const cryptonote::account_base &from, uint64_t amount, size_t nmix)
bool fill_tx_destination (tx_destination_entry &de, const cryptonote::account_public_address &to, uint64_t amount)
std::string dump_data (const cryptonote::transaction &tx)
cryptonote::account_public_address get_address (const var_addr_t &inp)
cryptonote::account_public_address get_address (const cryptonote::account_public_address &inp)
cryptonote::account_public_address get_address (const cryptonote::account_keys &inp)
cryptonote::account_public_address get_address (const cryptonote::account_base &inp)
cryptonote::account_public_address get_address (const cryptonote::tx_destination_entry &inp)
uint64_t sum_amount (const std::vector< tx_destination_entry > &destinations)
uint64_t sum_amount (const std::vector< cryptonote::tx_source_entry > &sources)
void fill_tx_destinations (const var_addr_t &from, const std::vector< tx_destination_entry > &dests, uint64_t fee, const std::vector< tx_source_entry > &sources, std::vector< tx_destination_entry > &destinations, bool always_change)
void fill_tx_destinations (const var_addr_t &from, const cryptonote::account_public_address &to, uint64_t amount, uint64_t fee, const std::vector< tx_source_entry > &sources, std::vector< tx_destination_entry > &destinations, std::vector< tx_destination_entry > &destinations_pure, bool always_change)
void fill_tx_destinations (const var_addr_t &from, const cryptonote::account_public_address &to, uint64_t amount, uint64_t fee, const std::vector< tx_source_entry > &sources, std::vector< tx_destination_entry > &destinations, bool always_change)
void fill_tx_sources_and_destinations (const std::vector< test_event_entry > &events, const block &blk_head, const cryptonote::account_base &from, const cryptonote::account_public_address &to, uint64_t amount, uint64_t fee, size_t nmix, std::vector< tx_source_entry > &sources, std::vector< tx_destination_entry > &destinations)
void fill_tx_sources_and_destinations (const std::vector< test_event_entry > &events, const block &blk_head, const cryptonote::account_base &from, const cryptonote::account_base &to, uint64_t amount, uint64_t fee, size_t nmix, std::vector< tx_source_entry > &sources, std::vector< tx_destination_entry > &destinations)
void fill_nonce (cryptonote::block &blk, const difficulty_type &diffic, uint64_t height)
cryptonote::tx_destination_entry build_dst (const var_addr_t &to, bool is_subaddr, uint64_t amount)
std::vector< cryptonote::tx_destination_entrybuild_dsts (const var_addr_t &to1, bool sub1, uint64_t am1)
std::vector< cryptonote::tx_destination_entrybuild_dsts (std::initializer_list< dest_wrapper_t > inps)
bool construct_miner_tx_manually (size_t height, uint64_t already_generated_coins, const account_public_address &miner_address, transaction &tx, uint64_t fee, keypair *p_txkey)
bool construct_tx_to_key (const std::vector< test_event_entry > &events, cryptonote::transaction &tx, const cryptonote::block &blk_head, const cryptonote::account_base &from, const var_addr_t &to, uint64_t amount, uint64_t fee, size_t nmix, bool rct, rct::RangeProofType range_proof_type, int bp_version)
bool construct_tx_to_key (const std::vector< test_event_entry > &events, cryptonote::transaction &tx, const cryptonote::block &blk_head, const cryptonote::account_base &from, std::vector< cryptonote::tx_destination_entry > destinations, uint64_t fee, size_t nmix, bool rct, rct::RangeProofType range_proof_type, int bp_version)
bool construct_tx_to_key (cryptonote::transaction &tx, const cryptonote::account_base &from, const var_addr_t &to, uint64_t amount, std::vector< cryptonote::tx_source_entry > &sources, uint64_t fee, bool rct, rct::RangeProofType range_proof_type, int bp_version)
bool construct_tx_to_key (cryptonote::transaction &tx, const cryptonote::account_base &from, const std::vector< cryptonote::tx_destination_entry > &destinations, std::vector< cryptonote::tx_source_entry > &sources, uint64_t fee, bool rct, rct::RangeProofType range_proof_type, int bp_version)
bool construct_tx_rct (const cryptonote::account_keys &sender_account_keys, std::vector< cryptonote::tx_source_entry > &sources, const std::vector< cryptonote::tx_destination_entry > &destinations, const boost::optional< cryptonote::account_public_address > &change_addr, std::vector< uint8_t > extra, cryptonote::transaction &tx, uint64_t unlock_time, bool rct, rct::RangeProofType range_proof_type, int bp_version)
transaction construct_tx_with_fee (std::vector< test_event_entry > &events, const block &blk_head, const account_base &acc_from, const var_addr_t &to, uint64_t amount, uint64_t fee)
uint64_t get_balance (const cryptonote::account_base &addr, const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx)
bool extract_hard_forks (const std::vector< test_event_entry > &events, v_hardforks_t &hard_forks)
void get_confirmed_txs (const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx, map_hash2tx_t &confirmed_txs)
bool trim_block_chain (std::vector< cryptonote::block > &blockchain, const crypto::hash &tail)
bool trim_block_chain (std::vector< const cryptonote::block * > &blockchain, const crypto::hash &tail)
uint64_t num_blocks (const std::vector< test_event_entry > &events)
cryptonote::block get_head_block (const std::vector< test_event_entry > &events)
bool find_block_chain (const std::vector< test_event_entry > &events, std::vector< cryptonote::block > &blockchain, map_hash2tx_t &mtx, const crypto::hash &head)
bool find_block_chain (const std::vector< test_event_entry > &events, std::vector< const cryptonote::block * > &blockchain, map_hash2tx_t &mtx, const crypto::hash &head)

Function Documentation

◆ build_dst()

cryptonote::tx_destination_entry build_dst ( const var_addr_t & to,
bool is_subaddr,
uint64_t amount )

Definition at line 804 of file chaingen.cpp.

805{
807 de.amount = amount;
808 de.addr = get_address(to);
809 de.is_subaddress = is_subaddr;
810 return de;
811}
cryptonote::account_public_address get_address(const var_addr_t &inp)
Definition chaingen.cpp:665
bool is_subaddress
uint64_t amount
account_public_address addr
Here is the call graph for this function:
Here is the caller graph for this function:

◆ build_dsts() [1/2]

std::vector< cryptonote::tx_destination_entry > build_dsts ( const var_addr_t & to1,
bool sub1,
uint64_t am1 )

Definition at line 813 of file chaingen.cpp.

814{
815 std::vector<cryptonote::tx_destination_entry> res;
816 res.push_back(build_dst(to1, sub1, am1));
817 return res;
818}
cryptonote::tx_destination_entry build_dst(const var_addr_t &to, bool is_subaddr, uint64_t amount)
Definition chaingen.cpp:804
const char * res
Here is the call graph for this function:
Here is the caller graph for this function:

◆ build_dsts() [2/2]

std::vector< cryptonote::tx_destination_entry > build_dsts ( std::initializer_list< dest_wrapper_t > inps)

Definition at line 820 of file chaingen.cpp.

821{
822 std::vector<cryptonote::tx_destination_entry> res;
823 res.reserve(inps.size());
824 for(auto & c : inps){
825 res.push_back(build_dst(c.addr, c.is_subaddr, c.amount));
826 }
827 return res;
828}
Here is the call graph for this function:

◆ construct_miner_tx_manually()

bool construct_miner_tx_manually ( size_t height,
uint64_t already_generated_coins,
const account_public_address & miner_address,
transaction & tx,
uint64_t fee,
keypair * p_txkey )

Definition at line 830 of file chaingen.cpp.

833{
834 keypair txkey;
835 txkey = keypair::generate(hw::get_device("default"));
836 add_tx_pub_key_to_extra(tx, txkey.pub);
837
838 if (0 != p_txkey)
839 *p_txkey = txkey;
840
841 txin_gen in;
842 in.height = height;
843 tx.vin.push_back(in);
844
845 // This will work, until size of constructed block is less then CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE
846 uint64_t block_reward;
847 //Deal with premine implementation.
848 if (height == 1){block_reward = 1260000000000;}
849 else if (!get_block_reward(0, 0, already_generated_coins, block_reward, 1, height))
850 {
851 LOG_PRINT_L0("Block is too big");
852 return false;
853 }
854 block_reward += fee;
855
856 crypto::key_derivation derivation;
857 crypto::public_key out_eph_public_key;
858 crypto::generate_key_derivation(miner_address.m_view_public_key, txkey.sec, derivation);
859 crypto::derive_public_key(derivation, 0, miner_address.m_spend_public_key, out_eph_public_key);
860
861 tx_out out;
862 out.amount = block_reward;
863 out.target = txout_to_key(out_eph_public_key);
864 tx.vout.push_back(out);
865
866 tx.version = 1;
868
869 return true;
870}
uint64_t height
#define CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
#define LOG_PRINT_L0(x)
Definition misc_log_ex.h:99
POD_CLASS key_derivation
Definition crypto.h:101
bool generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation)
Definition crypto.h:272
POD_CLASS public_key
Definition crypto.h:79
bool derive_public_key(const key_derivation &derivation, std::size_t output_index, const public_key &base, public_key &derived_key)
Definition crypto.h:275
bool get_block_reward(size_t median_weight, size_t current_block_weight, uint64_t already_generated_coins, uint64_t &reward, uint8_t version, uint64_t current_block_height, network_type nettype)
bool add_tx_pub_key_to_extra(transaction &tx, const crypto::public_key &tx_pub_key)
device & get_device(const std::string &device_descriptor)
Definition device.cpp:95
unsigned __int64 uint64_t
Definition stdint.h:136
crypto::secret_key sec
crypto::public_key pub
Here is the call graph for this function:

◆ construct_tx_rct()

bool construct_tx_rct ( const cryptonote::account_keys & sender_account_keys,
std::vector< cryptonote::tx_source_entry > & sources,
const std::vector< cryptonote::tx_destination_entry > & destinations,
const boost::optional< cryptonote::account_public_address > & change_addr,
std::vector< uint8_t > extra,
cryptonote::transaction & tx,
uint64_t unlock_time,
bool rct,
rct::RangeProofType range_proof_type,
int bp_version )

Definition at line 920 of file chaingen.cpp.

921{
922 std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
923 subaddresses[sender_account_keys.m_account_address.m_spend_public_key] = {0, 0};
924 crypto::secret_key tx_key;
925 std::vector<crypto::secret_key> additional_tx_keys;
926 std::vector<tx_destination_entry> destinations_copy = destinations;
927 rct::RCTConfig rct_config = {range_proof_type, bp_version};
928 return construct_tx_and_get_tx_key(sender_account_keys, subaddresses, sources, destinations_copy, change_addr, extra, tx, unlock_time, tx_key, additional_tx_keys, rct, rct_config, nullptr);
929}
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition crypto.h:82
bool construct_tx_and_get_tx_key(const account_keys &sender_account_keys, const std::unordered_map< crypto::public_key, subaddress_index > &subaddresses, std::vector< tx_source_entry > &sources, std::vector< tx_destination_entry > &destinations, const boost::optional< cryptonote::account_public_address > &change_addr, const std::vector< uint8_t > &extra, transaction &tx, uint64_t unlock_time, crypto::secret_key &tx_key, std::vector< crypto::secret_key > &additional_tx_keys, bool rct, const rct::RCTConfig &rct_config, rct::multisig_out *msout, const uint32_t account_major_offset, const cryptonote::network_type nettype)
account_public_address m_account_address
Definition account.h:43
Here is the call graph for this function:
Here is the caller graph for this function:

◆ construct_tx_to_key() [1/4]

bool construct_tx_to_key ( const std::vector< test_event_entry > & events,
cryptonote::transaction & tx,
const cryptonote::block & blk_head,
const cryptonote::account_base & from,
const var_addr_t & to,
uint64_t amount,
uint64_t fee,
size_t nmix,
bool rct,
rct::RangeProofType range_proof_type,
int bp_version )

Definition at line 872 of file chaingen.cpp.

875{
876 vector<tx_source_entry> sources;
877 vector<tx_destination_entry> destinations;
878 fill_tx_sources_and_destinations(events, blk_head, from, get_address(to), amount, fee, nmix, sources, destinations);
879
880 return construct_tx_rct(from.get_keys(), sources, destinations, from.get_keys().m_account_address, std::vector<uint8_t>(), tx, 0, rct, range_proof_type, bp_version);
881}
void fill_tx_sources_and_destinations(const std::vector< test_event_entry > &events, const block &blk_head, const cryptonote::account_base &from, const cryptonote::account_public_address &to, uint64_t amount, uint64_t fee, size_t nmix, std::vector< tx_source_entry > &sources, std::vector< tx_destination_entry > &destinations)
Definition chaingen.cpp:775
bool construct_tx_rct(const cryptonote::account_keys &sender_account_keys, std::vector< cryptonote::tx_source_entry > &sources, const std::vector< cryptonote::tx_destination_entry > &destinations, const boost::optional< cryptonote::account_public_address > &change_addr, std::vector< uint8_t > extra, cryptonote::transaction &tx, uint64_t unlock_time, bool rct, rct::RangeProofType range_proof_type, int bp_version)
Definition chaingen.cpp:920
const account_keys & get_keys() const
Definition account.cpp:264
Here is the call graph for this function:
Here is the caller graph for this function:

◆ construct_tx_to_key() [2/4]

bool construct_tx_to_key ( const std::vector< test_event_entry > & events,
cryptonote::transaction & tx,
const cryptonote::block & blk_head,
const cryptonote::account_base & from,
std::vector< cryptonote::tx_destination_entry > destinations,
uint64_t fee,
size_t nmix,
bool rct,
rct::RangeProofType range_proof_type,
int bp_version )

Definition at line 883 of file chaingen.cpp.

886{
887 vector<tx_source_entry> sources;
888 vector<tx_destination_entry> destinations_all;
889 uint64_t amount = sum_amount(destinations);
890
891 if (!fill_tx_sources(sources, events, blk_head, from, amount + fee, nmix))
892 throw std::runtime_error("couldn't fill transaction sources");
893
894 fill_tx_destinations(from, destinations, fee, sources, destinations_all, false);
895
896 return construct_tx_rct(from.get_keys(), sources, destinations_all, get_address(from), std::vector<uint8_t>(), tx, 0, rct, range_proof_type, bp_version);
897}
uint64_t sum_amount(const std::vector< tx_destination_entry > &destinations)
Definition chaingen.cpp:700
bool fill_tx_sources(std::vector< tx_source_entry > &sources, const std::vector< test_event_entry > &events, const block &blk_head, const cryptonote::account_base &from, uint64_t amount, size_t nmix)
Definition chaingen.cpp:396
void fill_tx_destinations(const var_addr_t &from, const std::vector< tx_destination_entry > &dests, uint64_t fee, const std::vector< tx_source_entry > &sources, std::vector< tx_destination_entry > &destinations, bool always_change)
Definition chaingen.cpp:720
Here is the call graph for this function:

◆ construct_tx_to_key() [3/4]

bool construct_tx_to_key ( cryptonote::transaction & tx,
const cryptonote::account_base & from,
const std::vector< cryptonote::tx_destination_entry > & destinations,
std::vector< cryptonote::tx_source_entry > & sources,
uint64_t fee,
bool rct,
rct::RangeProofType range_proof_type,
int bp_version )

Definition at line 909 of file chaingen.cpp.

914{
915 vector<tx_destination_entry> all_destinations;
916 fill_tx_destinations(from, destinations, fee, sources, all_destinations, rct);
917 return construct_tx_rct(from.get_keys(), sources, all_destinations, get_address(from), std::vector<uint8_t>(), tx, 0, rct, range_proof_type, bp_version);
918}
Here is the call graph for this function:

◆ construct_tx_to_key() [4/4]

bool construct_tx_to_key ( cryptonote::transaction & tx,
const cryptonote::account_base & from,
const var_addr_t & to,
uint64_t amount,
std::vector< cryptonote::tx_source_entry > & sources,
uint64_t fee,
bool rct,
rct::RangeProofType range_proof_type,
int bp_version )

Definition at line 899 of file chaingen.cpp.

903{
904 vector<tx_destination_entry> destinations;
905 fill_tx_destinations(from, get_address(to), amount, fee, sources, destinations, rct);
906 return construct_tx_rct(from.get_keys(), sources, destinations, get_address(from), std::vector<uint8_t>(), tx, 0, rct, range_proof_type, bp_version);
907}
Here is the call graph for this function:

◆ construct_tx_with_fee()

transaction construct_tx_with_fee ( std::vector< test_event_entry > & events,
const block & blk_head,
const account_base & acc_from,
const var_addr_t & to,
uint64_t amount,
uint64_t fee )

Definition at line 931 of file chaingen.cpp.

933{
934 transaction tx;
935 construct_tx_to_key(events, tx, blk_head, acc_from, to, amount, fee, 0);
936 events.push_back(tx);
937 return tx;
938}
bool construct_tx_to_key(const std::vector< test_event_entry > &events, cryptonote::transaction &tx, const cryptonote::block &blk_head, const cryptonote::account_base &from, const var_addr_t &to, uint64_t amount, uint64_t fee, size_t nmix, bool rct, rct::RangeProofType range_proof_type, int bp_version)
Definition chaingen.cpp:872
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dump_data()

std::string dump_data ( const cryptonote::transaction & tx)

Definition at line 617 of file chaingen.cpp.

618{
619 ostringstream ss;
620 ss << "msg: " << dump_keys(tx.rct_signatures.message.bytes)
621 << ", vin: ";
622
623 for(auto & in : tx.vin){
624 if (typeid(txin_to_key) == in.type()){
625 auto tk = boost::get<txin_to_key>(in);
626 std::vector<uint64_t> full_off;
627 int64_t last = -1;
628
629 ss << " i: " << tk.amount << " [";
630 for(auto ix : tk.key_offsets){
631 ss << ix << ", ";
632 if (last == -1){
633 last = ix;
634 full_off.push_back(ix);
635 } else {
636 last += ix;
637 full_off.push_back((uint64_t)last);
638 }
639 }
640
641 ss << "], full: [";
642 for(auto ix : full_off){
643 ss << ix << ", ";
644 }
645 ss << "]; ";
646
647 } else if (typeid(txin_gen) == in.type()){
648 ss << " h: " << boost::get<txin_gen>(in).height << ", ";
649 } else {
650 ss << " ?, ";
651 }
652 }
653
654 ss << ", mixring: \n";
655 for (const auto & row : tx.rct_signatures.mixRing){
656 for(auto cur : row){
657 ss << " (" << dump_keys(cur.dest.bytes) << ", " << dump_keys(cur.mask.bytes) << ")\n ";
658 }
659 ss << "; ";
660 }
661
662 return ss.str();
663}
std::string dump_keys(T *buff32)
Definition chaingen.h:271
signed __int64 int64_t
Definition stdint.h:135
unsigned char bytes[32]
Definition rctTypes.h:86
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_hard_forks()

bool extract_hard_forks ( const std::vector< test_event_entry > & events,
v_hardforks_t & hard_forks )

Definition at line 966 of file chaingen.cpp.

967{
968 for(auto & ev : events)
969 {
970 if (typeid(event_replay_settings) == ev.type())
971 {
972 const auto & rep_settings = boost::get<event_replay_settings>(ev);
973 if (rep_settings.hard_forks)
974 {
975 const auto & hf = rep_settings.hard_forks.get();
976 std::copy(hf.begin(), hf.end(), std::back_inserter(hard_forks));
977 }
978 }
979 }
980
981 return !hard_forks.empty();
982}
Here is the caller graph for this function:

◆ fill_nonce()

void fill_nonce ( cryptonote::block & blk,
const difficulty_type & diffic,
uint64_t height )

Definition at line 797 of file chaingen.cpp.

798{
799 blk.nonce = 0;
800 while (!miner::find_nonce_for_given_block(blk, diffic, height))
801 blk.timestamp++;
802}
static bool find_nonce_for_given_block(block &bl, const difficulty_type &diffic, uint64_t height)
Definition miner.cpp:478
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fill_output_entries()

bool fill_output_entries ( std::vector< output_index > & out_indices,
size_t sender_out,
size_t nmix,
size_t & real_entry_idx,
std::vector< tx_source_entry::output_entry > & output_entries )

Definition at line 359 of file chaingen.cpp.

360{
361 if (out_indices.size() <= nmix)
362 return false;
363
364 bool sender_out_found = false;
365 size_t rest = nmix;
366 for (size_t i = 0; i < out_indices.size() && (0 < rest || !sender_out_found); ++i)
367 {
368 const output_index& oi = out_indices[i];
369 if (oi.spent)
370 continue;
371
372 bool append = false;
373 if (i == sender_out)
374 {
375 append = true;
376 sender_out_found = true;
377 real_entry_idx = output_entries.size();
378 }
379 else if (0 < rest)
380 {
381 --rest;
382 append = true;
383 }
384
385 if (append)
386 {
387 rct::key comm = oi.commitment();
388 const txout_to_key& otk = boost::get<txout_to_key>(oi.out);
389 output_entries.push_back(tx_source_entry::output_entry(oi.idx, rct::ctkey({rct::pk2rct(otk.key), comm})));
390 }
391 }
392
393 return 0 == rest && sender_out_found;
394}
std::pair< uint64_t, rct::ctkey > output_entry
rct::key commitment() const
Definition chaingen.h:323
const cryptonote::txout_target_v out
Definition chaingen.h:289
size_t idx
Definition chaingen.h:294
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fill_tx_destination()

bool fill_tx_destination ( tx_destination_entry & de,
const cryptonote::account_public_address & to,
uint64_t amount )

Definition at line 456 of file chaingen.cpp.

456 {
457 de.addr = to;
458 de.amount = amount;
459 return true;
460}
Here is the caller graph for this function:

◆ fill_tx_destinations() [1/3]

void fill_tx_destinations ( const var_addr_t & from,
const cryptonote::account_public_address & to,
uint64_t amount,
uint64_t fee,
const std::vector< tx_source_entry > & sources,
std::vector< tx_destination_entry > & destinations,
bool always_change )

Definition at line 766 of file chaingen.cpp.

770{
771 std::vector<tx_destination_entry> destinations_pure;
772 fill_tx_destinations(from, to, amount, fee, sources, destinations, destinations_pure, always_change);
773}
Here is the call graph for this function:

◆ fill_tx_destinations() [2/3]

void fill_tx_destinations ( const var_addr_t & from,
const cryptonote::account_public_address & to,
uint64_t amount,
uint64_t fee,
const std::vector< tx_source_entry > & sources,
std::vector< tx_destination_entry > & destinations,
std::vector< tx_destination_entry > & destinations_pure,
bool always_change )

Definition at line 741 of file chaingen.cpp.

747{
748 destinations.clear();
749
751 if (!fill_tx_destination(de, to, amount))
752 throw std::runtime_error("couldn't fill transaction destination");
753 destinations.push_back(de);
754 destinations_pure.push_back(de);
755
756 tx_destination_entry de_change;
757 uint64_t cache_back = get_inputs_amount(sources) - (amount + fee);
758
759 if (cache_back > 0 || always_change) {
760 if (!fill_tx_destination(de_change, get_address(from), cache_back <= 0 ? 0 : cache_back))
761 throw std::runtime_error("couldn't fill transaction cache back destination");
762 destinations.push_back(de_change);
763 }
764}
bool fill_tx_destination(tx_destination_entry &de, const cryptonote::account_public_address &to, uint64_t amount)
Definition chaingen.cpp:456
Here is the call graph for this function:

◆ fill_tx_destinations() [3/3]

void fill_tx_destinations ( const var_addr_t & from,
const std::vector< tx_destination_entry > & dests,
uint64_t fee,
const std::vector< tx_source_entry > & sources,
std::vector< tx_destination_entry > & destinations,
bool always_change )

Definition at line 720 of file chaingen.cpp.

726{
727 destinations.clear();
728 uint64_t amount = sum_amount(dests);
729 std::copy(dests.begin(), dests.end(), std::back_inserter(destinations));
730
731 tx_destination_entry de_change;
732 uint64_t cache_back = get_inputs_amount(sources) - (amount + fee);
733
734 if (cache_back > 0 || always_change) {
735 if (!fill_tx_destination(de_change, get_address(from), cache_back <= 0 ? 0 : cache_back))
736 throw std::runtime_error("couldn't fill transaction cache back destination");
737 destinations.push_back(de_change);
738 }
739}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fill_tx_sources()

bool fill_tx_sources ( std::vector< tx_source_entry > & sources,
const std::vector< test_event_entry > & events,
const block & blk_head,
const cryptonote::account_base & from,
uint64_t amount,
size_t nmix )

Definition at line 396 of file chaingen.cpp.

398{
399 map_output_idx_t outs;
400 map_output_t outs_mine;
401
402 std::vector<cryptonote::block> blockchain;
403 map_hash2tx_t mtx;
404 if (!find_block_chain(events, blockchain, mtx, get_block_hash(blk_head)))
405 return false;
406
407 if (!init_output_indices(outs, outs_mine, blockchain, mtx, from))
408 return false;
409
410 if (!init_spent_output_indices(outs, outs_mine, blockchain, mtx, from))
411 return false;
412
413 // Iterate in reverse is more efficiency
414 uint64_t sources_amount = 0;
415 bool sources_found = false;
416 BOOST_REVERSE_FOREACH(const map_output_t::value_type o, outs_mine)
417 {
418 for (size_t i = 0; i < o.second.size() && !sources_found; ++i)
419 {
420 size_t sender_out = o.second[i];
421 const output_index& oi = outs[o.first][sender_out];
422 if (oi.spent)
423 continue;
424 if (oi.rct)
425 continue;
426
428 ts.amount = oi.amount;
430 ts.real_out_tx_key = get_tx_pub_key_from_extra(*oi.p_tx); // incoming tx public key
431 size_t realOutput;
432 if (!fill_output_entries(outs[o.first], sender_out, nmix, realOutput, ts.outputs))
433 continue;
434
435 ts.real_output = realOutput;
436 ts.rct = false;
437 ts.mask = rct::identity(); // non-rct has identity mask by definition
438
440 for(auto & ot : ts.outputs)
441 ot.second.mask = comm;
442
443 sources.push_back(ts);
444
445 sources_amount += ts.amount;
446 sources_found = amount <= sources_amount;
447 }
448
449 if (sources_found)
450 break;
451 }
452
453 return sources_found;
454}
bool find_block_chain(const std::vector< test_event_entry > &events, std::vector< cryptonote::block > &blockchain, map_hash2tx_t &mtx, const crypto::hash &head)
bool init_spent_output_indices(map_output_idx_t &outs, map_output_t &outs_mine, const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx, const cryptonote::account_base &from)
Definition chaingen.cpp:327
bool init_output_indices(map_output_idx_t &outs, std::map< uint64_t, std::vector< size_t > > &outs_mine, const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx, const cryptonote::account_base &from)
Definition chaingen.cpp:284
bool fill_output_entries(std::vector< output_index > &out_indices, size_t sender_out, size_t nmix, size_t &real_entry_idx, std::vector< tx_source_entry::output_entry > &output_entries)
Definition chaingen.cpp:359
std::unordered_map< crypto::hash, const cryptonote::transaction * > map_hash2tx_t
Definition chaingen.h:163
std::map< uint64_t, std::vector< output_index > > map_output_idx_t
Definition chaingen.h:356
std::map< uint64_t, std::vector< size_t > > map_output_t
Definition chaingen.h:355
bool get_block_hash(const block &b, crypto::hash &res)
crypto::public_key get_tx_pub_key_from_extra(const std::vector< uint8_t > &tx_extra, size_t pk_index)
key zeroCommit(etn_amount amount)
Definition rctOps.cpp:322
key identity()
Definition rctOps.h:73
crypto::public_key real_out_tx_key
uint64_t amount
bool rct
size_t real_output
std::vector< output_entry > outputs
rct::key mask
size_t real_output_in_tx_index
uint64_t amount
Definition chaingen.h:290
const cryptonote::transaction * p_tx
Definition chaingen.h:301
size_t out_no
Definition chaingen.h:293
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fill_tx_sources_and_destinations() [1/2]

void fill_tx_sources_and_destinations ( const std::vector< test_event_entry > & events,
const block & blk_head,
const cryptonote::account_base & from,
const cryptonote::account_base & to,
uint64_t amount,
uint64_t fee,
size_t nmix,
std::vector< tx_source_entry > & sources,
std::vector< tx_destination_entry > & destinations )

Definition at line 789 of file chaingen.cpp.

793{
794 fill_tx_sources_and_destinations(events, blk_head, from, to.get_keys().m_account_address, amount, fee, nmix, sources, destinations);
795}
Here is the call graph for this function:

◆ fill_tx_sources_and_destinations() [2/2]

void fill_tx_sources_and_destinations ( const std::vector< test_event_entry > & events,
const block & blk_head,
const cryptonote::account_base & from,
const cryptonote::account_public_address & to,
uint64_t amount,
uint64_t fee,
size_t nmix,
std::vector< tx_source_entry > & sources,
std::vector< tx_destination_entry > & destinations )

Definition at line 775 of file chaingen.cpp.

779{
780 sources.clear();
781 destinations.clear();
782
783 if (!fill_tx_sources(sources, events, blk_head, from, amount + fee, nmix))
784 throw std::runtime_error("couldn't fill transaction sources");
785
786 fill_tx_destinations(from, to, amount, fee, sources, destinations, false);
787}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_block_chain() [1/2]

bool find_block_chain ( const std::vector< test_event_entry > & events,
std::vector< const cryptonote::block * > & blockchain,
map_hash2tx_t & mtx,
const crypto::hash & head )

Definition at line 1105 of file chaingen.cpp.

1105 {
1106 std::unordered_map<crypto::hash, const block*> block_index;
1107 BOOST_FOREACH(const test_event_entry& ev, events)
1108 {
1109 if (typeid(block) == ev.type())
1110 {
1111 const block* blk = &boost::get<block>(ev);
1112 block_index[get_block_hash(*blk)] = blk;
1113 }
1114 else if (typeid(transaction) == ev.type())
1115 {
1116 const transaction& tx = boost::get<transaction>(ev);
1117 mtx[get_transaction_hash(tx)] = &tx;
1118 }
1119 }
1120
1121 bool b_success = false;
1122 crypto::hash id = head;
1123 for (auto it = block_index.find(id); block_index.end() != it; it = block_index.find(id))
1124 {
1125 blockchain.push_back(it->second);
1126 id = it->second->prev_id;
1127 if (null_hash == id)
1128 {
1129 b_success = true;
1130 break;
1131 }
1132 }
1133 reverse(blockchain.begin(), blockchain.end());
1134 return b_success;
1135}
boost::variant< cryptonote::block, cryptonote::transaction, std::vector< cryptonote::transaction >, cryptonote::account_base, callback_entry, serialized_block, serialized_transaction, event_visitor_settings, event_replay_settings > test_event_entry
Definition chaingen.h:162
POD_CLASS hash
Definition hash.h:50
crypto::hash get_transaction_hash(const transaction &t)
struct rule_list head
Here is the call graph for this function:

◆ find_block_chain() [2/2]

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 at line 1072 of file chaingen.cpp.

1072 {
1073 std::unordered_map<crypto::hash, const block*> block_index;
1074 BOOST_FOREACH(const test_event_entry& ev, events)
1075 {
1076 if (typeid(block) == ev.type())
1077 {
1078 const block* blk = &boost::get<block>(ev);
1079 block_index[get_block_hash(*blk)] = blk;
1080 }
1081 else if (typeid(transaction) == ev.type())
1082 {
1083 const transaction& tx = boost::get<transaction>(ev);
1084 mtx[get_transaction_hash(tx)] = &tx;
1085 }
1086 }
1087
1088 bool b_success = false;
1089 crypto::hash id = head;
1090 for (auto it = block_index.find(id); block_index.end() != it; it = block_index.find(id))
1091 {
1092 blockchain.push_back(*it->second);
1093 id = it->second->prev_id;
1094 if (null_hash == id)
1095 {
1096 b_success = true;
1097 break;
1098 }
1099 }
1100 reverse(blockchain.begin(), blockchain.end());
1101
1102 return b_success;
1103}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_address() [1/5]

Definition at line 690 of file chaingen.cpp.

691{
692 return inp.get_keys().m_account_address;
693}
const char * inp

◆ get_address() [2/5]

Definition at line 685 of file chaingen.cpp.

686{
687 return inp.m_account_address;
688}

◆ get_address() [3/5]

Definition at line 680 of file chaingen.cpp.

681{
682 return inp;
683}

◆ get_address() [4/5]

Definition at line 695 of file chaingen.cpp.

696{
697 return inp.addr;
698}

◆ get_address() [5/5]

cryptonote::account_public_address get_address ( const var_addr_t & inp)

Definition at line 665 of file chaingen.cpp.

666{
667 if (typeid(cryptonote::account_public_address) == inp.type()){
668 return boost::get<cryptonote::account_public_address>(inp);
669 } else if(typeid(cryptonote::account_keys) == inp.type()){
670 return boost::get<cryptonote::account_keys>(inp).m_account_address;
671 } else if (typeid(cryptonote::account_base) == inp.type()){
672 return boost::get<cryptonote::account_base>(inp).get_keys().m_account_address;
673 } else if (typeid(cryptonote::tx_destination_entry) == inp.type()){
674 return boost::get<cryptonote::tx_destination_entry>(inp).addr;
675 } else {
676 throw std::runtime_error("Unexpected type");
677 }
678}
Here is the caller graph for this function:

◆ get_balance()

uint64_t get_balance ( const cryptonote::account_base & addr,
const std::vector< cryptonote::block > & blockchain,
const map_hash2tx_t & mtx )

Definition at line 940 of file chaingen.cpp.

940 {
941 uint64_t res = 0;
942 std::map<uint64_t, std::vector<output_index> > outs;
943 std::map<uint64_t, std::vector<size_t> > outs_mine;
944
945 map_hash2tx_t confirmed_txs;
946 get_confirmed_txs(blockchain, mtx, confirmed_txs);
947
948 if (!init_output_indices(outs, outs_mine, blockchain, confirmed_txs, addr))
949 return false;
950
951 if (!init_spent_output_indices(outs, outs_mine, blockchain, confirmed_txs, addr))
952 return false;
953
954 BOOST_FOREACH (const map_output_t::value_type &o, outs_mine) {
955 for (size_t i = 0; i < o.second.size(); ++i) {
956 if (outs[o.first][o.second[i]].spent)
957 continue;
958
959 res += outs[o.first][o.second[i]].amount;
960 }
961 }
962
963 return res;
964}
void get_confirmed_txs(const std::vector< cryptonote::block > &blockchain, const map_hash2tx_t &mtx, map_hash2tx_t &confirmed_txs)
Definition chaingen.cpp:984
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_confirmed_txs()

void get_confirmed_txs ( const std::vector< cryptonote::block > & blockchain,
const map_hash2tx_t & mtx,
map_hash2tx_t & confirmed_txs )

Definition at line 984 of file chaingen.cpp.

985{
986 std::unordered_set<crypto::hash> confirmed_hashes;
987 BOOST_FOREACH(const block& blk, blockchain)
988 {
989 BOOST_FOREACH(const crypto::hash& tx_hash, blk.tx_hashes)
990 {
991 confirmed_hashes.insert(tx_hash);
992 }
993 }
994
995 BOOST_FOREACH(const auto& tx_pair, mtx)
996 {
997 if (0 != confirmed_hashes.count(tx_pair.first))
998 {
999 confirmed_txs.insert(tx_pair);
1000 }
1001 }
1002}
std::vector< crypto::hash > tx_hashes
Here is the caller graph for this function:

◆ get_head_block()

cryptonote::block get_head_block ( const std::vector< test_event_entry > & events)

Definition at line 1058 of file chaingen.cpp.

1059{
1060 for(auto it = events.rbegin(); it != events.rend(); ++it)
1061 {
1062 auto &ev = *it;
1063 if (typeid(block) == ev.type())
1064 {
1065 return boost::get<block>(ev);
1066 }
1067 }
1068
1069 throw std::runtime_error("No block event");
1070}
Here is the caller graph for this function:

◆ init_output_indices()

bool init_output_indices ( map_output_idx_t & outs,
std::map< uint64_t, std::vector< size_t > > & outs_mine,
const std::vector< cryptonote::block > & blockchain,
const map_hash2tx_t & mtx,
const cryptonote::account_base & from )

Definition at line 284 of file chaingen.cpp.

284 {
285
286 BOOST_FOREACH (const block& blk, blockchain) {
287 vector<const transaction*> vtx;
288 vtx.push_back(&blk.miner_tx);
289
290 BOOST_FOREACH(const crypto::hash &h, blk.tx_hashes) {
291 const map_hash2tx_t::const_iterator cit = mtx.find(h);
292 if (mtx.end() == cit)
293 throw std::runtime_error("block contains an unknown tx hash");
294
295 vtx.push_back(cit->second);
296 }
297
298 //vtx.insert(vtx.end(), blk.);
299 // TODO: add all other txes
300 for (size_t i = 0; i < vtx.size(); i++) {
301 const transaction &tx = *vtx[i];
302
303 for (size_t j = 0; j < tx.vout.size(); ++j) {
304 const tx_out &out = tx.vout[j];
305
306 output_index oi(out.target, out.amount, boost::get<txin_gen>(*blk.miner_tx.vin.begin()).height, i, j, &blk, vtx[i]);
307 oi.set_rct(tx.version == 4);
308 oi.unlock_time = tx.unlock_time;
309 oi.is_coin_base = i == 0;
310
311 if (2 == out.target.which()) { // out_to_key
312 outs[out.amount].push_back(oi);
313 size_t tx_global_idx = outs[out.amount].size() - 1;
314 outs[out.amount][tx_global_idx].idx = tx_global_idx;
315 // Is out to me?
316 if (is_out_to_acc(from.get_keys(), boost::get<txout_to_key>(out.target), get_tx_pub_key_from_extra(tx), get_additional_tx_pub_keys_from_extra(tx), j)) {
317 outs_mine[out.amount].push_back(tx_global_idx);
318 }
319 }
320 }
321 }
322 }
323
324 return true;
325}
bool is_out_to_acc(const account_keys &acc, const txout_to_key &out_key, const crypto::public_key &tx_pub_key, const std::vector< crypto::public_key > &additional_tx_pub_keys, size_t output_index)
std::vector< crypto::public_key > get_additional_tx_pub_keys_from_extra(const std::vector< uint8_t > &tx_extra)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_spent_output_indices()

bool init_spent_output_indices ( map_output_idx_t & outs,
map_output_t & outs_mine,
const std::vector< cryptonote::block > & blockchain,
const map_hash2tx_t & mtx,
const cryptonote::account_base & from )

Definition at line 327 of file chaingen.cpp.

327 {
328
329 BOOST_FOREACH (const map_output_t::value_type &o, outs_mine) {
330 for (size_t i = 0; i < o.second.size(); ++i) {
331 output_index &oi = outs[o.first][o.second[i]];
332
333 // construct key image for this output
335 keypair in_ephemeral;
336 crypto::public_key out_key = boost::get<txout_to_key>(oi.out).key;
337 std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
338 subaddresses[from.get_keys().m_account_address.m_spend_public_key] = {0,0};
339 generate_key_image_helper(from.get_keys(), subaddresses, out_key, get_tx_pub_key_from_extra(*oi.p_tx), get_additional_tx_pub_keys_from_extra(*oi.p_tx), oi.out_no, in_ephemeral, img, hw::get_device(("default")));
340
341 // lookup for this key image in the events vector
342 BOOST_FOREACH(auto& tx_pair, mtx) {
343 const transaction& tx = *tx_pair.second;
344 BOOST_FOREACH(const txin_v &in, tx.vin) {
345 if (typeid(txin_to_key) == in.type()) {
346 const txin_to_key &itk = boost::get<txin_to_key>(in);
347 if (itk.k_image == img) {
348 oi.spent = true;
349 }
350 }
351 }
352 }
353 }
354 }
355
356 return true;
357}
POD_CLASS key_image
Definition crypto.h:105
bool generate_key_image_helper(const account_keys &ack, const std::unordered_map< crypto::public_key, subaddress_index > &subaddresses, const crypto::public_key &out_key, const crypto::public_key &tx_public_key, const std::vector< crypto::public_key > &additional_tx_public_keys, size_t real_output_index, keypair &in_ephemeral, crypto::key_image &ki, hw::device &hwdev, const uint32_t account_major_offset)
boost::variant< txin_gen, txin_to_script, txin_to_scripthash, txin_to_key, txin_to_key_public > txin_v
crypto::key_image k_image
Here is the call graph for this function:
Here is the caller graph for this function:

◆ num_blocks()

uint64_t num_blocks ( const std::vector< test_event_entry > & events)

Definition at line 1044 of file chaingen.cpp.

1045{
1046 uint64_t res = 0;
1047 BOOST_FOREACH(const test_event_entry& ev, events)
1048 {
1049 if (typeid(block) == ev.type())
1050 {
1051 res += 1;
1052 }
1053 }
1054
1055 return res;
1056}
Here is the caller graph for this function:

◆ sum_amount() [1/2]

uint64_t sum_amount ( const std::vector< cryptonote::tx_source_entry > & sources)

Definition at line 710 of file chaingen.cpp.

711{
712 uint64_t amount = 0;
713 for(auto & cur : sources){
714 amount += cur.amount;
715 }
716
717 return amount;
718}

◆ sum_amount() [2/2]

uint64_t sum_amount ( const std::vector< tx_destination_entry > & destinations)

Definition at line 700 of file chaingen.cpp.

701{
702 uint64_t amount = 0;
703 for(auto & cur : destinations){
704 amount += cur.amount;
705 }
706
707 return amount;
708}
Here is the caller graph for this function:

◆ trim_block_chain() [1/2]

bool trim_block_chain ( std::vector< const cryptonote::block * > & blockchain,
const crypto::hash & tail )

Definition at line 1024 of file chaingen.cpp.

1024 {
1025 size_t cut = 0;
1026 bool found = true;
1027
1028 for(size_t i = 0; i < blockchain.size(); ++i){
1029 crypto::hash chash = get_block_hash(*blockchain[i]);
1030 if (chash == tail){
1031 cut = i;
1032 found = true;
1033 break;
1034 }
1035 }
1036
1037 if (found && cut > 0){
1038 blockchain.erase(blockchain.begin(), blockchain.begin() + cut);
1039 }
1040
1041 return found;
1042}
crypto::hash chash
Definition main.cpp:47
Here is the call graph for this function:

◆ trim_block_chain() [2/2]

bool trim_block_chain ( std::vector< cryptonote::block > & blockchain,
const crypto::hash & tail )

Definition at line 1004 of file chaingen.cpp.

1004 {
1005 size_t cut = 0;
1006 bool found = true;
1007
1008 for(size_t i = 0; i < blockchain.size(); ++i){
1009 crypto::hash chash = get_block_hash(blockchain[i]);
1010 if (chash == tail){
1011 cut = i;
1012 found = true;
1013 break;
1014 }
1015 }
1016
1017 if (found && cut > 0){
1018 blockchain.erase(blockchain.begin(), blockchain.begin() + cut);
1019 }
1020
1021 return found;
1022}
Here is the call graph for this function:
Here is the caller graph for this function: