Kagome
Polkadot Runtime Engine in C++17
apply_result.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_PRIMITIVES_APPLY_RESULT_HPP
7 #define KAGOME_CORE_PRIMITIVES_APPLY_RESULT_HPP
8 
9 #include <boost/variant.hpp>
10 
14 #include "scale/scale.hpp"
15 #include "scale/tie.hpp"
16 
17 namespace kagome::primitives {
18 
19  // Implementation according to
20  // https://github.com/paritytech/substrate/blob/7dcc77b982f59eaf6cec19499d981164b04a255d/primitives/runtime/src/lib.rs#L459
21  // and
22  // https://w3f-research.readthedocs.io/en/latest/_static/pdfview/viewer.html?file=https://w3f.github.io/polkadot-spec/spec/host/nightly.pdf#label329
23 
24  class DispatchSuccess {};
26 
27  namespace dispatch_error {
29  struct Other {
30  std::string value;
31  };
32  // string value is not currently encodes in rust implementation,
33  // thus we use empty coder
36  struct CannotLookup {};
39  struct BadOrigin {};
42  struct Module {
44  uint8_t index;
46  uint8_t error;
48  std::optional<std::string>
49  message; // not currently used in rust impl, thus not scale encoded
50  };
51 
52  template <typename Stream,
53  typename = std::enable_if_t<Stream::is_encoder_stream>>
54  Stream &operator<<(Stream &s, const Module &v) {
55  return s << v.index << v.error;
56  }
57 
58  template <typename Stream,
59  typename = std::enable_if_t<Stream::is_decoder_stream>>
61  s >> v.index >> v.error;
62  return s;
63  }
64 
66  struct ConsumerRemaining {};
69  struct NoProviders {};
72  struct Token {
73  SCALE_TIE(1);
74 
76  };
77 
79  struct Arithmetic {
80  SCALE_TIE(1);
81 
83  };
84  } // namespace dispatch_error
85 
86  namespace de = dispatch_error;
87  using DispatchError = boost::variant<de::Other,
90  de::Module,
93  de::Token,
95 
96  using DispatchOutcome = boost::variant<DispatchSuccess, DispatchError>;
97 
98  using ApplyExtrinsicResult =
99  boost::variant<DispatchOutcome, TransactionValidityError>;
100 
101 } // namespace kagome::primitives
102 
103 #endif // KAGOME_CORE_PRIMITIVES_APPLY_RESULT_HPP
uint8_t index
Module index, matching the metadata module index.
uint8_t error
Module specific error value.
Some unclassified error occurred.
boost::variant< de::Other, de::CannotLookup, de::BadOrigin, de::Module, de::ConsumerRemaining, de::NoProviders, de::Token, de::Arithmetic > DispatchError
boost::variant< DispatchSuccess, DispatchError > DispatchOutcome
Stream & operator>>(Stream &s, ArithmeticError &v)
#define SCALE_TIE(N)
Definition: tie.hpp:11
An error to do with tokens.
SCALE_EMPTY_CODER(DispatchSuccess)
boost::variant< DispatchOutcome, TransactionValidityError > ApplyExtrinsicResult
Stream & operator<<(Stream &s, const ArithmeticError &v)
libp2p::connection::Stream Stream
std::optional< std::string > message
Optional error message.
At least one consumer is remaining so the account cannot be destroyed.
There are no providers so the account cannot be created.