rippled
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 <ripple/json/json_value.h>
24 #include <ripple/protocol/UintTypes.h>
25 
26 #include <cassert>
27 #include <functional>
28 #include <type_traits>
29 
30 namespace ripple {
31 
35 class Issue
36 {
37 public:
40 
42  {
43  }
44 
45  Issue(Currency const& c, AccountID const& a) : currency(c), account(a)
46  {
47  }
48 
50  getText() const;
51 };
52 
53 bool
54 isConsistent(Issue const& ac);
55 
57 to_string(Issue const& ac);
58 
60 to_json(Issue const& is);
61 
62 Issue
63 issueFromJson(Json::Value const& v);
64 
66 operator<<(std::ostream& os, Issue const& x);
67 
68 template <class Hasher>
69 void
70 hash_append(Hasher& h, Issue const& r)
71 {
72  using beast::hash_append;
73  hash_append(h, r.currency, r.account);
74 }
75 
78 [[nodiscard]] inline constexpr bool
79 operator==(Issue const& lhs, Issue const& rhs)
80 {
81  return (lhs.currency == rhs.currency) &&
82  (isXRP(lhs.currency) || lhs.account == rhs.account);
83 }
88 [[nodiscard]] inline constexpr std::weak_ordering
89 operator<=>(Issue const& lhs, Issue const& rhs)
90 {
91  if (auto const c{lhs.currency <=> rhs.currency}; c != 0)
92  return c;
93 
94  if (isXRP(lhs.currency))
95  return std::weak_ordering::equivalent;
96 
97  return (lhs.account <=> rhs.account);
98 }
101 //------------------------------------------------------------------------------
102 
104 inline Issue const&
106 {
107  static Issue issue{xrpCurrency(), xrpAccount()};
108  return issue;
109 }
110 
112 inline Issue const&
114 {
115  static Issue issue{noCurrency(), noAccount()};
116  return issue;
117 }
118 
119 } // namespace ripple
120 
121 #endif
ripple::Issue
A currency issued by an account.
Definition: Issue.h:35
std::string
STL class.
ripple::noCurrency
Currency const & noCurrency()
A placeholder for empty currencies.
Definition: UintTypes.cpp:128
ripple::isConsistent
bool isConsistent(Book const &book)
Definition: Book.cpp:25
functional
std::weak_ordering
ripple::operator<=>
constexpr std::strong_ordering operator<=>(base_uint< Bits, Tag > const &lhs, base_uint< Bits, Tag > const &rhs)
Definition: base_uint.h:554
ripple::Issue::currency
Currency currency
Definition: Issue.h:38
ripple::noIssue
Issue const & noIssue()
Returns an asset specifier that represents no account and currency.
Definition: Issue.h:113
ripple::operator<<
std::ostream & operator<<(std::ostream &os, TOffer< TIn, TOut > const &offer)
Definition: Offer.h:303
ripple::operator==
bool operator==(Manifest const &lhs, Manifest const &rhs)
Definition: Manifest.h:165
ripple::base_uint< 160, detail::CurrencyTag >
std::ostream
STL class.
ripple::Issue::getText
std::string getText() const
Definition: Issue.cpp:29
ripple::xrpAccount
AccountID const & xrpAccount()
Compute AccountID from public key.
Definition: AccountID.cpp:168
ripple::isXRP
bool isXRP(AccountID const &c)
Definition: AccountID.h:89
ripple::issueFromJson
Issue issueFromJson(Json::Value const &v)
Definition: Issue.cpp:77
ripple::Issue::Issue
Issue(Currency const &c, AccountID const &a)
Definition: Issue.h:45
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Issue::Issue
Issue()
Definition: Issue.h:41
ripple::to_json
Json::Value to_json(Issue const &is)
Definition: Issue.cpp:67
beast::hash_append
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:236
cassert
ripple::xrpIssue
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
Definition: Issue.h:105
ripple::to_string
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
Definition: app/misc/impl/Manifest.cpp:41
ripple::hash_append
void hash_append(Hasher &h, ValidatorBlobInfo const &blobInfo)
Definition: ValidatorList.h:897
type_traits
ripple::noAccount
AccountID const & noAccount()
A placeholder for empty accounts.
Definition: AccountID.cpp:175
ripple::xrpCurrency
Currency const & xrpCurrency()
XRP currency.
Definition: UintTypes.cpp:121
ripple::Issue::account
AccountID account
Definition: Issue.h:39
Json::Value
Represents a JSON value.
Definition: json_value.h:145