rippled
Loading...
Searching...
No Matches
escrow.cpp
1#include <test/jtx/escrow.h>
2
3#include <xrpl/protocol/TxFlags.h>
4#include <xrpl/protocol/jss.h>
5
6namespace ripple {
7namespace test {
8namespace jtx {
9
11namespace escrow {
12
14create(AccountID const& account, AccountID const& to, STAmount const& amount)
15{
16 Json::Value jv;
17 jv[jss::TransactionType] = jss::EscrowCreate;
18 jv[jss::Flags] = tfFullyCanonicalSig;
19 jv[jss::Account] = to_string(account);
20 jv[jss::Destination] = to_string(to);
21 jv[jss::Amount] = amount.getJson(JsonOptions::none);
22 return jv;
23}
24
26finish(AccountID const& account, AccountID const& from, std::uint32_t seq)
27{
28 Json::Value jv;
29 jv[jss::TransactionType] = jss::EscrowFinish;
30 jv[jss::Flags] = tfFullyCanonicalSig;
31 jv[jss::Account] = to_string(account);
32 jv[sfOwner.jsonName] = to_string(from);
33 jv[sfOfferSequence.jsonName] = seq;
34 return jv;
35}
36
38cancel(AccountID const& account, Account const& from, std::uint32_t seq)
39{
40 Json::Value jv;
41 jv[jss::TransactionType] = jss::EscrowCancel;
42 jv[jss::Flags] = tfFullyCanonicalSig;
43 jv[jss::Account] = to_string(account);
44 jv[sfOwner.jsonName] = from.human();
45 jv[sfOfferSequence.jsonName] = seq;
46 return jv;
47}
48
49Rate
50rate(Env& env, Account const& account, std::uint32_t const& seq)
51{
52 auto const sle = env.le(keylet::escrow(account.id(), seq));
53 if (sle->isFieldPresent(sfTransferRate))
54 return ripple::Rate((*sle)[sfTransferRate]);
55 return Rate{0};
56}
57
58} // namespace escrow
59
60} // namespace jtx
61
62} // namespace test
63} // namespace ripple
Represents a JSON value.
Definition json_value.h:130
Json::Value getJson(JsonOptions=JsonOptions::none) const override
Definition STAmount.cpp:753
Immutable cryptographic account descriptor.
Definition Account.h:20
std::string const & human() const
Returns the human readable public key.
Definition Account.h:99
A transaction testing environment.
Definition Env.h:102
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Definition Env.cpp:259
Keylet escrow(AccountID const &src, std::uint32_t seq) noexcept
An escrow entry.
Definition Indexes.cpp:370
Json::Value create(AccountID const &account, AccountID const &to, STAmount const &amount)
Definition escrow.cpp:14
Rate rate(Env &env, Account const &account, std::uint32_t const &seq)
Definition escrow.cpp:50
Json::Value cancel(AccountID const &account, Account const &from, std::uint32_t seq)
Definition escrow.cpp:38
Json::Value finish(AccountID const &account, AccountID const &from, std::uint32_t seq)
Definition escrow.cpp:26
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:611
constexpr std::uint32_t tfFullyCanonicalSig
Transaction flags.
Definition TxFlags.h:41
Represents a transfer rate.
Definition Rate.h:21
Set the sequence number on a JTx.
Definition seq.h:15