rippled
STIssue.cpp
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 #include <ripple/protocol/STIssue.h>
21 
22 #include <ripple/basics/Log.h>
23 #include <ripple/basics/contract.h>
24 #include <ripple/protocol/SystemParameters.h>
25 #include <ripple/protocol/jss.h>
26 
27 #include <boost/algorithm/string.hpp>
28 #include <boost/multiprecision/cpp_int.hpp>
29 #include <boost/regex.hpp>
30 
31 #include <iostream>
32 #include <iterator>
33 #include <memory>
34 
35 namespace ripple {
36 
37 STIssue::STIssue(SField const& name) : STBase{name}
38 {
39 }
40 
41 STIssue::STIssue(SerialIter& sit, SField const& name) : STBase{name}
42 {
43  issue_.currency = sit.get160();
44  if (!isXRP(issue_.currency))
45  issue_.account = sit.get160();
46  else
47  issue_.account = xrpAccount();
48 
49  if (isXRP(issue_.currency) != isXRP(issue_.account))
50  Throw<std::runtime_error>(
51  "invalid issue: currency and account native mismatch");
52 }
53 
54 STIssue::STIssue(SField const& name, Issue const& issue)
55  : STBase{name}, issue_{issue}
56 {
57  if (isXRP(issue_.currency) != isXRP(issue_.account))
58  Throw<std::runtime_error>(
59  "invalid issue: currency and account native mismatch");
60 }
61 
64 {
65  return STI_ISSUE;
66 }
67 
70 {
71  return issue_.getText();
72 }
73 
75 {
76  return to_json(issue_);
77 }
78 
79 void
81 {
83  if (!isXRP(issue_.currency))
85 }
86 
87 bool
89 {
90  const STIssue* v = dynamic_cast<const STIssue*>(&t);
91  return v && (*v == *this);
92 }
93 
94 bool
96 {
97  return issue_ == xrpIssue();
98 }
99 
102 {
103  return std::make_unique<STIssue>(sit, name);
104 }
105 
106 STBase*
107 STIssue::copy(std::size_t n, void* buf) const
108 {
109  return emplace(n, buf, *this);
110 }
111 
112 STBase*
114 {
115  return emplace(n, buf, std::move(*this));
116 }
117 
118 STIssue
119 issueFromJson(SField const& name, Json::Value const& v)
120 {
121  return STIssue{name, issueFromJson(v)};
122 }
123 
124 } // namespace ripple
ripple::STIssue::issue_
Issue issue_
Definition: STIssue.h:34
ripple::STIssue::add
void add(Serializer &s) const override
Definition: STIssue.cpp:80
ripple::Issue
A currency issued by an account.
Definition: Issue.h:35
std::string
STL class.
ripple::JsonOptions
JsonOptions
Definition: STBase.h:34
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
iterator
ripple::Issue::currency
Currency currency
Definition: Issue.h:38
iostream
ripple::STIssue::getJson
Json::Value getJson(JsonOptions) const override
Definition: STIssue.cpp:74
ripple::STBase::emplace
static STBase * emplace(std::size_t n, void *buf, T &&val)
Definition: STBase.h:165
ripple::STIssue::isEquivalent
bool isEquivalent(const STBase &t) const override
Definition: STIssue.cpp:88
ripple::Issue::getText
std::string getText() const
Definition: Issue.cpp:30
ripple::xrpAccount
AccountID const & xrpAccount()
Compute AccountID from public key.
Definition: AccountID.cpp:168
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::construct
static std::unique_ptr< STIssue > construct(SerialIter &, SField const &name)
Definition: STIssue.cpp:101
ripple::STIssue
Definition: STIssue.h:31
memory
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::Serializer::addBitString
int addBitString(base_uint< Bits, Tag > const &v)
Definition: Serializer.h:98
ripple::to_json
Json::Value to_json(Issue const &is)
Definition: Issue.cpp:68
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:66
ripple::xrpIssue
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
Definition: Issue.h:105
std::size_t
ripple::STIssue::getText
std::string getText() const override
Definition: STIssue.cpp:69
ripple::STIssue::isDefault
bool isDefault() const override
Definition: STIssue.cpp:95
std::unique_ptr
STL class.
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
Json::Value
Represents a JSON value.
Definition: json_value.h:145