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#include <xrpl/basics/contract.h>
22#include <xrpl/protocol/jss.h>
23#include <stdexcept>
24
25namespace ripple {
26namespace test {
27namespace jtx {
28
30trust(Account const& account, STAmount const& amount, std::uint32_t flags)
31{
32 if (isXRP(amount))
33 Throw<std::runtime_error>("trust() requires IOU");
34 Json::Value jv;
35 jv[jss::Account] = account.human();
36 jv[jss::LimitAmount] = amount.getJson(JsonOptions::none);
37 jv[jss::TransactionType] = jss::TrustSet;
38 jv[jss::Flags] = flags;
39 return jv;
40}
41
42// This function overload is especially useful for modelling Authorised trust
43// lines. account (first function parameter) is the issuing authority, it
44// authorises peer (third function parameter) to hold a certain currency
45// (amount, the second function parameter)
48 Account const& account,
49 STAmount const& amount,
50 Account const& peer,
52{
53 if (isXRP(amount))
54 Throw<std::runtime_error>("trust() requires IOU");
55 Json::Value jv;
56 jv[jss::Account] = account.human();
57 {
58 auto& ja = jv[jss::LimitAmount] = amount.getJson(JsonOptions::none);
59 ja[jss::issuer] = peer.human();
60 }
61 jv[jss::TransactionType] = jss::TrustSet;
62 jv[jss::Flags] = flags;
63 return jv;
64}
65
68 Account const& account,
69 STAmount const& amount,
70 std::optional<Account> const& mptHolder)
71{
72 Json::Value jv;
73 jv[jss::Account] = account.human();
74 jv[jss::Amount] = amount.getJson(JsonOptions::none);
75 jv[jss::TransactionType] = jss::Clawback;
76
77 if (mptHolder)
78 jv[sfHolder.jsonName] = mptHolder->human();
79
80 return jv;
81}
82
83} // namespace jtx
84} // namespace test
85} // namespace ripple
Represents a JSON value.
Definition: json_value.h:147
Json::Value getJson(JsonOptions) const override
Definition: STAmount.cpp:604
Immutable cryptographic account descriptor.
Definition: Account.h:38
std::string const & human() const
Returns the human readable public key.
Definition: Account.h:113
Match set account flags.
Definition: flags.h:112
Json::Value claw(Account const &account, STAmount const &amount, std::optional< Account > const &mptHolder)
Definition: trust.cpp:67
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition: trust.cpp:30
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