rippled
Loading...
Searching...
No Matches
Issue.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_PROTOCOL_ISSUE_H_INCLUDED
21#define RIPPLE_PROTOCOL_ISSUE_H_INCLUDED
22
23#include <xrpl/beast/utility/instrumentation.h>
24#include <xrpl/json/json_value.h>
25#include <xrpl/protocol/UintTypes.h>
26
27namespace ripple {
28
32class Issue
33{
34public:
37
38 Issue() = default;
39
40 Issue(Currency const& c, AccountID const& a) : currency(c), account(a)
41 {
42 }
43
44 AccountID const&
45 getIssuer() const
46 {
47 return account;
48 }
49
51 getText() const;
52
53 void
54 setJson(Json::Value& jv) const;
55
56 bool
57 native() const;
58
59 friend constexpr std::weak_ordering
60 operator<=>(Issue const& lhs, Issue const& rhs);
61};
62
63bool
64isConsistent(Issue const& ac);
65
67to_string(Issue const& ac);
68
70to_json(Issue const& is);
71
72Issue
74
76operator<<(std::ostream& os, Issue const& x);
77
78template <class Hasher>
79void
80hash_append(Hasher& h, Issue const& r)
81{
84}
85
88[[nodiscard]] inline constexpr bool
89operator==(Issue const& lhs, Issue const& rhs)
90{
91 return (lhs.currency == rhs.currency) &&
92 (isXRP(lhs.currency) || lhs.account == rhs.account);
93}
98[[nodiscard]] constexpr std::weak_ordering
99operator<=>(Issue const& lhs, Issue const& rhs)
100{
101 if (auto const c{lhs.currency <=> rhs.currency}; c != 0)
102 return c;
103
104 if (isXRP(lhs.currency))
105 return std::weak_ordering::equivalent;
106
107 return (lhs.account <=> rhs.account);
108}
111//------------------------------------------------------------------------------
112
114inline Issue const&
116{
117 static Issue issue{xrpCurrency(), xrpAccount()};
118 return issue;
119}
120
122inline Issue const&
124{
125 static Issue issue{noCurrency(), noAccount()};
126 return issue;
127}
128
129inline bool
130isXRP(Issue const& issue)
131{
132 return issue.native();
133}
134
135} // namespace ripple
136
137#endif
Represents a JSON value.
Definition json_value.h:149
A currency issued by an account.
Definition Issue.h:33
std::string getText() const
Definition Issue.cpp:35
friend constexpr std::weak_ordering operator<=>(Issue const &lhs, Issue const &rhs)
Strict weak ordering.
Definition Issue.h:99
AccountID account
Definition Issue.h:36
Currency currency
Definition Issue.h:35
AccountID const & getIssuer() const
Definition Issue.h:45
bool native() const
Definition Issue.cpp:66
Issue()=default
void setJson(Json::Value &jv) const
Definition Issue.cpp:58
Issue(Currency const &c, AccountID const &a)
Definition Issue.h:40
std::enable_if_t< is_contiguously_hashable< T, Hasher >::value > hash_append(Hasher &h, T const &t) noexcept
Logically concatenate input data to a Hasher.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
Definition Issue.h:115
AccountID const & noAccount()
A placeholder for empty accounts.
void hash_append(Hasher &h, Slice const &v)
Definition Slice.h:199
bool isConsistent(Book const &book)
Definition Book.cpp:29
bool isXRP(AccountID const &c)
Definition AccountID.h:90
AccountID const & xrpAccount()
Compute AccountID from public key.
constexpr std::strong_ordering operator<=>(base_uint< Bits, Tag > const &lhs, base_uint< Bits, Tag > const &rhs)
Definition base_uint.h:563
Currency const & noCurrency()
A placeholder for empty currencies.
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
Definition base_uint.h:647
Json::Value to_json(Asset const &asset)
Definition Asset.h:123
Issue issueFromJson(Json::Value const &v)
Definition Issue.cpp:95
Currency const & xrpCurrency()
XRP currency.
Issue const & noIssue()
Returns an asset specifier that represents no account and currency.
Definition Issue.h:123
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:630
constexpr bool operator==(base_uint< Bits, Tag > const &lhs, base_uint< Bits, Tag > const &rhs)
Definition base_uint.h:585