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