xrpld
Loading...
Searching...
No Matches
escrow.h
1#pragma once
2
3#include <test/jtx/Account.h>
4#include <test/jtx/Env.h>
5#include <test/jtx/JTx.h>
6#include <test/jtx/TestHelpers.h>
7
8#include <xrpl/basics/Slice.h>
9#include <xrpl/basics/strHex.h>
10#include <xrpl/json/json_value.h>
11#include <xrpl/protocol/AccountID.h>
12#include <xrpl/protocol/Rate.h>
13#include <xrpl/protocol/SField.h>
14#include <xrpl/protocol/STAmount.h>
15
16#include <array>
17#include <cstddef>
18#include <cstdint>
19#include <string>
20#include <utility>
21
26
28create(AccountID const& account, AccountID const& to, STAmount const& amount);
29
30inline json::Value
31create(Account const& account, Account const& to, STAmount const& amount)
32{
33 return create(account.id(), to.id(), amount);
34}
35
37finish(AccountID const& account, AccountID const& from, std::uint32_t seq);
38
39inline json::Value
40finish(Account const& account, Account const& from, std::uint32_t seq)
41{
42 return finish(account.id(), from.id(), seq);
43}
44
46cancel(AccountID const& account, Account const& from, std::uint32_t seq);
47
48inline json::Value
49cancel(Account const& account, Account const& from, std::uint32_t seq)
50{
51 return cancel(account.id(), from, seq);
52}
53
54Rate
55rate(Env const& env, Account const& account, std::uint32_t const& seq);
56
57// A PreimageSha256 fulfillments and its associated kCondition.
58std::array<std::uint8_t, 4> const kFb1 = {{0xA0, 0x02, 0x80, 0x00}};
59
61 {
62 0xA0, 0x25, 0x80, 0x20, 0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC, 0x1C, 0x14, 0x9A,
63 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24, 0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B,
64 0x93, 0x4C, 0xA4, 0x95, 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55, 0x81, 0x01, 0x00,
65 },
66};
67
68// Another PreimageSha256 fulfillments and its associated kCondition.
69std::array<std::uint8_t, 7> const kFb2 = {{0xA0, 0x05, 0x80, 0x03, 0x61, 0x61, 0x61}};
70
72 {
73 0xA0, 0x25, 0x80, 0x20, 0x98, 0x34, 0x87, 0x6D, 0xCF, 0xB0, 0x5C, 0xB1, 0x67,
74 0xA5, 0xC2, 0x49, 0x53, 0xEB, 0xA5, 0x8C, 0x4A, 0xC8, 0x9B, 0x1A, 0xDF, 0x57,
75 0xF2, 0x8F, 0x2F, 0x9D, 0x09, 0xAF, 0x10, 0x7E, 0xE8, 0xF0, 0x81, 0x01, 0x03,
76 },
77};
78
79// Another PreimageSha256 kFulfillment and its associated kCondition.
80std::array<std::uint8_t, 8> const kFb3 = {{0xA0, 0x06, 0x80, 0x04, 0x6E, 0x69, 0x6B, 0x62}};
81
83 {
84 0xA0, 0x25, 0x80, 0x20, 0x6E, 0x4C, 0x71, 0x45, 0x30, 0xC0, 0xA4, 0x26, 0x8B,
85 0x3F, 0xA6, 0x3B, 0x1B, 0x60, 0x6F, 0x2D, 0x26, 0x4A, 0x2D, 0x85, 0x7B, 0xE8,
86 0xA0, 0x9C, 0x1D, 0xFD, 0x57, 0x0D, 0x15, 0x85, 0x8B, 0xD4, 0x81, 0x01, 0x04,
87 },
88};
89
93auto const kFinishTime = JTxFieldWrapper<TimePointField>(sfFinishAfter);
94
98auto const kCancelTime = JTxFieldWrapper<TimePointField>(sfCancelAfter);
99
100auto const kCondition = JTxFieldWrapper<BlobField>(sfCondition);
101
102auto const kFulfillment = JTxFieldWrapper<BlobField>(sfFulfillment);
103
107template <SF_VL const& Field>
109{
110private:
112
113public:
114 explicit HexBlobField(std::string hex) : value_(std::move(hex))
115 {
116 }
117
118 explicit HexBlobField(Slice const& blob) : value_(strHex(blob))
119 {
120 }
121
122 template <size_t N>
124 {
125 }
126
127 void
128 operator()(Env&, JTx& jt) const
129 {
130 // clang-tidy reads a reference template parameter as parenthesized.
131 jt.jv[Field.jsonName] = value_; // NOLINT(readability-redundant-parentheses)
132 }
133};
134
137
138struct Gas
139{
140private:
142
143public:
144 explicit Gas(std::uint32_t const value) : value_(value)
145 {
146 }
147
148 void
149 operator()(Env&, JTx& jt) const
150 {
151 jt.jv[sfGas.jsonName] = value_;
152 }
153};
154
155} // namespace xrpl::test::jtx::escrow
Represents a JSON value.
Definition json_value.h:121
An immutable linear range of bytes.
Definition Slice.h:28
Immutable cryptographic account descriptor.
Definition jtx/Account.h:21
AccountID id() const
Returns the Account ID.
A transaction testing environment.
Definition Env.h:161
STL namespace.
Escrow operations.
Definition escrow.h:25
HexBlobField< sfData > Data
Definition escrow.h:136
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
auto const kCondition
Definition escrow.h:100
auto const kCancelTime
Set the "CancelAfter" time tag on a JTx.
Definition escrow.h:98
auto const kFinishTime
Set the "FinishAfter" time tag on a JTx.
Definition escrow.h:93
HexBlobField< sfBytecode > Bytecode
Definition escrow.h:135
std::array< std::uint8_t, 8 > const kFb3
Definition escrow.h:80
std::array< std::uint8_t, 7 > const kFb2
Definition escrow.h:69
std::array< std::uint8_t, 39 > const kCb2
Definition escrow.h:71
auto const kFulfillment
Definition escrow.h:102
Rate rate(Env const &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::array< std::uint8_t, 4 > const kFb1
Definition escrow.h:58
std::array< std::uint8_t, 39 > const kCb1
Definition escrow.h:60
std::array< std::uint8_t, 39 > const kCb3
Definition escrow.h:82
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:13
Slice makeSlice(std::array< T, N > const &a)
Definition Slice.h:228
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
Represents a transfer rate.
Definition Rate.h:21
Execution context for applying a JSON transaction.
Definition JTx.h:27
json::Value jv
Definition JTx.h:28
Gas(std::uint32_t const value)
Definition escrow.h:144
void operator()(Env &, JTx &jt) const
Definition escrow.h:149
Set a hex-encoded blob field on a JTx.
Definition escrow.h:109
void operator()(Env &, JTx &jt) const
Definition escrow.h:128
HexBlobField(std::array< std::uint8_t, N > const &blob)
Definition escrow.h:123
HexBlobField(Slice const &blob)
Definition escrow.h:118