16 const jsonrpc::Request::Parameters ¶ms) {
19 return outcome::success();
22 if (params.size() > 1) {
23 throw jsonrpc::InvalidParametersFault(
"incorrect number of arguments");
26 const auto &arg0 = params[0];
27 if (arg0.IsInteger32()) {
28 param_ =
static_cast<uint32_t
>(arg0.AsInteger32());
29 }
else if (arg0.IsString()) {
31 }
else if (arg0.IsArray()) {
32 const auto &array = arg0.AsArray();
35 throw jsonrpc::InvalidParametersFault(
"invalid argument");
37 std::vector<VectorParam> param;
38 param.reserve(array.size());
39 for (
const auto &v : array) {
40 if (v.IsInteger32()) {
42 }
else if (v.IsString()) {
45 throw jsonrpc::InvalidParametersFault(
"invalid argument");
50 throw jsonrpc::InvalidParametersFault(
"invalid argument");
53 return outcome::success();
57 std::string formatBlockHash(
const BlockHash &bh) {
58 const static std::string prefix =
"0x";
65 return kagome::visit_in_place(
67 [
this](
const NoParameters &v) -> outcome::result<ResultType> {
69 OUTCOME_TRY(bh,
api_->getBlockHash());
70 return formatBlockHash(bh);
72 [
this](
BlockNumber v) -> outcome::result<ResultType> {
73 OUTCOME_TRY(bh,
api_->getBlockHash(v));
74 return formatBlockHash(bh);
76 [
this](std::string_view v) -> outcome::result<ResultType> {
77 OUTCOME_TRY(bh,
api_->getBlockHash(v));
78 return formatBlockHash(bh);
81 const std::vector<VectorParam> &v) -> outcome::result<ResultType> {
83 std::vector<std::string> results{};
84 results.reserve(v.size());
85 for (
const auto &it : rr) {
86 results.emplace_back(formatBlockHash(it));
outcome::result< void > init(const jsonrpc::Request::Parameters ¶ms)
std::string hex_lower(const gsl::span< const uint8_t > bytes) noexcept
Converts bytes to hex representation.
std::shared_ptr< ChainApi > api_
gsl::span< const uint8_t > make_span(const rocksdb::Slice &s)
boost::variant< Param1, Param2 > VectorParam
outcome::result< ResultType > execute()
primitives::BlockNumber BlockNumber
common::Hash256 BlockHash
primitives::BlockHash BlockHash