Monero
tx_extra.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
32 
33 
34 #define TX_EXTRA_PADDING_MAX_COUNT 255
35 #define TX_EXTRA_NONCE_MAX_COUNT 255
36 
37 #define TX_EXTRA_TAG_PADDING 0x00
38 #define TX_EXTRA_TAG_PUBKEY 0x01
39 #define TX_EXTRA_NONCE 0x02
40 #define TX_EXTRA_MERGE_MINING_TAG 0x03
41 #define TX_EXTRA_TAG_ADDITIONAL_PUBKEYS 0x04
42 #define TX_EXTRA_MYSTERIOUS_MINERGATE_TAG 0xDE
43 
44 #define TX_EXTRA_NONCE_PAYMENT_ID 0x00
45 #define TX_EXTRA_NONCE_ENCRYPTED_PAYMENT_ID 0x01
46 
47 namespace cryptonote
48 {
50  {
51  size_t size;
52 
53  // load
54  template <template <bool> class Archive>
55  bool do_serialize(Archive<false>& ar)
56  {
57  // size - 1 - because of variant tag
58  for (size = 1; size <= TX_EXTRA_PADDING_MAX_COUNT; ++size)
59  {
60  std::ios_base::iostate state = ar.stream().rdstate();
61  bool eof = EOF == ar.stream().peek();
62  ar.stream().clear(state);
63 
64  if (eof)
65  break;
66 
67  uint8_t zero;
68  if (!::do_serialize(ar, zero))
69  return false;
70 
71  if (0 != zero)
72  return false;
73  }
74 
76  }
77 
78  // store
79  template <template <bool> class Archive>
80  bool do_serialize(Archive<true>& ar)
81  {
83  return false;
84 
85  // i = 1 - because of variant tag
86  for (size_t i = 1; i < size; ++i)
87  {
88  uint8_t zero = 0;
89  if (!::do_serialize(ar, zero))
90  return false;
91  }
92  return true;
93  }
94  };
95 
97  {
99 
101  FIELD(pub_key)
102  END_SERIALIZE()
103  };
104 
106  {
107  std::string nonce;
108 
110  FIELD(nonce)
111  if(TX_EXTRA_NONCE_MAX_COUNT < nonce.size()) return false;
112  END_SERIALIZE()
113  };
114 
116  {
118  {
120 
121  serialize_helper(tx_extra_merge_mining_tag& mm_tag_) : mm_tag(mm_tag_)
122  {
123  }
124 
126  VARINT_FIELD_N("depth", mm_tag.depth)
127  FIELD_N("merkle_root", mm_tag.merkle_root)
128  END_SERIALIZE()
129  };
130 
131  size_t depth;
132  crypto::hash merkle_root;
133 
134  // load
135  template <template <bool> class Archive>
136  bool do_serialize(Archive<false>& ar)
137  {
138  std::string field;
139  if(!::do_serialize(ar, field))
140  return false;
141 
142  std::istringstream iss(field);
143  binary_archive<false> iar(iss);
144  serialize_helper helper(*this);
146  }
147 
148  // store
149  template <template <bool> class Archive>
150  bool do_serialize(Archive<true>& ar)
151  {
152  std::ostringstream oss;
153  binary_archive<true> oar(oss);
154  serialize_helper helper(*this);
155  if(!::do_serialize(oar, helper))
156  return false;
157 
158  std::string field = oss.str();
160  }
161  };
162 
163  // per-output additional tx pubkey for multi-destination transfers involving at least one subaddress
165  {
166  std::vector<crypto::public_key> data;
167 
169  FIELD(data)
170  END_SERIALIZE()
171  };
172 
174  {
175  std::string data;
176 
178  FIELD(data)
179  END_SERIALIZE()
180  };
181 
182  // tx_extra_field format, except tx_extra_padding and tx_extra_pub_key:
183  // varint tag;
184  // varint size;
185  // varint data[];
187 }
188 
#define TX_EXTRA_MYSTERIOUS_MINERGATE_TAG
Definition: tx_extra.h:42
std::vector< crypto::public_key > data
Definition: tx_extra.h:166
Definition: unordered_containers_boost_serialization.h:37
#define VARINT_FIELD_N(t, f)
tags (as t) and serializes the varint f
Definition: serialization.h:274
crypto::public_key pub_key
Definition: tx_extra.h:98
void serialize(Archive &a, std::unordered_map< h_key, hval > &x, const boost::serialization::version_type ver)
Definition: unordered_containers_boost_serialization.h:126
#define TX_EXTRA_PADDING_MAX_COUNT
Definition: tx_extra.h:34
crypto namespace.
Definition: crypto.cpp:59
Definition: tx_extra.h:49
Definition: binary_archive.h:180
size_t size
Definition: tx_extra.h:51
Definition: tx_extra.h:96
tx_extra_merge_mining_tag & mm_tag
Definition: tx_extra.h:119
#define END_SERIALIZE()
self-explanatory
Definition: serialization.h:214
bool do_serialize(Archive< false > &ar)
Definition: tx_extra.h:55
Holds cryptonote related classes and helpers.
Definition: db_bdb.cpp:224
void do_serialize(Archive &a, epee::net_utils::network_address &na, T local)
Definition: net_peerlist_boost_serialization.h:41
#define TX_EXTRA_NONCE_MAX_COUNT
Definition: tx_extra.h:35
static __thread int depth
Definition: threadpool.cpp:38
static const unsigned char zero[32]
Definition: fe_isnonzero.c:12
Definition: binary_archive.h:98
std::string nonce
Definition: tx_extra.h:107
#define TX_EXTRA_MERGE_MINING_TAG
Definition: tx_extra.h:40
bool do_serialize(Archive< true > &ar)
Definition: tx_extra.h:150
#define TX_EXTRA_TAG_PADDING
Definition: tx_extra.h:37
#define false
Definition: stdbool.h:37
POD_CLASS public_key
Definition: crypto.h:63
#define TX_EXTRA_TAG_PUBKEY
Definition: tx_extra.h:38
#define TX_EXTRA_TAG_ADDITIONAL_PUBKEYS
Definition: tx_extra.h:41
#define TX_EXTRA_NONCE
Definition: tx_extra.h:39
bool do_serialize(Archive< true > &ar)
Definition: tx_extra.h:80
boost::variant< tx_extra_padding, tx_extra_pub_key, tx_extra_nonce, tx_extra_merge_mining_tag, tx_extra_additional_pub_keys, tx_extra_mysterious_minergate > tx_extra_field
Definition: tx_extra.h:186
serialize_helper(tx_extra_merge_mining_tag &mm_tag_)
Definition: tx_extra.h:121
Definition: blake256.h:36
Definition: tx_extra.h:105
VARIANT_TAG(binary_archive, cryptonote::tx_extra_padding, TX_EXTRA_TAG_PADDING)
#define BEGIN_SERIALIZE()
Begins the environment of the DSL for describing how to serialize an of an archive type...
Definition: serialization.h:181
POD_CLASS hash
Definition: hash.h:49
Definition: tx_extra.h:115
#define FIELD(f)
tags the field with the variable name and then serializes it
Definition: serialization.h:243
std::string data
Definition: tx_extra.h:175
#define FIELD_N(t, f)
serializes a field f tagged t
Definition: serialization.h:232
Definition: binary_archive.h:94