Monero
Toggle main menu visibility
Loading...
Searching...
No Matches
src
cryptonote_basic
tx_extra.h
Go to the documentation of this file.
1
// Copyright (c) 2014-2022, 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
{
49
struct
tx_extra_padding
50
{
51
size_t
size
;
52
53
// load
54
template
<
template
<
bool
>
class
Archive>
55
bool
member_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
if
(
ar
.eof())
61
break
;
62
63
uint8_t
zero
;
64
if
(!
::do_serialize
(
ar
,
zero
))
65
return
false
;
66
67
if
(0 !=
zero
)
68
return
false
;
69
}
70
71
return
size
<=
TX_EXTRA_PADDING_MAX_COUNT
;
72
}
73
74
// store
75
template
<
template
<
bool
>
class
Archive>
76
bool
member_do_serialize
(Archive<true>&
ar
)
77
{
78
if
(
TX_EXTRA_PADDING_MAX_COUNT
<
size
)
79
return
false
;
80
81
// i = 1 - because of variant tag
82
for
(
size_t
i = 1; i <
size
; ++i)
83
{
84
uint8_t
zero
= 0;
85
if
(!
::do_serialize
(
ar
,
zero
))
86
return
false
;
87
}
88
return
true
;
89
}
90
};
91
92
struct
tx_extra_pub_key
93
{
94
crypto::public_key
pub_key
;
95
96
BEGIN_SERIALIZE
()
97
FIELD
(
pub_key
)
98
END_SERIALIZE
()
99
};
100
101
struct
tx_extra_nonce
102
{
103
std::string
nonce
;
104
105
BEGIN_SERIALIZE
()
106
FIELD
(
nonce
)
107
if
(
TX_EXTRA_NONCE_MAX_COUNT
<
nonce
.size()) return
false
;
108
END_SERIALIZE
()
109
};
110
111
struct
tx_extra_merge_mining_tag
112
{
113
struct
serialize_helper
114
{
115
tx_extra_merge_mining_tag
&
mm_tag
;
116
117
serialize_helper
(
tx_extra_merge_mining_tag
& mm_tag_) :
mm_tag
(mm_tag_)
118
{
119
}
120
121
BEGIN_SERIALIZE
()
122
VARINT_FIELD_N
(
"depth"
, mm_tag.
depth
)
123
FIELD_N
(
"merkle_root"
, mm_tag.
merkle_root
)
124
END_SERIALIZE
()
125
};
126
127
size_t
depth
;
128
crypto
::hash
merkle_root
;
129
130
// load
131
template <template <
bool
> class Archive>
132
bool
member_do_serialize
(Archive<
false
>&
ar
)
133
{
134
std::string field;
135
if
(!
::do_serialize
(
ar
, field))
136
return
false
;
137
138
binary_archive<false>
iar{
epee::strspan<std::uint8_t>
(field)};
139
serialize_helper
helper(*
this
);
140
return ::serialization::serialize(iar, helper);
141
}
142
143
// store
144
template
<
template
<
bool
>
class
Archive>
145
bool
member_do_serialize
(Archive<true>&
ar
)
146
{
147
std::ostringstream oss;
148
binary_archive<true>
oar(oss);
149
serialize_helper
helper(*
this
);
150
if
(!
::do_serialize
(oar, helper))
151
return
false
;
152
153
std::string field = oss.str();
154
return ::serialization::serialize(
ar
, field);
155
}
156
};
157
158
// per-output additional tx pubkey for multi-destination transfers involving at least one subaddress
159
struct
tx_extra_additional_pub_keys
160
{
161
std::vector<crypto::public_key>
data
;
162
163
BEGIN_SERIALIZE
()
164
FIELD
(
data
)
165
END_SERIALIZE
()
166
};
167
168
struct
tx_extra_mysterious_minergate
169
{
170
std::string
data
;
171
172
BEGIN_SERIALIZE
()
173
FIELD
(
data
)
174
END_SERIALIZE
()
175
};
176
177
// tx_extra_field format, except tx_extra_padding and tx_extra_pub_key:
178
// varint tag;
179
// varint size;
180
// varint data[];
181
typedef
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
;
182
}
183
184
VARIANT_TAG
(
binary_archive
,
cryptonote
::tx_extra_padding,
TX_EXTRA_TAG_PADDING
);
185
VARIANT_TAG
(
binary_archive
,
cryptonote
::tx_extra_pub_key,
TX_EXTRA_TAG_PUBKEY
);
186
VARIANT_TAG
(
binary_archive
,
cryptonote
::tx_extra_nonce,
TX_EXTRA_NONCE
);
187
VARIANT_TAG
(
binary_archive
,
cryptonote
::tx_extra_merge_mining_tag,
TX_EXTRA_MERGE_MINING_TAG
);
188
VARIANT_TAG
(
binary_archive
,
cryptonote
::tx_extra_additional_pub_keys,
TX_EXTRA_TAG_ADDITIONAL_PUBKEYS
);
189
VARIANT_TAG
(
binary_archive
,
cryptonote
::tx_extra_mysterious_minergate,
TX_EXTRA_MYSTERIOUS_MINERGATE_TAG
);
ar
binary_archive< false > ar
Definition
cold-outputs.cpp:54
do_serialize
bool do_serialize(Archive< false > &ar, std::vector< T > &v)
Definition
containers.h:108
BEGIN_SERIALIZE
#define BEGIN_SERIALIZE()
VARINT_FIELD_N
#define VARINT_FIELD_N(t, f)
FIELD
#define FIELD(f)
FIELD_N
#define FIELD_N(t, f)
false
#define false
END_SERIALIZE
#define END_SERIALIZE()
VARIANT_TAG
#define VARIANT_TAG(Archive, Type, Tag)
boost
Definition
portable_binary_archive.hpp:29
crypto
crypto namespace.
Definition
crypto.cpp:60
crypto::public_key
POD_CLASS public_key
Definition
crypto.h:64
cryptonote
Holds cryptonote related classes and helpers.
Definition
blockchain_db.cpp:45
cryptonote::tx_extra_field
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:181
epee::strspan
span< const T > strspan(const U &s) noexcept
make a span from a std::string
Definition
span.h:183
zero
static const unsigned char zero[32]
Definition
fe_isnonzero.c:12
uint8_t
unsigned char uint8_t
Definition
stdint.h:124
binary_archive
Definition
binary_archive.h:89
cryptonote::tx_extra_additional_pub_keys
Definition
tx_extra.h:160
cryptonote::tx_extra_additional_pub_keys::data
std::vector< crypto::public_key > data
Definition
tx_extra.h:161
cryptonote::tx_extra_merge_mining_tag::serialize_helper
Definition
tx_extra.h:114
cryptonote::tx_extra_merge_mining_tag::serialize_helper::serialize_helper
serialize_helper(tx_extra_merge_mining_tag &mm_tag_)
Definition
tx_extra.h:117
cryptonote::tx_extra_merge_mining_tag::serialize_helper::mm_tag
tx_extra_merge_mining_tag & mm_tag
Definition
tx_extra.h:115
cryptonote::tx_extra_merge_mining_tag
Definition
tx_extra.h:112
cryptonote::tx_extra_merge_mining_tag::depth
size_t depth
Definition
tx_extra.h:127
cryptonote::tx_extra_merge_mining_tag::member_do_serialize
bool member_do_serialize(Archive< true > &ar)
Definition
tx_extra.h:145
cryptonote::tx_extra_merge_mining_tag::merkle_root
crypto::hash merkle_root
Definition
tx_extra.h:128
cryptonote::tx_extra_merge_mining_tag::member_do_serialize
bool member_do_serialize(Archive< false > &ar)
Definition
tx_extra.h:132
cryptonote::tx_extra_mysterious_minergate
Definition
tx_extra.h:169
cryptonote::tx_extra_mysterious_minergate::data
std::string data
Definition
tx_extra.h:170
cryptonote::tx_extra_nonce
Definition
tx_extra.h:102
cryptonote::tx_extra_nonce::nonce
std::string nonce
Definition
tx_extra.h:103
cryptonote::tx_extra_nonce::if
if(TX_EXTRA_NONCE_MAX_COUNT< nonce.size()) return false
cryptonote::tx_extra_padding
Definition
tx_extra.h:50
cryptonote::tx_extra_padding::size
size_t size
Definition
tx_extra.h:51
cryptonote::tx_extra_padding::member_do_serialize
bool member_do_serialize(Archive< true > &ar)
Definition
tx_extra.h:76
cryptonote::tx_extra_padding::member_do_serialize
bool member_do_serialize(Archive< false > &ar)
Definition
tx_extra.h:55
cryptonote::tx_extra_pub_key
Definition
tx_extra.h:93
cryptonote::tx_extra_pub_key::pub_key
crypto::public_key pub_key
Definition
tx_extra.h:94
TX_EXTRA_NONCE_MAX_COUNT
#define TX_EXTRA_NONCE_MAX_COUNT
Definition
tx_extra.h:35
TX_EXTRA_TAG_PADDING
#define TX_EXTRA_TAG_PADDING
Definition
tx_extra.h:37
TX_EXTRA_TAG_PUBKEY
#define TX_EXTRA_TAG_PUBKEY
Definition
tx_extra.h:38
TX_EXTRA_NONCE
#define TX_EXTRA_NONCE
Definition
tx_extra.h:39
TX_EXTRA_MYSTERIOUS_MINERGATE_TAG
#define TX_EXTRA_MYSTERIOUS_MINERGATE_TAG
Definition
tx_extra.h:42
TX_EXTRA_TAG_ADDITIONAL_PUBKEYS
#define TX_EXTRA_TAG_ADDITIONAL_PUBKEYS
Definition
tx_extra.h:41
TX_EXTRA_PADDING_MAX_COUNT
#define TX_EXTRA_PADDING_MAX_COUNT
Definition
tx_extra.h:34
TX_EXTRA_MERGE_MINING_TAG
#define TX_EXTRA_MERGE_MINING_TAG
Definition
tx_extra.h:40
Generated on
for Monero by
1.17.0