rippled
Loading...
Searching...
No Matches
trust.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 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/trust.h>
21
22#include <xrpl/basics/contract.h>
23#include <xrpl/protocol/jss.h>
24
25#include <stdexcept>
26
27namespace ripple {
28namespace test {
29namespace jtx {
30
32trust(Account const& account, STAmount const& amount, std::uint32_t flags)
33{
34 if (isXRP(amount))
35 Throw<std::runtime_error>("trust() requires IOU");
36 Json::Value jv;
37 jv[jss::Account] = account.human();
38 jv[jss::LimitAmount] = amount.getJson(JsonOptions::none);
39 jv[jss::TransactionType] = jss::TrustSet;
40 jv[jss::Flags] = flags;
41 return jv;
42}
43
44// This function overload is especially useful for modelling Authorised trust
45// lines. account (first function parameter) is the issuing authority, it
46// authorises peer (third function parameter) to hold a certain currency
47// (amount, the second function parameter)
50 Account const& account,
51 STAmount const& amount,
52 Account const& peer,
54{
55 if (isXRP(amount))
56 Throw<std::runtime_error>("trust() requires IOU");
57 Json::Value jv;
58 jv[jss::Account] = account.human();
59 {
60 auto& ja = jv[jss::LimitAmount] = amount.getJson(JsonOptions::none);
61 ja[jss::issuer] = peer.human();
62 }
63 jv[jss::TransactionType] = jss::TrustSet;
64 jv[jss::Flags] = flags;
65 return jv;
66}
67
70 Account const& account,
71 STAmount const& amount,
72 std::optional<Account> const& mptHolder)
73{
74 Json::Value jv;
75 jv[jss::Account] = account.human();
76 jv[jss::Amount] = amount.getJson(JsonOptions::none);
77 jv[jss::TransactionType] = jss::Clawback;
78
79 if (mptHolder)
80 jv[sfHolder.jsonName] = mptHolder->human();
81
82 return jv;
83}
84
85} // namespace jtx
86} // namespace test
87} // 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
Match set account flags.
Definition: flags.h:125
Json::Value claw(Account const &account, STAmount const &amount, std::optional< Account > const &mptHolder)
Definition: trust.cpp:69
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition: trust.cpp:32
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
bool isXRP(AccountID const &c)
Definition: AccountID.h:91