xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
protocol
MPTIssue.h
1
#pragma once
2
3
#include <xrpl/json/json_value.h>
4
#include <xrpl/protocol/AccountID.h>
5
#include <xrpl/protocol/UintTypes.h>
6
7
#include <
algorithm
>
8
#include <
array
>
9
#include <
bit
>
10
#include <
compare
>
11
#include <
cstdint
>
12
#include <
functional
>
13
#include <
ostream
>
14
#include <
string
>
15
16
namespace
xrpl
{
17
18
/* Adapt MPTID to provide the same interface as Issue. Enables using static
19
* polymorphism by Asset and other classes. MPTID is a 192-bit concatenation
20
* of a 32-bit account sequence and a 160-bit account id.
21
*/
22
class
MPTIssue
23
{
24
private
:
25
MPTID
mptID_
;
26
27
public
:
28
MPTIssue
() =
default
;
29
30
MPTIssue
(
MPTID
const
& issuanceID);
31
32
MPTIssue
(
std::uint32_t
sequence,
AccountID
const
& account);
33
34
operator
MPTID
const
&()
const
35
{
36
return
mptID_
;
37
}
38
39
[[nodiscard]]
AccountID
const
&
40
getIssuer
()
const
;
41
42
[[nodiscard]]
constexpr
MPTID
const
&
43
getMptID
()
const
44
{
45
return
mptID_
;
46
}
47
48
[[nodiscard]]
std::string
49
getText
()
const
;
50
51
void
52
setJson
(
json::Value
& jv)
const
;
53
54
friend
constexpr
bool
55
operator==
(
MPTIssue
const
& lhs,
MPTIssue
const
& rhs);
56
57
friend
constexpr
std::weak_ordering
58
operator<=>
(
MPTIssue
const
& lhs,
MPTIssue
const
& rhs);
59
60
static
bool
61
native
()
62
{
63
return
false
;
64
}
65
66
static
bool
67
integral
()
68
{
69
return
true
;
70
}
71
};
72
73
constexpr
bool
74
operator==
(
MPTIssue
const
& lhs,
MPTIssue
const
& rhs)
75
{
76
return
lhs.
mptID_
== rhs.
mptID_
;
77
}
78
79
constexpr
std::weak_ordering
80
operator<=>
(
MPTIssue
const
& lhs,
MPTIssue
const
& rhs)
81
{
82
return
lhs.
mptID_
<=> rhs.
mptID_
;
83
}
84
88
inline
bool
89
isXRP
(
MPTID
const
&)
90
{
91
return
false
;
92
}
93
94
inline
AccountID
95
getMPTIssuer
(
MPTID
const
& mptid)
96
{
97
static_assert
(
sizeof
(
MPTID
) == (
sizeof
(
std::uint32_t
) +
sizeof
(
AccountID
)));
98
// Extract the 20 bytes for the AccountID
99
std::array
<
std::uint8_t
,
sizeof
(
AccountID
)> bytes{};
100
std::copy_n
(mptid.
data
() +
sizeof
(
std::uint32_t
),
sizeof
(
AccountID
), bytes.begin());
101
102
// bit_cast is a "magic" compiler intrinsic that is
103
// usually optimized away to nothing in the final assembly.
104
return
std::bit_cast<AccountID>
(bytes);
105
}
106
107
// Disallow temporary
108
AccountID
const
&
109
getMPTIssuer
(
MPTID
const
&&) =
delete
;
110
AccountID
const
&
111
getMPTIssuer
(
MPTID
&&) =
delete
;
112
113
inline
MPTID
114
noMPT
()
115
{
116
static
MPTIssue
const
kMPT{0,
noAccount
()};
117
return
kMPT.
getMptID
();
118
}
119
120
inline
MPTID
121
badMPT
()
122
{
123
static
MPTIssue
const
kMPT{0,
xrpAccount
()};
124
return
kMPT.
getMptID
();
125
}
126
127
template
<
class
Hasher>
128
void
129
hash_append
(Hasher& h,
MPTIssue
const
& r)
130
{
131
using
beast::hash_append
;
132
hash_append
(h, r.
getMptID
());
133
}
134
135
json::Value
136
toJson
(MPTIssue
const
& mptIssue);
137
138
std::string
139
to_string
(MPTIssue
const
& mptIssue);
140
141
MPTIssue
142
mptIssueFromJson
(
json::Value
const
& jv);
143
144
std::ostream
&
145
operator<<
(
std::ostream
& os, MPTIssue
const
& x);
146
147
}
// namespace xrpl
148
149
namespace
std
{
150
151
template
<>
152
struct
hash
<
xrpl
::MPTID> :
xrpl::MPTID::hasher
153
{
154
hash
() =
default
;
155
};
156
157
}
// namespace std
algorithm
array
std::ostream
std::string
std::bit_cast
T bit_cast(T... args)
bit
json::Value
Represents a JSON value.
Definition
json_value.h:117
xrpl::BaseUInt::data
pointer data()
Definition
base_uint.h:117
xrpl::BaseUInt< 192 >::hasher
HardenedHash<> hasher
Definition
base_uint.h:163
xrpl::MPTIssue
Definition
MPTIssue.h:23
xrpl::MPTIssue::native
static bool native()
Definition
MPTIssue.h:61
xrpl::MPTIssue::operator<=>
friend constexpr std::weak_ordering operator<=>(MPTIssue const &lhs, MPTIssue const &rhs)
Definition
MPTIssue.h:80
xrpl::MPTIssue::getMptID
constexpr MPTID const & getMptID() const
Definition
MPTIssue.h:43
xrpl::MPTIssue::operator==
friend constexpr bool operator==(MPTIssue const &lhs, MPTIssue const &rhs)
Definition
MPTIssue.h:74
xrpl::MPTIssue::mptID_
MPTID mptID_
Definition
MPTIssue.h:25
xrpl::MPTIssue::integral
static bool integral()
Definition
MPTIssue.h:67
xrpl::MPTIssue::getIssuer
AccountID const & getIssuer() const
Definition
MPTIssue.cpp:29
xrpl::MPTIssue::setJson
void setJson(json::Value &jv) const
Definition
MPTIssue.cpp:46
xrpl::MPTIssue::MPTIssue
MPTIssue()=default
xrpl::MPTIssue::getText
std::string getText() const
Definition
MPTIssue.cpp:40
compare
std::copy_n
T copy_n(T... args)
cstdint
functional
std::uint32_t
beast::hash_append
void hash_append(Hasher &h, T const &t) noexcept
Logically concatenate input data to a Hasher.
Definition
hash_append.h:206
std
STL namespace.
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::operator==
constexpr bool operator==(BaseUInt< Bits, Tag > const &lhs, BaseUInt< Bits, Tag > const &rhs)
Definition
base_uint.h:612
xrpl::isXRP
bool isXRP(AccountID const &c)
Definition
AccountID.h:84
xrpl::mptIssueFromJson
MPTIssue mptIssueFromJson(json::Value const &jv)
Definition
MPTIssue.cpp:66
xrpl::operator<<
std::ostream & operator<<(std::ostream &out, BaseUInt< Bits, Tag > const &u)
Definition
base_uint.h:672
xrpl::getMPTIssuer
AccountID getMPTIssuer(MPTID const &mptid)
Definition
MPTIssue.h:95
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::toJson
json::Value toJson(Asset const &asset)
Definition
Asset.h:168
xrpl::operator<=>
constexpr std::strong_ordering operator<=>(BaseUInt< Bits, Tag > const &lhs, BaseUInt< Bits, Tag > const &rhs)
Definition
base_uint.h:591
xrpl::noMPT
MPTID noMPT()
Definition
MPTIssue.h:114
xrpl::MPTID
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
Definition
UintTypes.h:54
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
xrpl::noAccount
AccountID const & noAccount()
A placeholder for empty accounts.
Definition
AccountID.cpp:166
xrpl::hash_append
void hash_append(Hasher &h, Slice const &v)
Definition
Slice.h:194
xrpl::xrpAccount
AccountID const & xrpAccount()
Compute AccountID from public key.
Definition
AccountID.cpp:159
xrpl::badMPT
MPTID badMPT()
Definition
MPTIssue.h:121
ostream
string
std::hash< xrpl::MPTID >::hash
hash()=default
std::weak_ordering
Generated by
1.17.0