src/primitives/transaction_validity.hpp¶
Namespaces¶
| Name |
|---|
| sgns |
| sgns::primitives |
Classes¶
| Name | |
|---|---|
| struct | sgns::primitives::ValidTransaction Information concerning a valid transaction. |
Types¶
| Name | |
|---|---|
| enum class uint8_t | InvalidTransaction { Call = 1, Payment, Future, Stale, BadProof, AncientBirthBlock, ExhaustsResources, Custom} Transaction is invalid. Details are described by the error code. |
| enum class uint8_t | UnknownTransaction { CannotLookup = 1, NoUnsignedValidator, Custom} An unknown transaction validity. |
| using boost::variant< InvalidTransaction, UnknownTransaction > | TransactionValidityError |
| using boost::variant< ValidTransaction, TransactionValidityError > | TransactionValidity |
Functions¶
| Name | |
|---|---|
| template <class Stream ,typename =std::enable_if_t Stream & |
operator<<(Stream & s, const InvalidTransaction & v) |
| template <class Stream ,typename =std::enable_if_t Stream & |
operator>>(Stream & s, InvalidTransaction & v) |
| template <class Stream ,typename =std::enable_if_t Stream & |
operator<<(Stream & s, const UnknownTransaction & v) |
| template <class Stream ,typename =std::enable_if_t Stream & |
operator>>(Stream & s, UnknownTransaction & v) |
| template <class Stream ,typename =std::enable_if_t Stream & |
operator<<(Stream & s, const ValidTransaction & v) outputs object of type Valid to stream |
| template <class Stream ,typename =std::enable_if_t Stream & |
operator>>(Stream & s, ValidTransaction & v) decodes object of type Valid from stream |
Types Documentation¶
enum InvalidTransaction¶
| Enumerator | Value | Description |
|---|---|---|
| Call | 1 | The call of the transaction is not expected. |
| Payment | General error to do with the inability to pay some fees (e.g. account balance too low). | |
| Future | General error to do with the transaction not yet being valid (e.g. nonce too high). | |
| Stale | General error to do with the transaction being outdated (e.g. nonce too low). | |
| BadProof | General error to do with the transaction's proofs (e.g. signature). | |
| AncientBirthBlock | The transaction birth block is ancient. | |
| ExhaustsResources | The transaction would exhaust the resources of current block. |
The transaction might be valid, but there are not enough resources left in the current block. | | Custom | | Any other custom invalid validity that is not covered by this enum. |
Transaction is invalid. Details are described by the error code.
enum UnknownTransaction¶
| Enumerator | Value | Description |
|---|---|---|
| CannotLookup | 1 | Could not lookup some information that is required to validate the transaction. |
| NoUnsignedValidator | No validator found for the given unsigned transaction. | |
| Custom | Any other custom unknown validity that is not covered by this enum. |
An unknown transaction validity.
using TransactionValidityError¶
using sgns::primitives::TransactionValidityError =
boost::variant<InvalidTransaction, UnknownTransaction>;
using TransactionValidity¶
using sgns::primitives::TransactionValidity =
boost::variant<ValidTransaction, TransactionValidityError>;
Information on a transaction's validity and, if valid, on how it relate to other transactions.
Functions Documentation¶
function operator<<¶
template <class Stream ,
typename =std::enable_if_t<Stream::is_encoder_stream>>
Stream & operator<<(
Stream & s,
const InvalidTransaction & v
)
function operator>>¶
template <class Stream ,
typename =std::enable_if_t<Stream::is_decoder_stream>>
Stream & operator>>(
Stream & s,
InvalidTransaction & v
)
function operator<<¶
template <class Stream ,
typename =std::enable_if_t<Stream::is_encoder_stream>>
Stream & operator<<(
Stream & s,
const UnknownTransaction & v
)
function operator>>¶
template <class Stream ,
typename =std::enable_if_t<Stream::is_decoder_stream>>
Stream & operator>>(
Stream & s,
UnknownTransaction & v
)
function operator<<¶
template <class Stream ,
typename =std::enable_if_t<Stream::is_encoder_stream>>
Stream & operator<<(
Stream & s,
const ValidTransaction & v
)
outputs object of type Valid to stream
Parameters:
- s stream reference
- v value to output
Template Parameters:
- Stream stream type
Return: reference to stream
function operator>>¶
template <class Stream ,
typename =std::enable_if_t<Stream::is_decoder_stream>>
Stream & operator>>(
Stream & s,
ValidTransaction & v
)
decodes object of type Valid from stream
Parameters:
- s stream reference
- v value to decode
Template Parameters:
- Stream input stream type
Return: reference to stream
Source code¶
#ifndef SUPERGENIUS_SRC_PRIMITIVES_TRANSACTION_VALIDITY_HPP
#define SUPERGENIUS_SRC_PRIMITIVES_TRANSACTION_VALIDITY_HPP
#include <cstdint>
#include <vector>
#include <boost/variant.hpp>
#include "outcome/outcome.hpp"
#include "primitives/transaction.hpp"
namespace sgns::primitives {
struct ValidTransaction {
Transaction::Priority priority{};
std::vector<Transaction::Tag> requires;
std::vector<Transaction::Tag> provides;
Transaction::Longevity longevity{};
bool propagate{};
bool operator==(const ValidTransaction &rhs) const {
return priority == rhs.priority && requires == rhs.requires
&& provides == rhs.provides && longevity == rhs.longevity
&& propagate == rhs.propagate;
}
bool operator!=(const ValidTransaction &rhs) const {
return !operator==(rhs);
}
//added to fix link error
friend std::ostream &operator<<(std::ostream &out, const ValidTransaction &v)
{
out << v.priority;
out << v.requires.size() ;
for(auto it = v.requires.begin() ; it != v.requires.end() ; it++)
{
// // out << *it;
}
out << v.provides.size();
for(auto it = v.provides.begin() ; it != v.provides.end() ; it++)
{
// // out << *it;
}
out << v.longevity
<< v.propagate;
return out;
}
//end
};
enum class InvalidTransaction : uint8_t {
Call = 1,
Payment,
Future,
Stale,
BadProof,
AncientBirthBlock,
ExhaustsResources,
Custom
};
template <class Stream,
typename = std::enable_if_t<Stream::is_encoder_stream>>
Stream &operator<<(Stream &s, const InvalidTransaction &v) {
// -1 is needed for compatibility with Rust; indices of error codes start
// from 0 there, while in supergenius they must start from 1 because of
// std::error_code policy
return s << static_cast<uint8_t>(v) - 1;
}
template <class Stream,
typename = std::enable_if_t<Stream::is_decoder_stream>>
Stream &operator>>(Stream &s, InvalidTransaction &v) {
uint8_t value = 0u;
s >> value;
// increment is needed for compatibility with Rust; indices of error codes
// start from 0 there, while in supergenius they must start from 1 because of
// std::error_code policy
value++;
if (value > static_cast<uint8_t>(InvalidTransaction::ExhaustsResources)) {
v = InvalidTransaction::Custom;
} else {
v = static_cast<InvalidTransaction>(value);
}
return s;
}
enum class UnknownTransaction : uint8_t {
CannotLookup = 1,
NoUnsignedValidator,
Custom
};
template <class Stream,
typename = std::enable_if_t<Stream::is_encoder_stream>>
Stream &operator<<(Stream &s, const UnknownTransaction &v) {
// -1 is needed for compatibility with Rust; indices of error codes start
// from 0 there, while in supergenius they must start from 1 because of
// std::error_code policy
return s << static_cast<uint8_t>(v) - 1;
}
template <class Stream,
typename = std::enable_if_t<Stream::is_decoder_stream>>
Stream &operator>>(Stream &s, UnknownTransaction &v) {
uint8_t value = 0u;
s >> value;
// increment is needed for compatibility with Rust; indices of error codes
// start from 0 there, while in supergenius they must start from 1 because of
// std::error_code policy
value++;
if (value > static_cast<uint8_t>(UnknownTransaction::NoUnsignedValidator)) {
v = UnknownTransaction::Custom;
} else {
v = static_cast<UnknownTransaction>(value);
}
return s;
}
using TransactionValidityError =
boost::variant<InvalidTransaction, UnknownTransaction>;
using TransactionValidity =
boost::variant<ValidTransaction, TransactionValidityError>;
template <class Stream,
typename = std::enable_if_t<Stream::is_encoder_stream>>
Stream &operator<<(Stream &s, const ValidTransaction &v) {
return s << v.priority << v.requires << v.provides << v.longevity
<< v.propagate;
}
template <class Stream,
typename = std::enable_if_t<Stream::is_decoder_stream>>
Stream &operator>>(Stream &s, ValidTransaction &v) {
return s >> v.priority >> v.requires >> v.provides >> v.longevity
>> v.propagate;
}
} // namespace sgns::primitives
OUTCOME_HPP_DECLARE_ERROR_2(sgns::primitives, InvalidTransaction)
OUTCOME_HPP_DECLARE_ERROR_2(sgns::primitives, UnknownTransaction)
#endif // SUPERGENIUS_SRC_PRIMITIVES_TRANSACTION_VALIDITY_HPP
Updated on 2026-03-04 at 13:10:44 -0800