Electroneum
cryptonote_tx_utils.h
Go to the documentation of this file.
1 // Copyrights(c) 2017-2019, The Electroneum Project
2 // Copyrights(c) 2014-2017, 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 #pragma once
34 #include <boost/serialization/vector.hpp>
35 #include <boost/serialization/utility.hpp>
36 #include "ringct/rctOps.h"
37 
38 namespace cryptonote
39 {
40  //---------------------------------------------------------------
41  bool construct_miner_tx(size_t height, size_t median_size, uint64_t already_generated_coins, size_t current_block_size, 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, bool testnet = false);
42 
44  {
45  typedef std::pair<uint64_t, rct::ctkey> output_entry;
46 
47  std::vector<output_entry> outputs; //index + key + optional ringct commitment
48  size_t real_output; //index in outputs vector of real output_entry
49  crypto::public_key real_out_tx_key; //incoming real tx public key
50  std::vector<crypto::public_key> real_out_additional_tx_keys; //incoming real tx additional public keys
51  size_t real_output_in_tx_index; //index in transaction outputs vector
52  uint64_t amount; //money
53  bool rct; //true if the output is rct
54  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)
67 
68  if (real_output >= outputs.size())
69  return false;
71  };
72 
74  {
75  uint64_t amount; //money
76  account_public_address addr; //destination address
77 
78  tx_destination_entry() : amount(0), addr(AUTO_VAL_INIT(addr)) { }
79  tx_destination_entry(uint64_t a, const account_public_address &ad) : amount(a), addr(ad) { }
80 
83  FIELD(addr)
85  };
86 
87  //---------------------------------------------------------------
88  crypto::public_key get_destination_view_key_pub(const std::vector<tx_destination_entry> &destinations, const account_keys &sender_keys);
89  bool construct_tx(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, std::vector<uint8_t> extra, transaction& tx, uint64_t unlock_time);
90  bool construct_tx_and_get_tx_key(const account_keys& sender_account_keys, const std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, std::vector<uint8_t> extra, transaction& tx, uint64_t unlock_time, crypto::secret_key &tx_key, bool rct = false);
91 
93  block& bl
94  , std::string const & genesis_tx
95  , uint32_t nonce
96  );
97 
98 }
99 
101 
102 namespace boost
103 {
104  namespace serialization
105  {
106  template <class Archive>
107  inline void serialize(Archive &a, cryptonote::tx_source_entry &x, const boost::serialization::version_type ver)
108  {
109  a & x.outputs;
110  a & x.real_output;
111  a & x.real_out_tx_key;
113  a & x.amount;
114  a & x.rct;
115  a & x.mask;
116  }
117  }
118 }
Definition: binary_utils.h:37
crypto::public_key real_out_tx_key
Definition: cryptonote_tx_utils.h:49
Definition: unordered_containers_boost_serialization.h:38
Definition: cryptonote_basic.h:382
Definition: rctTypes.h:100
uint64_t height
Definition: blockchain.cpp:87
crypto namespace.
Definition: crypto.cpp:47
Definition: block_queue.cpp:41
Definition: rctOps.cpp:41
bool rct
Definition: cryptonote_tx_utils.h:53
uint64_t amount
Definition: cryptonote_tx_utils.h:52
size_t real_output
Definition: cryptonote_tx_utils.h:48
key zeroCommit(xmr_amount amount)
Definition: rctOps.cpp:134
#define END_SERIALIZE()
self-explanatory
Definition: serialization.h:207
static const rct::key pk2rct(const crypto::public_key &pk)
Definition: rctTypes.h:428
BOOST_CLASS_VERSION(nodetool::node_server< cryptonote::t_cryptonote_protocol_handler< cryptonote::core > >, 1)
Holds cryptonote related classes and helpers.
Definition: db_bdb.cpp:225
tx_destination_entry(uint64_t a, const account_public_address &ad)
Definition: cryptonote_tx_utils.h:79
crypto::public_key get_destination_view_key_pub(const std::vector< tx_destination_entry > &destinations, const account_keys &sender_keys)
Definition: cryptonote_tx_utils.cpp:141
bool generate_genesis_block(block &bl, std::string const &genesis_tx, uint32_t nonce)
Definition: cryptonote_tx_utils.cpp:352
Definition: cryptonote_tx_utils.h:43
bool construct_tx(const account_keys &sender_account_keys, const std::vector< tx_source_entry > &sources, const std::vector< tx_destination_entry > &destinations, std::vector< uint8_t > extra, transaction &tx, uint64_t unlock_time)
Definition: cryptonote_tx_utils.cpp:346
Definition: rctTypes.h:82
#define BEGIN_SERIALIZE_OBJECT()
begins the environment of the DSL for described the serialization of an object
Definition: serialization.h:188
uint64_t amount
Definition: cryptonote_tx_utils.h:75
#define false
Definition: stdbool.h:38
Definition: account.h:41
bool construct_miner_tx(size_t height, size_t median_size, uint64_t already_generated_coins, size_t current_block_size, uint64_t fee, const account_public_address &miner_address, transaction &tx, const blobdata &extra_nonce, size_t max_outs, uint8_t hard_fork_version, bool testnet)
Definition: cryptonote_tx_utils.cpp:45
void serialize(Archive &a, cryptonote::tx_source_entry &x, const boost::serialization::version_type ver)
Definition: cryptonote_tx_utils.h:107
POD_CLASS public_key
Definition: crypto.h:65
void push_output(uint64_t idx, const crypto::public_key &k, uint64_t amount)
Definition: cryptonote_tx_utils.h:56
account_public_address addr
Definition: cryptonote_tx_utils.h:76
std::string blobdata
Definition: blobdatatype.h:36
Definition: cryptonote_basic.h:421
tx_destination_entry()
Definition: cryptonote_tx_utils.h:78
std::vector< crypto::public_key > real_out_additional_tx_keys
Definition: cryptonote_tx_utils.h:50
#define VARINT_FIELD(f)
tags and serializes the varint f
Definition: serialization.h:256
POD_CLASS secret_key
Definition: crypto.h:69
size_t real_output_in_tx_index
Definition: cryptonote_tx_utils.h:51
string a
Definition: MakeCryptoOps.py:15
bool construct_tx_and_get_tx_key(const account_keys &sender_account_keys, const std::vector< tx_source_entry > &sources, const std::vector< tx_destination_entry > &destinations, std::vector< uint8_t > extra, transaction &tx, uint64_t unlock_time, crypto::secret_key &tx_key, bool rct)
Definition: cryptonote_tx_utils.cpp:157
if(real_output >=outputs.size()) return false
std::vector< output_entry > outputs
Definition: cryptonote_tx_utils.h:47
Definition: cryptonote_tx_utils.h:73
std::pair< uint64_t, rct::ctkey > output_entry
Definition: cryptonote_tx_utils.h:45
#define FIELD(f)
tags the field with the variable name and then serializes it
Definition: serialization.h:236
Definition: cryptonote_basic.h:198
rct::key mask
Definition: cryptonote_tx_utils.h:54