rippled
Loading...
Searching...
No Matches
trust.cpp
1#include <test/jtx/trust.h>
2
3#include <xrpl/basics/contract.h>
4#include <xrpl/protocol/jss.h>
5
6#include <stdexcept>
7
8namespace ripple {
9namespace test {
10namespace jtx {
11
13trust(Account const& account, STAmount const& amount, std::uint32_t flags)
14{
15 if (isXRP(amount))
16 Throw<std::runtime_error>("trust() requires IOU");
17 Json::Value jv;
18 jv[jss::Account] = account.human();
19 jv[jss::LimitAmount] = amount.getJson(JsonOptions::none);
20 jv[jss::TransactionType] = jss::TrustSet;
21 jv[jss::Flags] = flags;
22 return jv;
23}
24
25// This function overload is especially useful for modelling Authorised trust
26// lines. account (first function parameter) is the issuing authority, it
27// authorises peer (third function parameter) to hold a certain currency
28// (amount, the second function parameter)
31 Account const& account,
32 STAmount const& amount,
33 Account const& peer,
35{
36 if (isXRP(amount))
37 Throw<std::runtime_error>("trust() requires IOU");
38 Json::Value jv;
39 jv[jss::Account] = account.human();
40 {
41 auto& ja = jv[jss::LimitAmount] = amount.getJson(JsonOptions::none);
42 ja[jss::issuer] = peer.human();
43 }
44 jv[jss::TransactionType] = jss::TrustSet;
45 jv[jss::Flags] = flags;
46 return jv;
47}
48
51 Account const& account,
52 STAmount const& amount,
53 std::optional<Account> const& mptHolder)
54{
55 Json::Value jv;
56 jv[jss::Account] = account.human();
57 jv[jss::Amount] = amount.getJson(JsonOptions::none);
58 jv[jss::TransactionType] = jss::Clawback;
59
60 if (mptHolder)
61 jv[sfHolder.jsonName] = mptHolder->human();
62
63 return jv;
64}
65
66} // namespace jtx
67} // namespace test
68} // namespace ripple
Represents a JSON value.
Definition json_value.h:130
Json::Value getJson(JsonOptions=JsonOptions::none) const override
Definition STAmount.cpp:753
Immutable cryptographic account descriptor.
Definition Account.h:20
std::string const & human() const
Returns the human readable public key.
Definition Account.h:99
Match set account flags.
Definition flags.h:109
Json::Value claw(Account const &account, STAmount const &amount, std::optional< Account > const &mptHolder)
Definition trust.cpp:50
Json::Value trust(Account const &account, STAmount const &amount, std::uint32_t flags)
Modify a trust line.
Definition trust.cpp:13
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
bool isXRP(AccountID const &c)
Definition AccountID.h:71