Monero
cryptonote_tx_utils.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2018, 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 #pragma once
33 #include <boost/serialization/vector.hpp>
34 #include <boost/serialization/utility.hpp>
35 #include "ringct/rctOps.h"
36 
37 namespace cryptonote
38 {
39  //---------------------------------------------------------------
40  bool construct_miner_tx(size_t height, size_t median_weight, uint64_t already_generated_coins, size_t current_block_weight, uint64_t fee, const account_public_address &miner_address, transaction& tx, const blobdata& extra_nonce = blobdata(), size_t max_outs = 999, uint8_t hard_fork_version = 1);
41 
43  {
44  typedef std::pair<uint64_t, rct::ctkey> output_entry;
45 
46  std::vector<output_entry> outputs; //index + key + optional ringct commitment
47  size_t real_output; //index in outputs vector of real output_entry
48  crypto::public_key real_out_tx_key; //incoming real tx public key
49  std::vector<crypto::public_key> real_out_additional_tx_keys; //incoming real tx additional public keys
50  size_t real_output_in_tx_index; //index in transaction outputs vector
51  uint64_t amount; //money
52  bool rct; //true if the output is rct
53  rct::key mask; //ringct amount mask
55 
56  void push_output(uint64_t idx, const crypto::public_key &k, uint64_t amount) { outputs.push_back(std::make_pair(idx, rct::ctkey({rct::pk2rct(k), rct::zeroCommit(amount)}))); }
57 
59  FIELD(outputs)
64  FIELD(amount)
65  FIELD(rct)
66  FIELD(mask)
68 
69  if (real_output >= outputs.size())
70  return false;
72  };
73 
75  {
76  std::string original;
77  uint64_t amount; //money
78  account_public_address addr; //destination address
81 
82  tx_destination_entry() : amount(0), addr(AUTO_VAL_INIT(addr)), is_subaddress(false), is_integrated(false) { }
83  tx_destination_entry(uint64_t a, const account_public_address &ad, bool is_subaddress) : amount(a), addr(ad), is_subaddress(is_subaddress), is_integrated(false) { }
84  tx_destination_entry(const std::string &o, uint64_t a, const account_public_address &ad, bool is_subaddress) : original(o), amount(a), addr(ad), is_subaddress(is_subaddress), is_integrated(false) { }
85 
87  FIELD(original)
89  FIELD(addr)
90  FIELD(is_subaddress)
91  FIELD(is_integrated)
93  };
94 
95  //---------------------------------------------------------------
96  crypto::public_key get_destination_view_key_pub(const std::vector<tx_destination_entry> &destinations, const boost::optional<cryptonote::account_public_address>& change_addr);
97  bool construct_tx(const account_keys& sender_account_keys, std::vector<tx_source_entry> &sources, const std::vector<tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, std::vector<uint8_t> extra, transaction& tx, uint64_t unlock_time);
98  bool construct_tx_with_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, std::vector<uint8_t> extra, transaction& tx, uint64_t unlock_time, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, bool rct = false, const rct::RCTConfig &rct_config = { rct::RangeProofBorromean, 0 }, rct::multisig_out *msout = NULL, bool shuffle_outs = true);
99  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, 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 = false, const rct::RCTConfig &rct_config = { rct::RangeProofBorromean, 0 }, rct::multisig_out *msout = NULL);
100  bool generate_output_ephemeral_keys(const size_t tx_version, const cryptonote::account_keys &sender_account_keys, const crypto::public_key &txkey_pub, const crypto::secret_key &tx_key,
101  const cryptonote::tx_destination_entry &dst_entr, const boost::optional<cryptonote::account_public_address> &change_addr, const size_t output_index,
102  const bool &need_additional_txkeys, const std::vector<crypto::secret_key> &additional_tx_keys,
103  std::vector<crypto::public_key> &additional_tx_public_keys,
104  std::vector<rct::key> &amount_keys,
105  crypto::public_key &out_eph_public_key) ;
106 
108  block& bl
109  , std::string const & genesis_tx
110  , uint32_t nonce
111  );
112 
113 }
114 
116 BOOST_CLASS_VERSION(cryptonote::tx_destination_entry, 2)
117 
118 namespace boost
119 {
120  namespace serialization
121  {
122  template <class Archive>
123  inline void serialize(Archive &a, cryptonote::tx_source_entry &x, const boost::serialization::version_type ver)
124  {
125  a & x.outputs;
126  a & x.real_output;
127  a & x.real_out_tx_key;
129  a & x.amount;
130  a & x.rct;
131  a & x.mask;
132  if (ver < 1)
133  return;
134  a & x.multisig_kLRki;
136  }
137 
138  template <class Archive>
139  inline void serialize(Archive& a, cryptonote::tx_destination_entry& x, const boost::serialization::version_type ver)
140  {
141  a & x.amount;
142  a & x.addr;
143  if (ver < 1)
144  return;
145  a & x.is_subaddress;
146  if (ver < 2)
147  {
148  x.is_integrated = false;
149  return;
150  }
151  a & x.original;
152  a & x.is_integrated;
153  }
154  }
155 }
Definition: binary_utils.h:36
crypto::public_key real_out_tx_key
Definition: cryptonote_tx_utils.h:48
Definition: rctTypes.h:111
static const rct::key & pk2rct(const crypto::public_key &pk)
Definition: rctTypes.h:555
Definition: unordered_containers_boost_serialization.h:37
Definition: rctTypes.h:96
uint64_t height
Definition: blockchain.cpp:89
void serialize(Archive &a, cryptonote::tx_destination_entry &x, const boost::serialization::version_type ver)
Definition: cryptonote_tx_utils.h:139
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, 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)
Definition: cryptonote_tx_utils.cpp:604
crypto namespace.
Definition: crypto.cpp:59
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition: crypto.h:69
Definition: blockchain_ancestry.cpp:70
Definition: bulletproofs.cc:56
tx_destination_entry(const std::string &o, uint64_t a, const account_public_address &ad, bool is_subaddress)
Definition: cryptonote_tx_utils.h:84
bool rct
Definition: cryptonote_tx_utils.h:52
uint64_t amount
Definition: cryptonote_tx_utils.h:51
size_t real_output
Definition: cryptonote_tx_utils.h:47
Definition: rctTypes.h:104
key zeroCommit(xmr_amount amount)
Definition: rctOps.cpp:145
#define END_SERIALIZE()
self-explanatory
Definition: serialization.h:214
BOOST_CLASS_VERSION(nodetool::node_server< cryptonote::t_cryptonote_protocol_handler< cryptonote::core > >, 1)
Holds cryptonote related classes and helpers.
Definition: db_bdb.cpp:224
bool generate_genesis_block(block &bl, std::string const &genesis_tx, uint32_t nonce)
Definition: cryptonote_tx_utils.cpp:637
Definition: cryptonote_tx_utils.h:42
Definition: rctTypes.h:78
Definition: subaddress_index.h:38
#define BEGIN_SERIALIZE_OBJECT()
begins the environment of the DSL \detailed for described the serialization of an object
Definition: serialization.h:190
uint64_t amount
Definition: cryptonote_tx_utils.h:77
tx_destination_entry(uint64_t a, const account_public_address &ad, bool is_subaddress)
Definition: cryptonote_tx_utils.h:83
Definition: rctTypes.h:235
#define false
Definition: stdbool.h:37
bool is_subaddress
Definition: cryptonote_tx_utils.h:79
Definition: account.h:40
bool is_integrated
Definition: cryptonote_tx_utils.h:80
POD_CLASS public_key
Definition: crypto.h:63
void push_output(uint64_t idx, const crypto::public_key &k, uint64_t amount)
Definition: cryptonote_tx_utils.h:56
rct::multisig_kLRki multisig_kLRki
Definition: cryptonote_tx_utils.h:54
account_public_address addr
Definition: cryptonote_tx_utils.h:78
std::string blobdata
Definition: blobdatatype.h:35
Definition: cryptonote_basic.h:400
tx_destination_entry()
Definition: cryptonote_tx_utils.h:82
std::string original
Definition: cryptonote_tx_utils.h:76
std::vector< crypto::public_key > real_out_additional_tx_keys
Definition: cryptonote_tx_utils.h:49
crypto::public_key get_destination_view_key_pub(const std::vector< tx_destination_entry > &destinations, const boost::optional< cryptonote::account_public_address > &change_addr)
Definition: cryptonote_tx_utils.cpp:176
#define VARINT_FIELD(f)
tags and serializes the varint f
Definition: serialization.h:263
size_t real_output_in_tx_index
Definition: cryptonote_tx_utils.h:50
string a
Definition: MakeCryptoOps.py:15
if(real_output >=outputs.size()) return false
bool construct_tx(const account_keys &sender_account_keys, std::vector< tx_source_entry > &sources, const std::vector< tx_destination_entry > &destinations, const boost::optional< cryptonote::account_public_address > &change_addr, std::vector< uint8_t > extra, transaction &tx, uint64_t unlock_time)
Definition: cryptonote_tx_utils.cpp:627
std::vector< output_entry > outputs
Definition: cryptonote_tx_utils.h:46
Definition: rctTypes.h:236
Definition: cryptonote_tx_utils.h:74
bool generate_output_ephemeral_keys(const size_t tx_version, const cryptonote::account_keys &sender_account_keys, const crypto::public_key &txkey_pub, const crypto::secret_key &tx_key, const cryptonote::tx_destination_entry &dst_entr, const boost::optional< cryptonote::account_public_address > &change_addr, const size_t output_index, const bool &need_additional_txkeys, const std::vector< crypto::secret_key > &additional_tx_keys, std::vector< crypto::public_key > &additional_tx_public_keys, std::vector< rct::key > &amount_keys, crypto::public_key &out_eph_public_key)
std::pair< uint64_t, rct::ctkey > output_entry
Definition: cryptonote_tx_utils.h:44
#define FIELD(f)
tags the field with the variable name and then serializes it
Definition: serialization.h:243
bool construct_miner_tx(size_t height, size_t median_weight, uint64_t already_generated_coins, size_t current_block_weight, uint64_t fee, const account_public_address &miner_address, transaction &tx, const blobdata &extra_nonce, size_t max_outs, uint8_t hard_fork_version)
Definition: cryptonote_tx_utils.cpp:77
Definition: cryptonote_basic.h:182
bool construct_tx_with_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, std::vector< uint8_t > extra, transaction &tx, uint64_t unlock_time, const crypto::secret_key &tx_key, const std::vector< crypto::secret_key > &additional_tx_keys, bool rct, const rct::RCTConfig &rct_config, rct::multisig_out *msout, bool shuffle_outs)
Definition: cryptonote_tx_utils.cpp:198
rct::key mask
Definition: cryptonote_tx_utils.h:53