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 <cassert>
24 #include <functional>
25 #include <type_traits>
26 
27 #include <ripple/protocol/UintTypes.h>
28 
29 namespace ripple {
30 
34 class Issue
35 {
36 public:
39 
41  {
42  }
43 
44  Issue(Currency const& c, AccountID const& a) : currency(c), account(a)
45  {
46  }
47 };
48 
49 bool
50 isConsistent(Issue const& ac);
51 
53 to_string(Issue const& ac);
54 
56 operator<<(std::ostream& os, Issue const& x);
57 
58 template <class Hasher>
59 void
60 hash_append(Hasher& h, Issue const& r)
61 {
62  using beast::hash_append;
63  hash_append(h, r.currency, r.account);
64 }
65 
68 [[nodiscard]] inline constexpr bool
69 operator==(Issue const& lhs, Issue const& rhs)
70 {
71  return (lhs.currency == rhs.currency) &&
72  (isXRP(lhs.currency) || lhs.account == rhs.account);
73 }
78 [[nodiscard]] inline constexpr std::weak_ordering
79 operator<=>(Issue const& lhs, Issue const& rhs)
80 {
81  if (auto const c{lhs.currency <=> rhs.currency}; c != 0)
82  return c;
83 
84  if (isXRP(lhs.currency))
85  return std::weak_ordering::equivalent;
86 
87  return (lhs.account <=> rhs.account);
88 }
91 //------------------------------------------------------------------------------
92 
94 inline Issue const&
96 {
97  static Issue issue{xrpCurrency(), xrpAccount()};
98  return issue;
99 }
100 
102 inline Issue const&
104 {
105  static Issue issue{noCurrency(), noAccount()};
106  return issue;
107 }
108 
109 } // namespace ripple
110 
111 #endif
ripple::Issue
A currency issued by an account.
Definition: Issue.h:34
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:37
ripple::noIssue
Issue const & noIssue()
Returns an asset specifier that represents no account and currency.
Definition: Issue.h:103
ripple::operator<<
std::ostream & operator<<(std::ostream &os, TOffer< TIn, TOut > const &offer)
Definition: Offer.h:242
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::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::Issue::Issue
Issue(Currency const &c, AccountID const &a)
Definition: Issue.h:44
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:40
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:95
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:38