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
27#include <functional>
28#include <type_traits>
29
30namespace ripple {
31
35class Issue
36{
37public:
40
41 Issue() = default;
42
43 Issue(Currency const& c, AccountID const& a) : currency(c), account(a)
44 {
45 }
46
47 AccountID const&
48 getIssuer() const
49 {
50 return account;
51 }
52
54 getText() const;
55
56 void
57 setJson(Json::Value& jv) const;
58
59 bool
60 native() const;
61
62 friend constexpr std::weak_ordering
63 operator<=>(Issue const& lhs, Issue const& rhs);
64};
65
66bool
67isConsistent(Issue const& ac);
68
70to_string(Issue const& ac);
71
73to_json(Issue const& is);
74
75Issue
77
79operator<<(std::ostream& os, Issue const& x);
80
81template <class Hasher>
82void
83hash_append(Hasher& h, Issue const& r)
84{
87}
88
91[[nodiscard]] inline constexpr bool
92operator==(Issue const& lhs, Issue const& rhs)
93{
94 return (lhs.currency == rhs.currency) &&
95 (isXRP(lhs.currency) || lhs.account == rhs.account);
96}
101[[nodiscard]] constexpr std::weak_ordering
102operator<=>(Issue const& lhs, Issue const& rhs)
103{
104 if (auto const c{lhs.currency <=> rhs.currency}; c != 0)
105 return c;
106
107 if (isXRP(lhs.currency))
108 return std::weak_ordering::equivalent;
109
110 return (lhs.account <=> rhs.account);
111}
114//------------------------------------------------------------------------------
115
117inline Issue const&
119{
120 static Issue issue{xrpCurrency(), xrpAccount()};
121 return issue;
122}
123
125inline Issue const&
127{
128 static Issue issue{noCurrency(), noAccount()};
129 return issue;
130}
131
132inline bool
133isXRP(Issue const& issue)
134{
135 return issue.native();
136}
137
138} // namespace ripple
139
140#endif
Represents a JSON value.
Definition: json_value.h:150
A currency issued by an account.
Definition: Issue.h:36
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:102
AccountID account
Definition: Issue.h:39
Currency currency
Definition: Issue.h:38
AccountID const & getIssuer() const
Definition: Issue.h:48
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:43
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.
Definition: hash_append.h:237
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
Definition: Issue.h:118
AccountID const & noAccount()
A placeholder for empty accounts.
Definition: AccountID.cpp:185
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:91
AccountID const & xrpAccount()
Compute AccountID from public key.
Definition: AccountID.cpp:178
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.
Definition: UintTypes.cpp:126
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
Definition: base_uint.h:637
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.
Definition: UintTypes.cpp:119
Issue const & noIssue()
Returns an asset specifier that represents no account and currency.
Definition: Issue.h:126
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