xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
tests
libxrpl
helpers
IOU.h
1
#pragma once
2
3
#include <xrpl/basics/Number.h>
4
#include <xrpl/beast/utility/instrumentation.h>
5
#include <xrpl/protocol/Asset.h>
6
#include <xrpl/protocol/Issue.h>
7
#include <xrpl/protocol/STAmount.h>
8
#include <xrpl/protocol/UintTypes.h>
9
10
#include <helpers/Account.h>
11
12
#include <
string
>
13
#include <
string_view
>
14
#include <
type_traits
>
15
16
namespace
xrpl::test
{
17
33
class
IOU
34
{
35
public
:
41
IOU
(
std::string_view
currencyCode,
Account
const
&
issuer
)
42
:
currency_
(
toCurrency
(
std
::string(currencyCode))),
issuer_
(
issuer
.id())
43
{
44
XRPL_ASSERT(!
isXRP
(
currency_
),
"IOU: currency code must not resolve to XRP"
);
45
}
46
52
IOU
(
Currency
currency
,
Account
const
&
issuer
) :
currency_
(
currency
),
issuer_
(
issuer
.id())
53
{
54
XRPL_ASSERT(!
isXRP
(
currency_
),
"IOU: currency code must not resolve to XRP"
);
55
}
56
61
[[nodiscard]]
Issue
62
issue
()
const
63
{
64
return
Issue
{
currency_
,
issuer_
};
65
}
66
71
[[nodiscard]]
Asset
72
asset
()
const
73
{
74
return
Asset
{
issue
()};
75
}
76
87
template
<
typename
T>
88
requires
std::is_arithmetic_v<T>
89
[[nodiscard]]
STAmount
90
amount
(T value)
const
91
{
92
return
amountFromString
(
issue
(),
to_string
(value));
93
}
94
100
[[nodiscard]]
STAmount
101
amount
(
Number
const
& value)
const
102
{
103
return
STAmount
{
issue
(), value};
104
}
105
110
[[nodiscard]]
Currency
const
&
111
currency
()
const
112
{
113
return
currency_
;
114
}
115
120
[[nodiscard]]
AccountID
const
&
121
issuer
()
const
122
{
123
return
issuer_
;
124
}
125
126
private
:
127
Currency
currency_
;
128
AccountID
issuer_
;
129
};
130
131
}
// namespace xrpl::test
std::string_view
xrpl::Asset
Definition
Asset.h:52
xrpl::Issue
A currency issued by an account.
Definition
Issue.h:18
xrpl::Number
Number is a floating point type that can represent a wide range of values.
Definition
Number.h:351
xrpl::STAmount
Definition
STAmount.h:46
xrpl::test::IOU::asset
Asset asset() const
Get the Asset.
Definition
IOU.h:72
xrpl::test::IOU::amount
STAmount amount(Number const &value) const
Create an STAmount of this IOU from a Number.
Definition
IOU.h:101
xrpl::test::IOU::currency_
Currency currency_
Definition
IOU.h:127
xrpl::test::IOU::issuer
AccountID const & issuer() const
Get the issuer account ID.
Definition
IOU.h:121
xrpl::test::IOU::currency
Currency const & currency() const
Get the currency.
Definition
IOU.h:111
xrpl::test::IOU::IOU
IOU(Currency currency, Account const &issuer)
Construct an IOU from a Currency and issuing account.
Definition
IOU.h:52
xrpl::test::IOU::issuer_
AccountID issuer_
Definition
IOU.h:128
xrpl::test::IOU::amount
STAmount amount(T value) const
Create an STAmount of this IOU.
Definition
IOU.h:90
xrpl::test::IOU::IOU
IOU(std::string_view currencyCode, Account const &issuer)
Construct an IOU from a currency code and issuing account.
Definition
IOU.h:41
xrpl::test::IOU::issue
Issue issue() const
Get the Issue (currency + issuer pair).
Definition
IOU.h:62
xrpl::test::jtx::Account
Immutable cryptographic account descriptor.
Definition
jtx/Account.h:21
xrpl::test::jtx::IOU::issue
Issue issue() const
Definition
src/test/jtx/amount.h:415
std::is_arithmetic_v
T is_arithmetic_v
std
STL namespace.
xrpl::test
Definition
STLedgerEntry.h:21
xrpl::isXRP
bool isXRP(AccountID const &c)
Definition
AccountID.h:84
xrpl::Currency
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition
UintTypes.h:42
xrpl::amountFromString
STAmount amountFromString(Asset const &asset, std::string const &amount)
Definition
STAmount.cpp:908
xrpl::toCurrency
bool toCurrency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.
Definition
UintTypes.cpp:65
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
string
string_view
type_traits
Generated by
1.17.0