Kagome
Polkadot Runtime Engine in C++17
transaction_validity.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_PRIMITIVES_TRANSACTION_VALIDITY_HPP
7 #define KAGOME_CORE_PRIMITIVES_TRANSACTION_VALIDITY_HPP
8 
9 #include <cstdint>
10 #include <vector>
11 
12 #include <boost/variant.hpp>
13 #include <outcome/outcome.hpp>
14 
16 #include "scale/tie.hpp"
17 
18 namespace kagome::primitives {
19 
20  enum class TransactionSource : uint8_t {
27  InBlock,
28 
34  Local,
35 
40  External,
41  };
42 
50  SCALE_TIE(5);
51 
58 
64  std::vector<Transaction::Tag>
66 
75  std::vector<Transaction::Tag> provides;
76 
84 
91  bool propagate{};
92  };
93 
95  enum class InvalidTransaction : uint8_t {
97  Call = 1,
100  Payment,
103  Future,
106  Stale,
108  BadProof,
117  Custom,
122  BadMandatory,
126  };
127 
128  template <class Stream,
129  typename = std::enable_if_t<Stream::is_encoder_stream>>
131  // -1 is needed for compatibility with Rust; indices of error codes start
132  // from 0 there, while in kagome they must start from 1 because of
133  // std::error_code policy
134  return s << static_cast<uint8_t>(v) - 1;
135  }
136 
137  template <class Stream,
138  typename = std::enable_if_t<Stream::is_decoder_stream>>
139  Stream &operator>>(Stream &s, InvalidTransaction &v) {
140  uint8_t value = 0u;
141  s >> value;
142 
143  // increment is needed for compatibility with Rust; indices of error codes
144  // start from 0 there, while in kagome they must start from 1 because of
145  // std::error_code policy
146  value++;
147  if (value > static_cast<uint8_t>(InvalidTransaction::ExhaustsResources)) {
149  } else {
150  v = static_cast<InvalidTransaction>(value);
151  }
152  return s;
153  }
154 
156  enum class UnknownTransaction : uint8_t {
159  CannotLookup = 1,
163  Custom
164  };
165 
166  template <class Stream,
167  typename = std::enable_if_t<Stream::is_encoder_stream>>
168  Stream &operator<<(Stream &s, const UnknownTransaction &v) {
169  // -1 is needed for compatibility with Rust; indices of error codes start
170  // from 0 there, while in kagome they must start from 1 because of
171  // std::error_code policy
172  return s << static_cast<uint8_t>(v) - 1;
173  }
174 
175  template <class Stream,
176  typename = std::enable_if_t<Stream::is_decoder_stream>>
177  Stream &operator>>(Stream &s, UnknownTransaction &v) {
178  uint8_t value = 0u;
179  s >> value;
180 
181  // increment is needed for compatibility with Rust; indices of error codes
182  // start from 0 there, while in kagome they must start from 1 because of
183  // std::error_code policy
184  value++;
185  if (value > static_cast<uint8_t>(UnknownTransaction::NoUnsignedValidator)) {
187  } else {
188  v = static_cast<UnknownTransaction>(value);
189  }
190  return s;
191  }
192 
194  boost::variant<InvalidTransaction, UnknownTransaction>;
195 
200  using TransactionValidity =
201  boost::variant<ValidTransaction, TransactionValidityError>;
202 } // namespace kagome::primitives
203 
206 
207 #endif // KAGOME_CORE_PRIMITIVES_TRANSACTION_VALIDITY_HPP
General error to do with the transaction&#39;s proofs (e.g. signature).
The transaction birth block is ancient.
std::vector< Transaction::Tag > requires
Transaction dependencies A non-empty list signifies that some other transactions which provide given ...
boost::variant< InvalidTransaction, UnknownTransaction > TransactionValidityError
No validator found for the given unsigned transaction.
Stream & operator>>(Stream &s, ArithmeticError &v)
#define SCALE_TIE(N)
Definition: tie.hpp:11
OUTCOME_HPP_DECLARE_ERROR(kagome::api, JRpcServerImpl::Error)
UnknownTransaction
An unknown transaction validity.
std::vector< Transaction::Tag > provides
Provided tags A list of tags this transaction provides. Successful transaction import will enable oth...
Information concerning a valid transaction.
The call of the transaction is not expected.
boost::variant< ValidTransaction, TransactionValidityError > TransactionValidity
Stream & operator<<(Stream &s, const ArithmeticError &v)
libp2p::connection::Stream Stream
uint64_t Priority
Priority for a transaction. Additive. Higher is better.
Definition: transaction.hpp:19
Any other custom invalid validity that is not covered by this enum.
InvalidTransaction
Transaction is invalid. Details are described by the error code.