rippled
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 #include <ripple/protocol/jss.h>
22 #include <ripple/protocol/TxFlags.h>
23 
24 namespace ripple {
25 namespace test {
26 namespace jtx {
27 
28 namespace check {
29 
30 // Create a check.
32 create (jtx::Account const& account,
33  jtx::Account const& dest, STAmount const& sendMax)
34 {
35  Json::Value jv;
36  jv[sfAccount.jsonName] = account.human();
38  jv[sfDestination.jsonName] = dest.human();
39  jv[sfTransactionType.jsonName] = jss::CheckCreate;
41  return jv;
42 }
43 
44 // Cash a check requiring that a specific amount be delivered.
46 cash (jtx::Account const& dest,
47  uint256 const& checkId, STAmount const& amount)
48 {
49  Json::Value jv;
50  jv[sfAccount.jsonName] = dest.human();
52  jv[sfCheckID.jsonName] = to_string (checkId);
53  jv[sfTransactionType.jsonName] = jss::CheckCash;
55  return jv;
56 }
57 
58 // Cash a check requiring that at least a minimum amount be delivered.
60 cash (jtx::Account const& dest,
61  uint256 const& checkId, DeliverMin const& atLeast)
62 {
63  Json::Value jv;
64  jv[sfAccount.jsonName] = dest.human();
66  jv[sfCheckID.jsonName] = to_string (checkId);
67  jv[sfTransactionType.jsonName] = jss::CheckCash;
69  return jv;
70 }
71 
72 // Cancel a check.
74 cancel (jtx::Account const& dest, uint256 const& checkId)
75 {
76  Json::Value jv;
77  jv[sfAccount.jsonName] = dest.human();
78  jv[sfCheckID.jsonName] = to_string (checkId);
79  jv[sfTransactionType.jsonName] = jss::CheckCancel;
81  return jv;
82 }
83 
84 } // check
85 
86 } // jtx
87 } // test
88 } // ripple
ripple::test::jtx::check::create
Json::Value create(jtx::Account const &account, jtx::Account const &dest, STAmount const &sendMax)
Create a check.
Definition: check.cpp:32
ripple::STAmount::getJson
Json::Value getJson(JsonOptions) const override
Definition: STAmount.cpp:582
ripple::sfAccount
const SF_Account sfAccount(access, STI_ACCOUNT, 1, "Account")
Definition: SField.h:460
ripple::sfFlags
const SF_U32 sfFlags(access, STI_UINT32, 2, "Flags")
Definition: SField.h:338
ripple::test::jtx::Account::human
std::string const & human() const
Returns the human readable public key.
Definition: Account.h:104
Json::check
void check(bool condition, std::string const &message)
Definition: json/Writer.h:234
ripple::to_string
std::string to_string(ListDisposition disposition)
Definition: ValidatorList.cpp:41
ripple::sfAmount
const SF_Amount sfAmount(access, STI_AMOUNT, 1, "Amount")
Definition: SField.h:423
ripple::SField::jsonName
const Json::StaticString jsonName
Definition: SField.h:140
ripple::test::jtx::check::cancel
Json::Value cancel(jtx::Account const &dest, uint256 const &checkId)
Cancel a check.
Definition: check.cpp:74
ripple::base_uint
Definition: base_uint.h:65
ripple::sfSendMax
const SF_Amount sfSendMax(access, STI_AMOUNT, 9, "SendMax")
Definition: SField.h:431
ripple::JsonOptions::none
@ none
ripple::test::jtx::check::DeliverMin
Type used to specify DeliverMin for cashing a check.
Definition: check.h:45
ripple::sfTransactionType
const SF_U16 sfTransactionType(access, STI_UINT16, 2, "TransactionType")
Definition: SField.h:331
ripple::STAmount
Definition: STAmount.h:42
ripple::test::jtx::check::DeliverMin::value
STAmount value
Definition: check.h:47
ripple::tfUniversal
const std::uint32_t tfUniversal
Definition: TxFlags.h:49
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::sfDeliverMin
const SF_Amount sfDeliverMin(access, STI_AMOUNT, 10, "DeliverMin")
Definition: SField.h:432
ripple::test::jtx::check::cash
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:46
ripple::sfDestination
const SF_Account sfDestination(access, STI_ACCOUNT, 3, "Destination")
Definition: SField.h:462
ripple::sfCheckID
const SF_U256 sfCheckID(access, STI_HASH256, 24, "CheckID")
Definition: SField.h:420
ripple::test::jtx::Account
Immutable cryptographic account descriptor.
Definition: Account.h:37
Json::Value
Represents a JSON value.
Definition: json_value.h:141