xrpld
Loading...
Searching...
No Matches
sponsor.cpp
1#include <test/jtx/sponsor.h>
2
3#include <test/jtx/Account.h>
4#include <test/jtx/Env.h>
5#include <test/jtx/JTx.h>
6
7#include <xrpl/basics/base_uint.h>
8#include <xrpl/json/json_value.h>
9#include <xrpl/json/to_string.h>
10#include <xrpl/protocol/Indexes.h>
11#include <xrpl/protocol/SField.h>
12#include <xrpl/protocol/STAmount.h>
13#include <xrpl/protocol/TxFlags.h>
14#include <xrpl/protocol/jss.h>
15
16#include <cstdint>
17#include <optional>
18
20
22set(jtx::Account const& account,
23 uint32_t flags,
24 std::optional<int32_t> const reserveCountDelta,
25 std::optional<STAmount> const feeAmountDelta,
26 std::optional<STAmount> const maxFee)
27{
28 json::Value jv;
29 jv[jss::TransactionType] = jss::SponsorshipSet;
30 jv[jss::Account] = account.human();
31 jv[sfFlags.jsonName] = flags;
32 if (reserveCountDelta)
33 jv[sfRemainingOwnerCountDelta.jsonName] = *reserveCountDelta;
34 if (feeAmountDelta)
35 jv[sfFeeAmountDelta.jsonName] = feeAmountDelta->getJson(JsonOptions::Values::None);
36 if (maxFee)
37 jv[sfMaxFee.jsonName] = maxFee->getJson(JsonOptions::Values::None);
38 return jv;
39}
40
42del(jtx::Account const& account)
43{
44 json::Value jv;
45 jv[jss::TransactionType] = jss::SponsorshipSet;
46 jv[jss::Account] = account.human();
47 jv[sfFlags.jsonName] = tfDeleteObject;
48 return jv;
49}
50
52transfer(jtx::Account const& account, uint32_t flags, std::optional<uint256> const& index)
53{
54 json::Value jv;
55 jv[jss::TransactionType] = jss::SponsorshipTransfer;
56 jv[jss::Account] = account.human();
57 jv[sfFlags.jsonName] = flags;
58 if (index)
59 jv[sfObjectID.jsonName] = to_string(*index);
60 return jv;
61}
62
63void
65{
66 jt.jv[sfCounterpartySponsor.jsonName] = sponsor_.human();
67}
68
69void
71{
72 jt.jv[sfSponsee.jsonName] = sponsee_.human();
73}
74
75void
76As::operator()(Env& env, JTx& jt) const
77{
78 jt.jv[sfSponsor.jsonName] = sponsor_.human();
79 jt.jv[sfSponsorFlags.jsonName] = flags_;
80}
81
84{
85 json::Value jvParams;
86 jvParams[jss::ledger_index] = jss::validated;
87 jvParams[jss::sponsorship][jss::sponsor] = sponsor.human();
88 jvParams[jss::sponsorship][jss::sponsee] = sponsee.human();
89 return env.rpc("json", "ledger_entry", to_string(jvParams));
90}
91
94{
95 return env.le(keylet::sponsorship(sponsor, sponsee))->getFieldAmount(sfFeeAmount).xrp();
96}
97
98} // namespace xrpl::test::jtx::sponsor
Represents a JSON value.
Definition json_value.h:117
Immutable cryptographic account descriptor.
Definition jtx/Account.h:21
std::string const & human() const
Returns the human readable public key.
A transaction testing environment.
Definition Env.h:161
SLE::const_pointer le(Account const &account) const
Return an account root.
Definition Env.cpp:311
json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Definition Env.h:1056
Keylet sponsorship(AccountID const &sponsor, AccountID const &sponsee) noexcept
A Sponsorship.
Definition Indexes.cpp:332
json::Value transfer(jtx::Account const &account, uint32_t flags, std::optional< uint256 > const &index)
Definition sponsor.cpp:52
STAmount sponsorshipFeeBalance(jtx::Env &env, jtx::Account const &sponsor, jtx::Account const &sponsee)
Definition sponsor.cpp:93
json::Value ledgerEntry(jtx::Env &env, jtx::Account const &sponsor, jtx::Account const &sponsee)
Definition sponsor.cpp:83
json::Value del(jtx::Account const &account)
Definition sponsor.cpp:42
json::Value set(jtx::Account const &account, uint32_t flags, std::optional< int32_t > const reserveCountDelta, std::optional< STAmount > const feeAmountDelta, std::optional< STAmount > const maxFee)
Definition sponsor.cpp:22
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:651
Execution context for applying a JSON transaction.
Definition JTx.h:27
json::Value jv
Definition JTx.h:28
void operator()(jtx::Env &, jtx::JTx &jtx) const
Definition sponsor.cpp:76
void operator()(jtx::Env &, jtx::JTx &jtx) const
Definition sponsor.cpp:64
void operator()(jtx::Env &, jtx::JTx &jtx) const
Definition sponsor.cpp:70