rippled
Loading...
Searching...
No Matches
escrow.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2019 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/escrow.h>
21
22#include <xrpl/protocol/TxFlags.h>
23#include <xrpl/protocol/jss.h>
24
25namespace ripple {
26namespace test {
27namespace jtx {
28
30namespace escrow {
31
33create(AccountID const& account, AccountID const& to, STAmount const& amount)
34{
35 Json::Value jv;
36 jv[jss::TransactionType] = jss::EscrowCreate;
37 jv[jss::Flags] = tfFullyCanonicalSig;
38 jv[jss::Account] = to_string(account);
39 jv[jss::Destination] = to_string(to);
40 jv[jss::Amount] = amount.getJson(JsonOptions::none);
41 return jv;
42}
43
45finish(AccountID const& account, AccountID const& from, std::uint32_t seq)
46{
47 Json::Value jv;
48 jv[jss::TransactionType] = jss::EscrowFinish;
49 jv[jss::Flags] = tfFullyCanonicalSig;
50 jv[jss::Account] = to_string(account);
51 jv[sfOwner.jsonName] = to_string(from);
52 jv[sfOfferSequence.jsonName] = seq;
53 return jv;
54}
55
57cancel(AccountID const& account, Account const& from, std::uint32_t seq)
58{
59 Json::Value jv;
60 jv[jss::TransactionType] = jss::EscrowCancel;
61 jv[jss::Flags] = tfFullyCanonicalSig;
62 jv[jss::Account] = to_string(account);
63 jv[sfOwner.jsonName] = from.human();
64 jv[sfOfferSequence.jsonName] = seq;
65 return jv;
66}
67
68Rate
69rate(Env& env, Account const& account, std::uint32_t const& seq)
70{
71 auto const sle = env.le(keylet::escrow(account.id(), seq));
72 if (sle->isFieldPresent(sfTransferRate))
73 return ripple::Rate((*sle)[sfTransferRate]);
74 return Rate{0};
75}
76
77} // namespace escrow
78
79} // namespace jtx
80
81} // namespace test
82} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
Json::Value getJson(JsonOptions=JsonOptions::none) const override
Definition STAmount.cpp:795
Immutable cryptographic account descriptor.
Definition Account.h:39
std::string const & human() const
Returns the human readable public key.
Definition Account.h:118
A transaction testing environment.
Definition Env.h:121
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Definition Env.cpp:277
Keylet escrow(AccountID const &src, std::uint32_t seq) noexcept
An escrow entry.
Definition Indexes.cpp:389
Json::Value create(AccountID const &account, AccountID const &to, STAmount const &amount)
Definition escrow.cpp:33
Rate rate(Env &env, Account const &account, std::uint32_t const &seq)
Definition escrow.cpp:69
Json::Value cancel(AccountID const &account, Account const &from, std::uint32_t seq)
Definition escrow.cpp:57
Json::Value finish(AccountID const &account, AccountID const &from, std::uint32_t seq)
Definition escrow.cpp:45
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:630
constexpr std::uint32_t tfFullyCanonicalSig
Transaction flags.
Definition TxFlags.h:60
Represents a transfer rate.
Definition Rate.h:40
Set the sequence number on a JTx.
Definition seq.h:34