xrpld
Loading...
Searching...
No Matches
escrow.cpp
1#include <test/jtx/escrow.h>
2
3#include <test/jtx/Account.h>
4#include <test/jtx/Env.h>
5
6#include <xrpl/json/json_value.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/Rate.h>
10#include <xrpl/protocol/SField.h>
11#include <xrpl/protocol/STAmount.h>
12#include <xrpl/protocol/TxFlags.h>
13#include <xrpl/protocol/jss.h>
14
15#include <cstdint>
16
19
20json::Value
21create(AccountID const& account, AccountID const& to, STAmount const& amount)
22{
23 json::Value jv;
24 jv[jss::TransactionType] = jss::EscrowCreate;
25 jv[jss::Flags] = tfFullyCanonicalSig;
26 jv[jss::Account] = to_string(account);
27 jv[jss::Destination] = to_string(to);
28 jv[jss::Amount] = amount.getJson(JsonOptions::Values::None);
29 return jv;
30}
31
33finish(AccountID const& account, AccountID const& from, std::uint32_t seq)
34{
35 json::Value jv;
36 jv[jss::TransactionType] = jss::EscrowFinish;
37 jv[jss::Flags] = tfFullyCanonicalSig;
38 jv[jss::Account] = to_string(account);
39 jv[sfOwner.jsonName] = to_string(from);
40 jv[sfOfferSequence.jsonName] = seq;
41 return jv;
42}
43
45cancel(AccountID const& account, Account const& from, std::uint32_t seq)
46{
47 json::Value jv;
48 jv[jss::TransactionType] = jss::EscrowCancel;
49 jv[jss::Flags] = tfFullyCanonicalSig;
50 jv[jss::Account] = to_string(account);
51 jv[sfOwner.jsonName] = from.human();
52 jv[sfOfferSequence.jsonName] = seq;
53 return jv;
54}
55
56Rate
57rate(Env& env, Account const& account, std::uint32_t const& seq)
58{
59 auto const sle = env.le(keylet::escrow(account.id(), seq));
60 if (sle->isFieldPresent(sfTransferRate))
61 return xrpl::Rate((*sle)[sfTransferRate]);
62 return Rate{0};
63}
64
65} // namespace xrpl::test::jtx::escrow
Represents a JSON value.
Definition json_value.h:130
json::Value getJson(JsonOptions=JsonOptions::Values::None) const override
Definition STAmount.cpp:734
Immutable cryptographic account descriptor.
Definition jtx/Account.h:17
std::string const & human() const
Returns the human readable public key.
Definition jtx/Account.h:92
A transaction testing environment.
Definition Env.h:143
SLE::const_pointer le(Account const &account) const
Return an account root.
Definition Env.cpp:284
Keylet escrow(AccountID const &src, std::uint32_t seq) noexcept
An escrow entry.
Definition Indexes.cpp:372
Escrow operations.
Definition escrow.h:12
json::Value create(AccountID const &account, AccountID const &to, STAmount const &amount)
Definition escrow.cpp:21
json::Value cancel(AccountID const &account, Account const &from, std::uint32_t seq)
Definition escrow.cpp:45
Rate rate(Env &env, Account const &account, std::uint32_t const &seq)
Definition escrow.cpp:57
json::Value finish(AccountID const &account, AccountID const &from, std::uint32_t seq)
Definition escrow.cpp:33
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:633
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
constexpr FlagValue tfFullyCanonicalSig
Definition TxFlags.h:42
Represents a transfer rate.
Definition Rate.h:20