rippled
Loading...
Searching...
No Matches
vault.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2024 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 <test/jtx/Env.h>
21#include <test/jtx/vault.h>
22
23#include <xrpl/json/json_value.h>
24#include <xrpl/protocol/STAmount.h>
25#include <xrpl/protocol/jss.h>
26
27#include <optional>
28
29namespace ripple {
30namespace test {
31namespace jtx {
32
35{
36 auto keylet = keylet::vault(args.owner.id(), env.seq(args.owner));
37 Json::Value jv;
38 jv[jss::TransactionType] = jss::VaultCreate;
39 jv[jss::Account] = args.owner.human();
40 jv[jss::Asset] = to_json(args.asset);
41 jv[jss::Fee] = STAmount(env.current()->fees().increment).getJson();
42 if (args.flags)
43 jv[jss::Flags] = *args.flags;
44 return {jv, keylet};
45}
46
48Vault::set(SetArgs const& args)
49{
50 Json::Value jv;
51 jv[jss::TransactionType] = jss::VaultSet;
52 jv[jss::Account] = args.owner.human();
53 jv[sfVaultID] = to_string(args.id);
54 return jv;
55}
56
59{
60 Json::Value jv;
61 jv[jss::TransactionType] = jss::VaultDelete;
62 jv[jss::Account] = args.owner.human();
63 jv[sfVaultID] = to_string(args.id);
64 return jv;
65}
66
69{
70 Json::Value jv;
71 jv[jss::TransactionType] = jss::VaultDeposit;
72 jv[jss::Account] = args.depositor.human();
73 jv[sfVaultID] = to_string(args.id);
74 jv[jss::Amount] = to_json(args.amount);
75 return jv;
76}
77
80{
81 Json::Value jv;
82 jv[jss::TransactionType] = jss::VaultWithdraw;
83 jv[jss::Account] = args.depositor.human();
84 jv[sfVaultID] = to_string(args.id);
85 jv[jss::Amount] = to_json(args.amount);
86 return jv;
87}
88
91{
92 Json::Value jv;
93 jv[jss::TransactionType] = jss::VaultClawback;
94 jv[jss::Account] = args.issuer.human();
95 jv[sfVaultID] = to_string(args.id);
96 jv[jss::Holder] = args.holder.human();
97 if (args.amount)
98 jv[jss::Amount] = to_json(*args.amount);
99 return jv;
100}
101
102} // namespace jtx
103} // namespace test
104} // namespace ripple
Represents a JSON value.
Definition: json_value.h:150
Json::Value getJson(JsonOptions=JsonOptions::none) const override
Definition: STAmount.cpp:639
AccountID id() const
Returns the Account ID.
Definition: Account.h:107
std::string const & human() const
Returns the human readable public key.
Definition: Account.h:114
std::uint32_t seq(Account const &account) const
Returns the next sequence number on account.
Definition: Env.cpp:212
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition: Env.h:331
Keylet vault(AccountID const &owner, std::uint32_t seq) noexcept
Definition: Indexes.cpp:557
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
Json::Value to_json(Asset const &asset)
Definition: Asset.h:123
std::string to_string(base_uint< Bits, Tag > const &a)
Definition: base_uint.h:630
std::optional< STAmount > amount
Definition: vault.h:98
std::optional< std::uint32_t > flags
Definition: vault.h:48
Json::Value set(SetArgs const &args)
Definition: vault.cpp:48
std::tuple< Json::Value, Keylet > create(CreateArgs const &args)
Return a VaultCreate transaction and the Vault's expected keylet.
Definition: vault.cpp:34
Json::Value withdraw(WithdrawArgs const &args)
Definition: vault.cpp:79
Json::Value del(DeleteArgs const &args)
Definition: vault.cpp:58
Json::Value clawback(ClawbackArgs const &args)
Definition: vault.cpp:90
Json::Value deposit(DepositArgs const &args)
Definition: vault.cpp:68