rippled
STIssue.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2023 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_STISSUE_H_INCLUDED
21 #define RIPPLE_PROTOCOL_STISSUE_H_INCLUDED
22 
23 #include <ripple/basics/CountedObject.h>
24 #include <ripple/protocol/Issue.h>
25 #include <ripple/protocol/SField.h>
26 #include <ripple/protocol/STBase.h>
27 #include <ripple/protocol/Serializer.h>
28 
29 namespace ripple {
30 
31 class STIssue final : public STBase, CountedObject<STIssue>
32 {
33 private:
35 
36 public:
37  using value_type = Issue;
38 
39  STIssue() = default;
40 
41  explicit STIssue(SerialIter& sit, SField const& name);
42 
43  explicit STIssue(SField const& name, Issue const& issue);
44 
45  explicit STIssue(SField const& name);
46 
47  Issue const&
48  issue() const;
49 
50  Issue const&
51  value() const noexcept;
52 
53  void
54  setIssue(Issue const& issue);
55 
57  getSType() const override;
58 
59  std::string
60  getText() const override;
61 
62  Json::Value getJson(JsonOptions) const override;
63 
64  void
65  add(Serializer& s) const override;
66 
67  bool
68  isEquivalent(const STBase& t) const override;
69 
70  bool
71  isDefault() const override;
72 
73 private:
74  static std::unique_ptr<STIssue>
75  construct(SerialIter&, SField const& name);
76 
77  STBase*
78  copy(std::size_t n, void* buf) const override;
79  STBase*
80  move(std::size_t n, void* buf) override;
81 
82  friend class detail::STVar;
83 };
84 
85 STIssue
86 issueFromJson(SField const& name, Json::Value const& v);
87 
88 inline Issue const&
89 STIssue::issue() const
90 {
91  return issue_;
92 }
93 
94 inline Issue const&
95 STIssue::value() const noexcept
96 {
97  return issue_;
98 }
99 
100 inline void
102 {
104  Throw<std::runtime_error>(
105  "invalid issue: currency and account native mismatch");
106 
107  issue_ = issue;
108 }
109 
110 inline bool
111 operator==(STIssue const& lhs, STIssue const& rhs)
112 {
113  return lhs.issue() == rhs.issue();
114 }
115 
116 inline bool
117 operator!=(STIssue const& lhs, STIssue const& rhs)
118 {
119  return !operator==(lhs, rhs);
120 }
121 
122 inline bool
123 operator<(STIssue const& lhs, STIssue const& rhs)
124 {
125  return lhs.issue() < rhs.issue();
126 }
127 
128 inline bool
129 operator==(STIssue const& lhs, Issue const& rhs)
130 {
131  return lhs.issue() == rhs;
132 }
133 
134 inline bool
135 operator<(STIssue const& lhs, Issue const& rhs)
136 {
137  return lhs.issue() < rhs;
138 }
139 
140 } // namespace ripple
141 
142 #endif
ripple::STIssue::issue_
Issue issue_
Definition: STIssue.h:34
ripple::STIssue::add
void add(Serializer &s) const override
Definition: STIssue.cpp:80
ripple::STIssue::issue
Issue const & issue() const
Definition: STIssue.h:89
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
ripple::Issue
A currency issued by an account.
Definition: Issue.h:35
ripple::STIssue::copy
STBase * copy(std::size_t n, void *buf) const override
Definition: STIssue.cpp:107
ripple::STIssue::STIssue
STIssue()=default
ripple::STIssue::getSType
SerializedTypeID getSType() const override
Definition: STIssue.cpp:63
ripple::SerializedTypeID
SerializedTypeID
Definition: SField.h:104
ripple::Issue::currency
Currency currency
Definition: Issue.h:38
ripple::STIssue::getJson
Json::Value getJson(JsonOptions) const override
Definition: STIssue.cpp:74
Json
JSON (JavaScript Object Notation).
Definition: DeliverMax.h:28
ripple::operator<
bool operator<(CanonicalTXSet::Key const &lhs, CanonicalTXSet::Key const &rhs)
Definition: CanonicalTXSet.cpp:25
ripple::STIssue::isEquivalent
bool isEquivalent(const STBase &t) const override
Definition: STIssue.cpp:88
ripple::isXRP
bool isXRP(AccountID const &c)
Definition: AccountID.h:91
ripple::SerialIter
Definition: Serializer.h:311
ripple::issueFromJson
Issue issueFromJson(Json::Value const &v)
Definition: Issue.cpp:78
ripple::STIssue::value
Issue const & value() const noexcept
Definition: STIssue.h:95
ripple::STIssue::construct
static std::unique_ptr< STIssue > construct(SerialIter &, SField const &name)
Definition: STIssue.cpp:101
ripple::STIssue
Definition: STIssue.h:31
ripple::Serializer
Definition: Serializer.h:40
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::JsonOptions
Note, should be treated as flags that can be | and &.
Definition: STBase.h:35
ripple::SField
Identifies fields.
Definition: SField.h:139
ripple::STBase
A type which can be exported to a well known binary format.
Definition: STBase.h:121
ripple::STBase::operator!=
bool operator!=(const STBase &t) const
Definition: STBase.cpp:51
ripple::STIssue::setIssue
void setIssue(Issue const &issue)
Definition: STIssue.h:101
std
STL namespace.
ripple::xrpIssue
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
Definition: Issue.h:105
ripple::STBase::operator==
bool operator==(const STBase &t) const
Definition: STBase.cpp:45
ripple::STIssue::getText
std::string getText() const override
Definition: STIssue.cpp:69
ripple::STIssue::isDefault
bool isDefault() const override
Definition: STIssue.cpp:95
ripple::STIssue::move
STBase * move(std::size_t n, void *buf) override
Definition: STIssue.cpp:113
ripple::Issue::account
AccountID account
Definition: Issue.h:39