rippled
Loading...
Searching...
No Matches
creds.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2024 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/credentials.h>
21
22#include <xrpl/protocol/TxFlags.h>
23#include <xrpl/protocol/jss.h>
24
25namespace ripple {
26namespace test {
27namespace jtx {
28
29namespace credentials {
30
33 jtx::Account const& subject,
34 jtx::Account const& issuer,
35 std::string_view credType)
36{
37 Json::Value jv;
38 jv[jss::TransactionType] = jss::CredentialCreate;
39
40 jv[jss::Account] = issuer.human();
41 jv[jss::Subject] = subject.human();
42 jv[sfCredentialType.jsonName] = strHex(credType);
43
44 return jv;
45}
46
49 jtx::Account const& subject,
50 jtx::Account const& issuer,
51 std::string_view credType)
52{
53 Json::Value jv;
54 jv[jss::TransactionType] = jss::CredentialAccept;
55 jv[jss::Account] = subject.human();
56 jv[jss::Issuer] = issuer.human();
57 jv[sfCredentialType.jsonName] = strHex(credType);
58 return jv;
59}
60
63 jtx::Account const& acc,
64 jtx::Account const& subject,
65 jtx::Account const& issuer,
66 std::string_view credType)
67{
68 Json::Value jv;
69 jv[jss::TransactionType] = jss::CredentialDelete;
70 jv[jss::Account] = acc.human();
71 jv[jss::Subject] = subject.human();
72 jv[jss::Issuer] = issuer.human();
73 jv[sfCredentialType.jsonName] = strHex(credType);
74 return jv;
75}
76
79 jtx::Env& env,
80 jtx::Account const& subject,
81 jtx::Account const& issuer,
82 std::string_view credType)
83{
84 Json::Value jvParams;
85 jvParams[jss::ledger_index] = jss::validated;
86 jvParams[jss::credential][jss::subject] = subject.human();
87 jvParams[jss::credential][jss::issuer] = issuer.human();
88 jvParams[jss::credential][jss::credential_type] = strHex(credType);
89 return env.rpc("json", "ledger_entry", to_string(jvParams));
90}
91
93ledgerEntry(jtx::Env& env, std::string const& credIdx)
94{
95 Json::Value jvParams;
96 jvParams[jss::ledger_index] = jss::validated;
97 jvParams[jss::credential] = credIdx;
98 return env.rpc("json", "ledger_entry", to_string(jvParams));
99}
100
101} // namespace credentials
102
103} // namespace jtx
104
105} // namespace test
106} // namespace ripple
Represents a JSON value.
Definition: json_value.h:150
Immutable cryptographic account descriptor.
Definition: Account.h:39
std::string const & human() const
Returns the human readable public key.
Definition: Account.h:114
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:779
Json::Value create(jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Definition: creds.cpp:32
Json::Value accept(jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Definition: creds.cpp:48
Json::Value deleteCred(jtx::Account const &acc, jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Definition: creds.cpp:62
Json::Value ledgerEntry(jtx::Env &env, jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Definition: creds.cpp:78
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
std::string strHex(FwdIt begin, FwdIt end)
Definition: strHex.h:30
std::string to_string(base_uint< Bits, Tag > const &a)
Definition: base_uint.h:630