Monero
Loading...
Searching...
No Matches
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
47namespace cryptonote
48{
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
59 {
60 if (ar.eof())
61 break;
62
64 if (!::do_serialize(ar, zero))
65 return false;
66
67 if (0 != zero)
68 return false;
69 }
70
72 }
73
74 // store
75 template <template <bool> class Archive>
76 bool member_do_serialize(Archive<true>& ar)
77 {
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
100
102 {
103 std::string nonce;
104
106 FIELD(nonce)
109 };
110
112 {
114 {
116
118 {
119 }
120
122 VARINT_FIELD_N("depth", mm_tag.depth)
123 FIELD_N("merkle_root", mm_tag.merkle_root)
125 };
126
127 size_t depth;
129
130 // load
131 template <template <bool> class Archive>
133 {
134 std::string field;
135 if(!::do_serialize(ar, field))
136 return false;
137
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
160 {
161 std::vector<crypto::public_key> data;
162
164 FIELD(data)
166 };
167
169 {
170 std::string data;
171
173 FIELD(data)
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[];
182}
183
binary_archive< false > ar
Definition cold-outputs.cpp:54
bool do_serialize(Archive< false > &ar, std::vector< T > &v)
Definition containers.h:109
#define BEGIN_SERIALIZE()
#define VARINT_FIELD_N(t, f)
#define FIELD(f)
#define FIELD_N(t, f)
#define false
#define END_SERIALIZE()
#define VARIANT_TAG(Archive, Type, Tag)
Definition portable_binary_archive.hpp:29
crypto namespace.
Definition crypto.cpp:60
POD_CLASS public_key
Definition crypto.h:64
Holds cryptonote related classes and helpers.
Definition blockchain_db.cpp:45
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
span< const T > strspan(const U &s) noexcept
make a span from a std::string
Definition span.h:183
static const unsigned char zero[32]
Definition fe_isnonzero.c:12
unsigned char uint8_t
Definition stdint.h:124
Definition binary_archive.h:89
std::vector< crypto::public_key > data
Definition tx_extra.h:161
serialize_helper(tx_extra_merge_mining_tag &mm_tag_)
Definition tx_extra.h:117
tx_extra_merge_mining_tag & mm_tag
Definition tx_extra.h:115
Definition tx_extra.h:112
size_t depth
Definition tx_extra.h:127
bool member_do_serialize(Archive< true > &ar)
Definition tx_extra.h:145
crypto::hash merkle_root
Definition tx_extra.h:128
bool member_do_serialize(Archive< false > &ar)
Definition tx_extra.h:132
std::string data
Definition tx_extra.h:170
Definition tx_extra.h:102
std::string nonce
Definition tx_extra.h:103
if(TX_EXTRA_NONCE_MAX_COUNT< nonce.size()) return false
Definition tx_extra.h:50
size_t size
Definition tx_extra.h:51
bool member_do_serialize(Archive< true > &ar)
Definition tx_extra.h:76
bool member_do_serialize(Archive< false > &ar)
Definition tx_extra.h:55
Definition tx_extra.h:93
crypto::public_key pub_key
Definition tx_extra.h:94
#define TX_EXTRA_NONCE_MAX_COUNT
Definition tx_extra.h:35
#define TX_EXTRA_TAG_PADDING
Definition tx_extra.h:37
#define TX_EXTRA_TAG_PUBKEY
Definition tx_extra.h:38
#define TX_EXTRA_NONCE
Definition tx_extra.h:39
#define TX_EXTRA_MYSTERIOUS_MINERGATE_TAG
Definition tx_extra.h:42
#define TX_EXTRA_TAG_ADDITIONAL_PUBKEYS
Definition tx_extra.h:41
#define TX_EXTRA_PADDING_MAX_COUNT
Definition tx_extra.h:34
#define TX_EXTRA_MERGE_MINING_TAG
Definition tx_extra.h:40