xrpld
Loading...
Searching...
No Matches
creds.cpp
1#include <test/jtx/Account.h>
2#include <test/jtx/Env.h>
3#include <test/jtx/credentials.h>
4
5#include <xrpl/basics/strHex.h>
6#include <xrpl/json/json_value.h>
7#include <xrpl/json/to_string.h>
8#include <xrpl/protocol/SField.h>
9#include <xrpl/protocol/jss.h>
10
11#include <string_view>
12
14
15json::Value
16create(jtx::Account const& subject, jtx::Account const& issuer, std::string_view credType)
17{
18 json::Value jv;
19 jv[jss::TransactionType] = jss::CredentialCreate;
20
21 jv[jss::Account] = issuer.human();
22 jv[jss::Subject] = subject.human();
23 jv[sfCredentialType.jsonName] = strHex(credType);
24
25 return jv;
26}
27
29accept(jtx::Account const& subject, jtx::Account const& issuer, std::string_view credType)
30{
31 json::Value jv;
32 jv[jss::TransactionType] = jss::CredentialAccept;
33 jv[jss::Account] = subject.human();
34 jv[jss::Issuer] = issuer.human();
35 jv[sfCredentialType.jsonName] = strHex(credType);
36 return jv;
37}
38
41 jtx::Account const& acc,
42 jtx::Account const& subject,
43 jtx::Account const& issuer,
44 std::string_view credType)
45{
46 json::Value jv;
47 jv[jss::TransactionType] = jss::CredentialDelete;
48 jv[jss::Account] = acc.human();
49 jv[jss::Subject] = subject.human();
50 jv[jss::Issuer] = issuer.human();
51 jv[sfCredentialType.jsonName] = strHex(credType);
52 return jv;
53}
54
57 jtx::Env& env,
58 jtx::Account const& subject,
59 jtx::Account const& issuer,
60 std::string_view credType)
61{
62 json::Value jvParams;
63 jvParams[jss::ledger_index] = jss::validated;
64 jvParams[jss::credential][jss::subject] = subject.human();
65 jvParams[jss::credential][jss::issuer] = issuer.human();
66 jvParams[jss::credential][jss::credential_type] = strHex(credType);
67 return env.rpc("json", "ledger_entry", to_string(jvParams));
68}
69
71ledgerEntry(jtx::Env& env, std::string const& credIdx)
72{
73 json::Value jvParams;
74 jvParams[jss::ledger_index] = jss::validated;
75 jvParams[jss::credential] = credIdx;
76 return env.rpc("json", "ledger_entry", to_string(jvParams));
77}
78
79} // namespace xrpl::test::jtx::credentials
Represents a JSON value.
Definition json_value.h:130
Immutable cryptographic account descriptor.
Definition jtx/Account.h:17
std::string const & human() const
Returns the human readable public key.
Definition jtx/Account.h:92
A transaction testing environment.
Definition Env.h:143
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:864
json::Value deleteCred(jtx::Account const &acc, jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Definition creds.cpp:40
json::Value accept(jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Definition creds.cpp:29
json::Value create(jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Definition creds.cpp:16
json::Value ledgerEntry(jtx::Env &env, jtx::Account const &subject, jtx::Account const &issuer, std::string_view credType)
Definition creds.cpp:56
std::string strHex(FwdIt begin, FwdIt end)
Definition strHex.h:10
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:633