xrpld
Loading...
Searching...
No Matches
xrpld/rpc/handlers/server_info/Manifest.cpp
1// Copyright (c) 2019 Dev Null Productions
2
3#include <xrpld/app/main/Application.h>
4#include <xrpld/rpc/Context.h>
5
6#include <xrpl/basics/base64.h>
7#include <xrpl/json/json_value.h>
8#include <xrpl/protocol/ErrorCodes.h>
9#include <xrpl/protocol/PublicKey.h>
10#include <xrpl/protocol/jss.h>
11#include <xrpl/protocol/tokens.h>
12
13namespace xrpl {
14json::Value
16{
17 auto& params = context.params;
18
19 if (!params.isMember(jss::public_key))
20 return RPC::missingFieldError(jss::public_key);
21
22 auto const requested = params[jss::public_key].asString();
23
24 json::Value ret;
25 ret[jss::requested] = requested;
26
27 auto const pk = parseBase58<PublicKey>(TokenType::NodePublic, requested);
28 if (!pk)
29 {
31 return ret;
32 }
33
34 // first attempt to use params as ephemeral key,
35 // if this lookup succeeds master key will be returned,
36 // else an unseated optional is returned
37 auto const mk = context.app.getValidatorManifests().getMasterKey(*pk);
38
39 auto const ek = context.app.getValidatorManifests().getSigningKey(mk);
40
41 // if ephemeral key not found, we don't have specified manifest
42 if (!ek)
43 return ret;
44
45 if (auto const manifest = context.app.getValidatorManifests().getManifest(mk))
46 ret[jss::manifest] = base64Encode(*manifest);
47 json::Value details;
48
49 details[jss::master_key] = toBase58(TokenType::NodePublic, mk);
50 details[jss::ephemeral_key] = toBase58(TokenType::NodePublic, *ek);
51
52 if (auto const seq = context.app.getValidatorManifests().getSequence(mk))
53 details[jss::seq] = *seq;
54
55 if (auto const domain = context.app.getValidatorManifests().getDomain(mk))
56 details[jss::domain] = *domain;
57
58 ret[jss::details] = details;
59 return ret;
60}
61} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
std::optional< PublicKey > getSigningKey(PublicKey const &pk) const
Returns master key's current signing key.
std::optional< std::string > getDomain(PublicKey const &pk) const
Returns domain claimed by a given public key.
PublicKey getMasterKey(PublicKey const &pk) const
Returns ephemeral signing key's master public key.
std::optional< std::string > getManifest(PublicKey const &pk) const
Returns manifest corresponding to a given public key.
std::optional< std::uint32_t > getSequence(PublicKey const &pk) const
Returns master key's current manifest sequence.
virtual ManifestCache & getValidatorManifests()=0
void injectError(ErrorCodeI code, json::Value &json)
Add or update the json update to reflect the error code.
json::Value missingFieldError(std::string const &name)
Definition ErrorCodes.h:231
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
json::Value doManifest(RPC::JsonContext &)
@ RpcInvalidParams
Definition ErrorCodes.h:66
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:93
std::string base64Encode(std::uint8_t const *data, std::size_t len)
Application & app
Definition Context.h:21
json::Value params
Definition Context.h:43