6 #ifndef KAGOME_CORE_API_EXTRINSIC_RESPONSE_VALUE_CONVERTER_HPP 7 #define KAGOME_CORE_API_EXTRINSIC_RESPONSE_VALUE_CONVERTER_HPP 11 #include <jsonrpc-lean/value.h> 12 #include <boost/range/adaptor/transformed.hpp> 26 #include "scale/scale.hpp" 31 using jString = jsonrpc::Value::String;
32 using jArray = jsonrpc::Value::Array;
33 using jStruct = jsonrpc::Value::Struct;
36 inline jsonrpc::Value
makeValue(
const uint32_t &);
37 inline jsonrpc::Value
makeValue(
const uint64_t &);
38 inline jsonrpc::Value
makeValue(
const std::nullptr_t &);
39 inline jsonrpc::Value
makeValue(
const std::nullopt_t &);
40 inline jsonrpc::Value
makeValue(
const std::nullopt_t &);
43 inline jsonrpc::Value
makeValue(
const std::reference_wrapper<T> &v);
46 inline jsonrpc::Value
makeValue(
const std::optional<T> &val);
48 template <
typename... Ts>
49 inline jsonrpc::Value
makeValue(
const boost::variant<Ts...> &v);
51 template <
typename T1,
typename T2>
52 inline jsonrpc::Value
makeValue(
const std::pair<T1, T2> &val);
55 inline jsonrpc::Value
makeValue(
const std::vector<T> &);
58 inline jsonrpc::Value
makeValue(
const common::Blob<N> &);
62 inline jsonrpc::Value
makeValue(
const primitives::Extrinsic &);
63 inline jsonrpc::Value
makeValue(
const primitives::RuntimeDispatchInfo &v);
65 inline jsonrpc::Value
makeValue(
const primitives::BlockData &);
66 inline jsonrpc::Value
makeValue(
const primitives::BlockHeader &);
67 inline jsonrpc::Value
makeValue(
const primitives::Version &);
68 inline jsonrpc::Value
makeValue(
const primitives::Justification &);
69 inline jsonrpc::Value
makeValue(
const primitives::RpcMethods &);
71 inline jsonrpc::Value
makeValue(
const uint32_t &val) {
72 return static_cast<int64_t
>(val);
75 inline jsonrpc::Value
makeValue(
const uint64_t &val) {
76 return static_cast<int64_t
>(val);
79 inline jsonrpc::Value
makeValue(
const std::nullptr_t &) {
83 inline jsonrpc::Value
makeValue(
const std::nullopt_t &) {
89 jsonrpc::Value ret(val);
94 inline jsonrpc::Value
makeValue(std::remove_reference_t<T> &&val) {
99 inline jsonrpc::Value
makeValue(
const std::reference_wrapper<T> &v) {
103 template <
typename T>
104 inline jsonrpc::Value
makeValue(
const std::optional<T> &val) {
109 template <
typename... Ts>
110 inline jsonrpc::Value
makeValue(
const boost::variant<Ts...> &v) {
111 return visit_in_place(v,
112 [](
const auto &value) {
return makeValue(value); });
115 template <
typename T1,
typename T2>
116 inline jsonrpc::Value
makeValue(
const std::pair<T1, T2> &val) {
121 data.emplace_back(
makeValue(val.second));
126 template <
typename T>
127 inline jsonrpc::Value
makeValue(
const std::vector<T> &v) {
130 value.reserve(v.size());
131 for (
auto &item : v) {
152 auto result = scale::encode(val);
153 if (result.has_value()) {
156 throw jsonrpc::InternalErrorFault(
"Unable to encode arguments.");
172 std::transform(val.
apis.begin(),
174 std::back_inserter(apis),
175 [](
const auto &api) {
178 api_data.emplace_back(
makeValue(api.second));
182 data[
"apis"] = std::move(apis);
189 std::stringstream stream;
190 stream <<
"0x" << std::hex << val.
number;
191 data[
"number"] =
makeValue(stream.str());
193 data[
"extrinsicsRoot"] =
197 logs.reserve(val.
digest.size());
198 for (
const auto &d : val.
digest) {
203 digest[
"logs"] = std::move(logs);
205 data[
"digest"] = std::move(digest);
211 frnk.emplace_back(jArray({
'F',
'R',
'N',
'K'}));
212 frnk.emplace_back(jArray(val.
data.begin(), val.
data.end()));
214 res.emplace_back(std::move(frnk));
231 data[
"block"] = std::move(block);
243 res[
"class"] =
"normal";
245 case Class::Mandatory:
246 res[
"class"] =
"mandatory";
248 case Class::Operational:
249 res[
"class"] =
"operational";
257 return visit_in_place(
259 [&event](std::nullopt_t) -> jsonrpc::Value {
260 switch (event.type) {
261 case primitives::events::ExtrinsicEventType::FUTURE:
263 case primitives::events::ExtrinsicEventType::READY:
265 case primitives::events::ExtrinsicEventType::INVALID:
267 case primitives::events::ExtrinsicEventType::DROPPED:
270 BOOST_UNREACHABLE_RETURN({});
276 peers.resize(params.peers.size());
278 params.peers.cbegin(),
281 [](
const auto &peer_id) {
return makeValue(peer_id.toHex()); });
282 return jStruct{std::pair{
"broadcast", std::move(peers)}};
285 return jStruct{std::pair{
289 return jStruct{std::pair{
295 std::pair{
"finalityTimeout",
299 return jStruct{std::pair{
303 return jStruct{std::pair{
315 #endif // KAGOME_CORE_API_EXTRINSIC_RESPONSE_VALUE_CONVERTER_HPP Class represents arbitrary (including empty) byte buffer.
std::optional< primitives::BlockHeader > header
const std::vector< uint8_t > & asVector() const
getter for vector of bytes
common::BufferView BufferView
Version version
Descriptor version.
common::Buffer data
extrinsic content as byte array
ApisVec apis
List of supported API "features" along with their versions.
uint8_t state_version
Version of the state implementation used by this runtime.
SLBuffer< std::numeric_limits< size_t >::max()> Buffer
enum kagome::primitives::RuntimeDispatchInfo::DispatchClass dispatch_class
uint32_t transaction_version
std::string hex_lower_0x(gsl::span< const uint8_t > bytes) noexcept
Converts bytes to hex representation with prefix 0x.
uint32_t authoring_version
authoring_version is the version of the authorship interface
jsonrpc::Value makeValue(const uint32_t &)
boost::variant< Other, Unused< 1 >, Unused< 2 >, Unused< 3 >, Consensus, Seal, PreRuntime, Unused< 7 >, RuntimeEnvironmentUpdated > DigestItem
static constexpr size_t size()
Extrinsic class represents extrinsic.
Methods methods
A set of methods names as strings.
std::optional< primitives::BlockBody > body
std::optional< primitives::Justification > justification