xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
jtx
impl
vault.cpp
1
#include <test/jtx/vault.h>
2
3
#include <test/jtx/Env.h>
4
5
#include <xrpl/basics/base_uint.h>
6
#include <xrpl/basics/chrono.h>
7
#include <xrpl/json/json_value.h>
8
#include <xrpl/protocol/Asset.h>
9
#include <xrpl/protocol/Indexes.h>
10
#include <xrpl/protocol/Keylet.h>
11
#include <xrpl/protocol/Protocol.h>
12
#include <xrpl/protocol/SField.h>
13
#include <xrpl/protocol/STBase.h>
14
#include <xrpl/protocol/SeqProxy.h>
15
#include <xrpl/protocol/jss.h>
16
17
#include <
chrono
>
18
#include <
cstdint
>
19
#include <
optional
>
20
#include <
tuple
>
21
#include <
utility
>
22
23
namespace
xrpl::test::jtx
{
24
25
std::tuple<json::Value, Keylet>
26
Vault::create
(
CreateArgs
const
& args)
const
27
{
28
auto
const
seqProxy =
SeqProxy::rawSequence
(
env
.seq(args.
owner
));
29
auto
keylet
=
keylet::vault
(args.
owner
.
id
(), seqProxy);
30
json::Value
jv;
31
jv[jss::TransactionType] = jss::VaultCreate;
32
jv[jss::Account] = args.
owner
.
human
();
33
jv[jss::Asset] =
toJson
(args.
asset
);
34
if
(args.
flags
)
35
jv[jss::Flags] = *args.
flags
;
36
if
(args.
vaultKind
)
37
jv[sfVaultKind] = *args.
vaultKind
;
38
if
(args.
subscriptionDate
)
39
jv[sfSubscriptionDate] = *args.
subscriptionDate
;
40
if
(args.
redemptionDate
)
41
jv[sfRedemptionDate] = *args.
redemptionDate
;
42
if
(args.
leVersion
)
43
jv[sfLEVersion] = std::to_underlying(*args.
leVersion
);
44
return
{jv,
keylet
};
45
}
46
47
std::tuple<json::Value, Keylet, NetClock::time_point>
48
Vault::createClosedEnded
(
CreateClosedEndedArgs
const
& args)
const
49
{
50
auto
const
sub =
env
.now() + args.
subscriptionOffset
;
51
auto
const
red = sub + args.
investmentWindow
;
52
auto
[jv,
keylet
] =
create
(
53
{.owner = args.
owner
,
54
.asset = args.
asset
,
55
.flags = args.
flags
,
56
.vaultKind = std::to_underlying(
VaultKind::ClosedEnded
),
57
.subscriptionDate =
static_cast<
std::uint32_t
>
(sub.time_since_epoch().count()),
58
.redemptionDate =
static_cast<
std::uint32_t
>
(red.time_since_epoch().count())});
59
return
{jv,
keylet
, sub};
60
}
61
62
void
63
Vault::closePastSubscription
(
NetClock::time_point
subscriptionDate)
const
64
{
65
env
.close(subscriptionDate +
std::chrono::seconds
{1});
66
}
67
68
json::Value
69
Vault::set
(
SetArgs
const
& args)
70
{
71
json::Value
jv;
72
jv[jss::TransactionType] = jss::VaultSet;
73
jv[jss::Account] = args.
owner
.
human
();
74
jv[sfVaultID] =
to_string
(args.
id
);
75
return
jv;
76
}
77
78
json::Value
79
Vault::del
(
DeleteArgs
const
& args)
80
{
81
json::Value
jv;
82
jv[jss::TransactionType] = jss::VaultDelete;
83
jv[jss::Account] = args.
owner
.
human
();
84
jv[sfVaultID] =
to_string
(args.
id
);
85
return
jv;
86
}
87
88
json::Value
89
Vault::deposit
(
DepositArgs
const
& args)
90
{
91
json::Value
jv;
92
jv[jss::TransactionType] = jss::VaultDeposit;
93
jv[jss::Account] = args.
depositor
.
human
();
94
jv[sfVaultID] =
to_string
(args.
id
);
95
jv[jss::Amount] =
toJson
(args.
amount
);
96
return
jv;
97
}
98
99
json::Value
100
Vault::withdraw
(
WithdrawArgs
const
& args)
101
{
102
json::Value
jv;
103
jv[jss::TransactionType] = jss::VaultWithdraw;
104
jv[jss::Account] = args.
depositor
.
human
();
105
jv[sfVaultID] =
to_string
(args.
id
);
106
jv[jss::Amount] =
toJson
(args.
amount
);
107
return
jv;
108
}
109
110
json::Value
111
Vault::clawback
(
ClawbackArgs
const
& args)
112
{
113
json::Value
jv;
114
jv[jss::TransactionType] = jss::VaultClawback;
115
jv[jss::Account] = args.
issuer
.
human
();
116
jv[sfVaultID] =
to_string
(args.
id
);
117
jv[jss::Holder] = args.
holder
.
human
();
118
if
(args.
amount
)
119
jv[jss::Amount] =
toJson
(*args.
amount
);
120
return
jv;
121
}
122
123
}
// namespace xrpl::test::jtx
chrono
json::Value
Represents a JSON value.
Definition
json_value.h:117
xrpl::NetClock::time_point
std::chrono::time_point< NetClock > time_point
Definition
chrono.h:48
xrpl::SeqProxy::rawSequence
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition
SeqProxy.h:62
xrpl::test::jtx::Account::human
std::string const & human() const
Returns the human readable public key.
Definition
jtx/Account.h:113
xrpl::test::jtx::Account::id
AccountID id() const
Returns the Account ID.
Definition
jtx/Account.h:104
cstdint
std::chrono::seconds
std::uint32_t
xrpl::keylet
Keylet computation functions.
Definition
Indexes.h:40
xrpl::keylet::vault
Keylet vault(AccountID const &owner, SeqProxy const &seq) noexcept
Definition
Indexes.cpp:591
xrpl::test::jtx
Definition
Oracle_test.cpp:34
xrpl::VaultKind::ClosedEnded
@ ClosedEnded
Definition
Protocol.h:338
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::toJson
json::Value toJson(Asset const &asset)
Definition
Asset.h:168
optional
xrpl::test::jtx::Vault::ClawbackArgs
Definition
vault.h:118
xrpl::test::jtx::Vault::ClawbackArgs::holder
Account holder
Definition
vault.h:121
xrpl::test::jtx::Vault::ClawbackArgs::issuer
Account issuer
Definition
vault.h:119
xrpl::test::jtx::Vault::ClawbackArgs::amount
std::optional< STAmount > amount
Definition
vault.h:122
xrpl::test::jtx::Vault::ClawbackArgs::id
UInt256 id
Definition
vault.h:120
xrpl::test::jtx::Vault::CreateArgs
Definition
vault.h:26
xrpl::test::jtx::Vault::CreateArgs::owner
Account owner
Definition
vault.h:27
xrpl::test::jtx::Vault::CreateArgs::asset
Asset asset
Definition
vault.h:28
xrpl::test::jtx::Vault::CreateArgs::vaultKind
std::optional< std::uint8_t > vaultKind
Definition
vault.h:31
xrpl::test::jtx::Vault::CreateArgs::subscriptionDate
std::optional< std::uint32_t > subscriptionDate
Definition
vault.h:33
xrpl::test::jtx::Vault::CreateArgs::redemptionDate
std::optional< std::uint32_t > redemptionDate
Definition
vault.h:35
xrpl::test::jtx::Vault::CreateArgs::leVersion
std::optional< VaultVersion > leVersion
Definition
vault.h:37
xrpl::test::jtx::Vault::CreateArgs::flags
std::optional< std::uint32_t > flags
Definition
vault.h:29
xrpl::test::jtx::Vault::CreateClosedEndedArgs
Definition
vault.h:48
xrpl::test::jtx::Vault::CreateClosedEndedArgs::investmentWindow
NetClock::duration investmentWindow
Definition
vault.h:54
xrpl::test::jtx::Vault::CreateClosedEndedArgs::subscriptionOffset
NetClock::duration subscriptionOffset
Definition
vault.h:53
xrpl::test::jtx::Vault::CreateClosedEndedArgs::flags
std::optional< std::uint32_t > flags
Definition
vault.h:51
xrpl::test::jtx::Vault::CreateClosedEndedArgs::asset
Asset asset
Definition
vault.h:50
xrpl::test::jtx::Vault::CreateClosedEndedArgs::owner
Account owner
Definition
vault.h:49
xrpl::test::jtx::Vault::DeleteArgs
Definition
vault.h:89
xrpl::test::jtx::Vault::DeleteArgs::id
UInt256 id
Definition
vault.h:91
xrpl::test::jtx::Vault::DeleteArgs::owner
Account owner
Definition
vault.h:90
xrpl::test::jtx::Vault::DepositArgs
Definition
vault.h:98
xrpl::test::jtx::Vault::DepositArgs::id
UInt256 id
Definition
vault.h:100
xrpl::test::jtx::Vault::DepositArgs::depositor
Account depositor
Definition
vault.h:99
xrpl::test::jtx::Vault::DepositArgs::amount
STAmount amount
Definition
vault.h:101
xrpl::test::jtx::Vault::SetArgs
Definition
vault.h:80
xrpl::test::jtx::Vault::SetArgs::id
UInt256 id
Definition
vault.h:82
xrpl::test::jtx::Vault::SetArgs::owner
Account owner
Definition
vault.h:81
xrpl::test::jtx::Vault::WithdrawArgs
Definition
vault.h:108
xrpl::test::jtx::Vault::WithdrawArgs::id
UInt256 id
Definition
vault.h:110
xrpl::test::jtx::Vault::WithdrawArgs::depositor
Account depositor
Definition
vault.h:109
xrpl::test::jtx::Vault::WithdrawArgs::amount
STAmount amount
Definition
vault.h:111
xrpl::test::jtx::Vault::create
std::tuple< json::Value, Keylet > create(CreateArgs const &args) const
Return a VaultCreate transaction and the Vault's expected keylet.
Definition
vault.cpp:26
xrpl::test::jtx::Vault::withdraw
static json::Value withdraw(WithdrawArgs const &args)
Definition
vault.cpp:100
xrpl::test::jtx::Vault::del
static json::Value del(DeleteArgs const &args)
Definition
vault.cpp:79
xrpl::test::jtx::Vault::clawback
static json::Value clawback(ClawbackArgs const &args)
Definition
vault.cpp:111
xrpl::test::jtx::Vault::set
static json::Value set(SetArgs const &args)
Definition
vault.cpp:69
xrpl::test::jtx::Vault::env
Env & env
Definition
vault.h:23
xrpl::test::jtx::Vault::createClosedEnded
std::tuple< json::Value, Keylet, NetClock::time_point > createClosedEnded(CreateClosedEndedArgs const &args) const
Return a VaultCreate transaction for a closed-ended vault, its expected keylet, and the vault's Subsc...
Definition
vault.cpp:48
xrpl::test::jtx::Vault::closePastSubscription
void closePastSubscription(NetClock::time_point subscriptionDate) const
Advance env's clock to just past subscriptionDate, moving a closed-ended vault from the Subscription ...
Definition
vault.cpp:63
xrpl::test::jtx::Vault::deposit
static json::Value deposit(DepositArgs const &args)
Definition
vault.cpp:89
tuple
utility
Generated by
1.17.0