rippled
Loading...
Searching...
No Matches
check.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/check.h>
21
22#include <xrpl/protocol/TxFlags.h>
23#include <xrpl/protocol/jss.h>
24
25namespace ripple {
26namespace test {
27namespace jtx {
28
29namespace check {
30
31// Cash a check requiring that a specific amount be delivered.
33cash(jtx::Account const& dest, uint256 const& checkId, STAmount const& amount)
34{
35 Json::Value jv;
36 jv[sfAccount.jsonName] = dest.human();
37 jv[sfAmount.jsonName] = amount.getJson(JsonOptions::none);
38 jv[sfCheckID.jsonName] = to_string(checkId);
39 jv[sfTransactionType.jsonName] = jss::CheckCash;
40 jv[sfFlags.jsonName] = tfUniversal;
41 return jv;
42}
43
44// Cash a check requiring that at least a minimum amount be delivered.
47 jtx::Account const& dest,
48 uint256 const& checkId,
49 DeliverMin const& atLeast)
50{
51 Json::Value jv;
52 jv[sfAccount.jsonName] = dest.human();
53 jv[sfDeliverMin.jsonName] = atLeast.value.getJson(JsonOptions::none);
54 jv[sfCheckID.jsonName] = to_string(checkId);
55 jv[sfTransactionType.jsonName] = jss::CheckCash;
56 jv[sfFlags.jsonName] = tfUniversal;
57 return jv;
58}
59
60// Cancel a check.
62cancel(jtx::Account const& dest, uint256 const& checkId)
63{
64 Json::Value jv;
65 jv[sfAccount.jsonName] = dest.human();
66 jv[sfCheckID.jsonName] = to_string(checkId);
67 jv[sfTransactionType.jsonName] = jss::CheckCancel;
68 jv[sfFlags.jsonName] = tfUniversal;
69 return jv;
70}
71
72} // namespace check
73
74} // namespace jtx
75} // namespace test
76} // namespace ripple
Represents a JSON value.
Definition: json_value.h:150
Json::Value getJson(JsonOptions=JsonOptions::none) const override
Definition: STAmount.cpp:639
Immutable cryptographic account descriptor.
Definition: Account.h:39
std::string const & human() const
Returns the human readable public key.
Definition: Account.h:114
void check(bool condition, std::string const &message)
Definition: json/Writer.h:253
Json::Value cancel(jtx::Account const &dest, uint256 const &checkId)
Cancel a check.
Definition: check.cpp:62
Json::Value cash(jtx::Account const &dest, uint256 const &checkId, STAmount const &amount)
Cash a check requiring that a specific amount be delivered.
Definition: check.cpp:33
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
constexpr std::uint32_t tfUniversal
Definition: TxFlags.h:61
std::string to_string(base_uint< Bits, Tag > const &a)
Definition: base_uint.h:630
Type used to specify DeliverMin for cashing a check.
Definition: check.h:40