rippled
Loading...
Searching...
No Matches
escrow.h
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#ifndef RIPPLE_TEST_JTX_ESCROW_H_INCLUDED
21#define RIPPLE_TEST_JTX_ESCROW_H_INCLUDED
22
23#include <test/jtx/Account.h>
24#include <test/jtx/Env.h>
25#include <test/jtx/owners.h>
26#include <test/jtx/rate.h>
27
28#include <xrpl/protocol/Indexes.h>
29
30namespace ripple {
31namespace test {
32namespace jtx {
33
35namespace escrow {
36
38create(AccountID const& account, AccountID const& to, STAmount const& amount);
39
40inline Json::Value
41create(Account const& account, Account const& to, STAmount const& amount)
42{
43 return create(account.id(), to.id(), amount);
44}
45
47finish(AccountID const& account, AccountID const& from, std::uint32_t seq);
48
49inline Json::Value
50finish(Account const& account, Account const& from, std::uint32_t seq)
51{
52 return finish(account.id(), from.id(), seq);
53}
54
56cancel(AccountID const& account, Account const& from, std::uint32_t seq);
57
58inline Json::Value
59cancel(Account const& account, Account const& from, std::uint32_t seq)
60{
61 return cancel(account.id(), from, seq);
62}
63
64Rate
65rate(Env& env, Account const& account, std::uint32_t const& seq);
66
67// A PreimageSha256 fulfillments and its associated condition.
68std::array<std::uint8_t, 4> const fb1 = {{0xA0, 0x02, 0x80, 0x00}};
69
71 {0xA0, 0x25, 0x80, 0x20, 0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC,
72 0x1C, 0x14, 0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24,
73 0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B, 0x93, 0x4C, 0xA4, 0x95,
74 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55, 0x81, 0x01, 0x00}};
75
76// Another PreimageSha256 fulfillments and its associated condition.
78 {0xA0, 0x05, 0x80, 0x03, 0x61, 0x61, 0x61}};
79
81 {0xA0, 0x25, 0x80, 0x20, 0x98, 0x34, 0x87, 0x6D, 0xCF, 0xB0,
82 0x5C, 0xB1, 0x67, 0xA5, 0xC2, 0x49, 0x53, 0xEB, 0xA5, 0x8C,
83 0x4A, 0xC8, 0x9B, 0x1A, 0xDF, 0x57, 0xF2, 0x8F, 0x2F, 0x9D,
84 0x09, 0xAF, 0x10, 0x7E, 0xE8, 0xF0, 0x81, 0x01, 0x03}};
85
86// Another PreimageSha256 fulfillment and its associated condition.
88 {0xA0, 0x06, 0x80, 0x04, 0x6E, 0x69, 0x6B, 0x62}};
89
91 {0xA0, 0x25, 0x80, 0x20, 0x6E, 0x4C, 0x71, 0x45, 0x30, 0xC0,
92 0xA4, 0x26, 0x8B, 0x3F, 0xA6, 0x3B, 0x1B, 0x60, 0x6F, 0x2D,
93 0x26, 0x4A, 0x2D, 0x85, 0x7B, 0xE8, 0xA0, 0x9C, 0x1D, 0xFD,
94 0x57, 0x0D, 0x15, 0x85, 0x8B, 0xD4, 0x81, 0x01, 0x04}};
95
98{
99private:
101
102public:
103 explicit finish_time(NetClock::time_point const& value) : value_(value)
104 {
105 }
106
107 void
108 operator()(Env&, JTx& jt) const
109 {
110 jt.jv[sfFinishAfter.jsonName] = value_.time_since_epoch().count();
111 }
112};
113
116{
117private:
119
120public:
121 explicit cancel_time(NetClock::time_point const& value) : value_(value)
122 {
123 }
124
125 void
127 {
128 jt.jv[sfCancelAfter.jsonName] = value_.time_since_epoch().count();
129 }
130};
131
133{
134private:
136
137public:
138 explicit condition(Slice const& cond) : value_(strHex(cond))
139 {
140 }
141
142 template <size_t N>
144 : condition(makeSlice(c))
145 {
146 }
147
148 void
149 operator()(Env&, JTx& jt) const
150 {
151 jt.jv[sfCondition.jsonName] = value_;
152 }
153};
154
156{
157private:
159
160public:
162 {
163 }
164
165 template <size_t N>
168 {
169 }
170
171 void
172 operator()(Env&, JTx& jt) const
173 {
174 jt.jv[sfFulfillment.jsonName] = value_;
175 }
176};
177
178} // namespace escrow
179
180} // namespace jtx
181
182} // namespace test
183} // namespace ripple
184
185#endif
Represents a JSON value.
Definition: json_value.h:149
An immutable linear range of bytes.
Definition: Slice.h:46
Immutable cryptographic account descriptor.
Definition: Account.h:39
AccountID id() const
Returns the Account ID.
Definition: Account.h:107
A transaction testing environment.
Definition: Env.h:121
std::array< std::uint8_t, 7 > const fb2
Definition: escrow.h:77
std::array< std::uint8_t, 8 > const fb3
Definition: escrow.h:87
std::array< std::uint8_t, 39 > const cb1
Definition: escrow.h:70
std::array< std::uint8_t, 39 > const cb3
Definition: escrow.h:90
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
std::array< std::uint8_t, 39 > const cb2
Definition: escrow.h:80
std::array< std::uint8_t, 4 > const fb1
Definition: escrow.h:68
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 strHex(FwdIt begin, FwdIt end)
Definition: strHex.h:30
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
Definition: Slice.h:244
Represents a transfer rate.
Definition: Rate.h:40
Execution context for applying a JSON transaction.
Definition: JTx.h:45
Json::Value jv
Definition: JTx.h:46
Set the "CancelAfter" time tag on a JTx.
Definition: escrow.h:116
NetClock::time_point value_
Definition: escrow.h:118
void operator()(jtx::Env &, jtx::JTx &jt) const
Definition: escrow.h:126
cancel_time(NetClock::time_point const &value)
Definition: escrow.h:121
condition(Slice const &cond)
Definition: escrow.h:138
void operator()(Env &, JTx &jt) const
Definition: escrow.h:149
condition(std::array< std::uint8_t, N > const &c)
Definition: escrow.h:143
Set the "FinishAfter" time tag on a JTx.
Definition: escrow.h:98
finish_time(NetClock::time_point const &value)
Definition: escrow.h:103
NetClock::time_point value_
Definition: escrow.h:100
void operator()(Env &, JTx &jt) const
Definition: escrow.h:108
void operator()(Env &, JTx &jt) const
Definition: escrow.h:172
fulfillment(std::array< std::uint8_t, N > f)
Definition: escrow.h:166
Set the sequence number on a JTx.
Definition: seq.h:34
T time_since_epoch(T... args)