xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
jtx
impl
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
21
namespace
xrpl::test::jtx::escrow
{
22
23
json::Value
24
create
(
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
35
json::Value
36
finish
(
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
47
json::Value
48
cancel
(
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
59
Rate
60
rate
(
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
json::Value
Represents a JSON value.
Definition
json_value.h:117
xrpl::STAmount
Definition
STAmount.h:46
xrpl::STAmount::getJson
json::Value getJson(JsonOptions=JsonOptions::Values::None) const override
Definition
STAmount.cpp:735
xrpl::SeqProxy::rawSequence
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition
SeqProxy.h:62
xrpl::test::jtx::Account
Immutable cryptographic account descriptor.
Definition
jtx/Account.h:21
xrpl::test::jtx::Account::human
std::string const & human() const
Returns the human readable public key.
Definition
jtx/Account.h:113
xrpl::test::jtx::Env
A transaction testing environment.
Definition
Env.h:161
xrpl::test::jtx::Env::le
SLE::const_pointer le(Account const &account) const
Return an account root.
Definition
Env.cpp:311
cstdint
std::uint32_t
xrpl::keylet::escrow
Keylet escrow(AccountID const &src, SeqProxy const &seq) noexcept
An escrow entry.
Definition
Indexes.cpp:418
xrpl::test::jtx::escrow
Escrow operations.
Definition
escrow.h:19
xrpl::test::jtx::escrow::create
json::Value create(AccountID const &account, AccountID const &to, STAmount const &amount)
Definition
escrow.cpp:24
xrpl::test::jtx::escrow::cancel
json::Value cancel(AccountID const &account, Account const &from, std::uint32_t seq)
Definition
escrow.cpp:48
xrpl::test::jtx::escrow::rate
Rate rate(Env &env, Account const &account, std::uint32_t const &seq)
Definition
escrow.cpp:60
xrpl::test::jtx::escrow::finish
json::Value finish(AccountID const &account, AccountID const &from, std::uint32_t seq)
Definition
escrow.cpp:36
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
xrpl::tfFullyCanonicalSig
constexpr FlagValue tfFullyCanonicalSig
Definition
TxFlags.h:43
xrpl::JsonOptions::Values::None
@ None
Definition
STBase.h:27
xrpl::Rate
Represents a transfer rate.
Definition
Rate.h:21
Generated by
1.17.0