rippled
Loading...
Searching...
No Matches
delegate.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2025 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/delegate.h>
21
22#include <xrpl/protocol/jss.h>
23
24namespace ripple {
25namespace test {
26namespace jtx {
27
28namespace delegate {
29
31set(jtx::Account const& account,
32 jtx::Account const& authorize,
33 std::vector<std::string> const& permissions)
34{
35 Json::Value jv;
36 jv[jss::TransactionType] = jss::DelegateSet;
37 jv[jss::Account] = account.human();
38 jv[sfAuthorize.jsonName] = authorize.human();
39 Json::Value permissionsJson(Json::arrayValue);
40 for (auto const& permission : permissions)
41 {
42 Json::Value permissionValue;
43 permissionValue[sfPermissionValue.jsonName] = permission;
44 Json::Value permissionObj;
45 permissionObj[sfPermission.jsonName] = permissionValue;
46 permissionsJson.append(permissionObj);
47 }
48
49 jv[sfPermissions.jsonName] = permissionsJson;
50
51 return jv;
52}
53
55entry(jtx::Env& env, jtx::Account const& account, jtx::Account const& authorize)
56{
57 Json::Value jvParams;
58 jvParams[jss::ledger_index] = jss::validated;
59 jvParams[jss::delegate][jss::account] = account.human();
60 jvParams[jss::delegate][jss::authorize] = authorize.human();
61 return env.rpc("json", "ledger_entry", to_string(jvParams));
62}
63
64} // namespace delegate
65} // namespace jtx
66} // namespace test
67} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
Value & append(Value const &value)
Append value to array at the end.
Immutable cryptographic account descriptor.
Definition Account.h:39
std::string const & human() const
Returns the human readable public key.
Definition Account.h:118
A transaction testing environment.
Definition Env.h:121
Json::Value rpc(unsigned apiVersion, std::unordered_map< std::string, std::string > const &headers, std::string const &cmd, Args &&... args)
Execute an RPC command.
Definition Env.h:791
@ arrayValue
array value (ordered list)
Definition json_value.h:44
Keylet delegate(AccountID const &account, AccountID const &authorizedAccount) noexcept
A keylet for Delegate object.
Definition Indexes.cpp:465
Json::Value entry(jtx::Env &env, jtx::Account const &account, jtx::Account const &authorize)
Definition delegate.cpp:55
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
bool set(T &target, std::string const &name, Section const &section)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:630