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/SeqProxy.h>
13#include <xrpl/protocol/TxFlags.h>
14#include <xrpl/protocol/jss.h>
15
16#include <cstdint>
17
22
23json::Value
24create(AccountID const& account, AccountID const& to, STAmount const& amount)
25{
26 json::Value jv;
27 jv[jss::TransactionType] = jss::EscrowCreate;
28 jv[jss::Flags] = tfFullyCanonicalSig;
29 jv[jss::Account] = to_string(account);
30 jv[jss::Destination] = to_string(to);
31 jv[jss::Amount] = amount.getJson(JsonOptions::Values::None);
32 return jv;
33}
34
36finish(AccountID const& account, AccountID const& from, std::uint32_t seq)
37{
38 json::Value jv;
39 jv[jss::TransactionType] = jss::EscrowFinish;
40 jv[jss::Flags] = tfFullyCanonicalSig;
41 jv[jss::Account] = to_string(account);
42 jv[sfOwner.jsonName] = to_string(from);
43 jv[sfOfferSequence.jsonName] = seq;
44 return jv;
45}
46
48cancel(AccountID const& account, Account const& from, std::uint32_t seq)
49{
50 json::Value jv;
51 jv[jss::TransactionType] = jss::EscrowCancel;
52 jv[jss::Flags] = tfFullyCanonicalSig;
53 jv[jss::Account] = to_string(account);
54 jv[sfOwner.jsonName] = from.human();
55 jv[sfOfferSequence.jsonName] = seq;
56 return jv;
57}
58
59Rate
60rate(Env& env, Account const& account, std::uint32_t const& seq)
61{
62 auto const sle = env.le(keylet::escrow(account.id(), SeqProxy::rawSequence(seq)));
63 if (sle->isFieldPresent(sfTransferRate))
64 return xrpl::Rate((*sle)[sfTransferRate]);
65 return Rate{0};
66}
67
68} // namespace xrpl::test::jtx::escrow
Represents a JSON value.
Definition json_value.h:117
json::Value getJson(JsonOptions=JsonOptions::Values::None) const override
Definition STAmount.cpp:734
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition SeqProxy.h:62
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
Keylet escrow(AccountID const &src, SeqProxy const &seq) noexcept
An escrow entry.
Definition Indexes.cpp:388
Escrow operations.
Definition escrow.h:19
json::Value create(AccountID const &account, AccountID const &to, STAmount const &amount)
Definition escrow.cpp:24
json::Value cancel(AccountID const &account, Account const &from, std::uint32_t seq)
Definition escrow.cpp:48
Rate rate(Env &env, Account const &account, std::uint32_t const &seq)
Definition escrow.cpp:60
json::Value finish(AccountID const &account, AccountID const &from, std::uint32_t seq)
Definition escrow.cpp:36
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:651
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
constexpr FlagValue tfFullyCanonicalSig
Definition TxFlags.h:43
Represents a transfer rate.
Definition Rate.h:21