rippled
Loading...
Searching...
No Matches
ValidatorInfo.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2019 Dev Null Productions
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 <xrpld/app/main/Application.h>
21#include <xrpld/app/misc/ValidatorKeys.h>
22#include <xrpld/rpc/Context.h>
23
24#include <xrpl/basics/base64.h>
25#include <xrpl/json/json_value.h>
26#include <xrpl/protocol/ErrorCodes.h>
27#include <xrpl/protocol/jss.h>
28
29namespace ripple {
32{
33 // return error if not configured as validator
34 auto const validationPK = context.app.getValidationPublicKey();
35 if (!validationPK)
37
38 Json::Value ret;
39
40 // assume validationPK is ephemeral key, get master key
41 auto const mk =
42 context.app.validatorManifests().getMasterKey(*validationPK);
43 ret[jss::master_key] = toBase58(TokenType::NodePublic, mk);
44
45 // validationPK is master key, this implies that there is no ephemeral
46 // key, no manifest, hence return
47 if (mk == validationPK)
48 return ret;
49
50 ret[jss::ephemeral_key] = toBase58(TokenType::NodePublic, *validationPK);
51
52 if (auto const manifest = context.app.validatorManifests().getManifest(mk))
53 ret[jss::manifest] = base64_encode(*manifest);
54
55 if (auto const seq = context.app.validatorManifests().getSequence(mk))
56 ret[jss::seq] = *seq;
57
58 if (auto const domain = context.app.validatorManifests().getDomain(mk))
59 ret[jss::domain] = *domain;
60
61 return ret;
62}
63} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
virtual std::optional< PublicKey const > getValidationPublicKey() const =0
virtual ManifestCache & validatorManifests()=0
std::optional< std::uint32_t > getSequence(PublicKey const &pk) const
Returns master key's current manifest sequence.
Definition Manifest.cpp:335
std::optional< std::string > getManifest(PublicKey const &pk) const
Returns mainfest corresponding to a given public key.
Definition Manifest.cpp:359
PublicKey getMasterKey(PublicKey const &pk) const
Returns ephemeral signing key's master public key.
Definition Manifest.cpp:323
std::optional< std::string > getDomain(PublicKey const &pk) const
Returns domain claimed by a given public key.
Definition Manifest.cpp:347
Json::Value not_validator_error()
Definition ErrorCodes.h:361
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
std::string base64_encode(std::uint8_t const *data, std::size_t len)
Json::Value doValidatorInfo(RPC::JsonContext &)
@ manifest
Manifest.
Application & app
Definition Context.h:41