6 #ifndef KAGOME_OFFCHAIN_TYPES 7 #define KAGOME_OFFCHAIN_TYPES 9 #include <boost/optional.hpp> 10 #include <boost/variant.hpp> 11 #include <libp2p/multi/multiaddress.hpp> 12 #include <libp2p/peer/peer_id.hpp> 16 #include "scale/scale.hpp" 57 template <
typename S,
typename F>
58 struct Result final : boost::variant<S, F> {
59 using boost::variant<S, F>::variant;
61 return boost::variant<S, F>::which() == 0;
64 return boost::variant<S, F>::which() == 1;
67 return boost::relaxed_get<S>(*this);
70 return boost::relaxed_get<F>(*this);
76 std::list<libp2p::multi::Multiaddress>
address;
79 std::list<libp2p::multi::Multiaddress> address)
80 : peer_id(
std::move(peer_id)), address(
std::move(address)) {}
89 typename = std::enable_if_t<Stream::is_encoder_stream>>
95 for (
auto &address : v.
address) {
96 s << address.getBytesAddress();
103 typename = std::enable_if_t<Stream::is_decoder_stream>>
108 auto peer_id_res = libp2p::peer::PeerId::fromBytes(buff);
109 if (peer_id_res.has_error()) {
110 throw std::runtime_error(peer_id_res.error().message());
112 v.
peer_id = std::move(peer_id_res.value());
116 v.
address.resize(size.convert_to<uint64_t>());
118 for (
auto &address : v.
address) {
120 auto ma_res = libp2p::multi::Multiaddress::create(buff);
121 if (ma_res.has_error()) {
122 throw std::runtime_error(ma_res.error().message());
124 address = std::move(ma_res.value());
132 #endif // KAGOME_OFFCHAIN_TYPES Class represents arbitrary (including empty) byte buffer.
Stream & operator<<(Stream &s, const OpaqueNetworkState &v)
The deadline was reached.
SCALE_EMPTY_CODER(NoPayload)
uint16_t HttpStatus
HTTP status codes that can get returned by certain Offchain funcs. 0: the specified request identifie...
There was an IO error while processing the request.
libp2p::peer::PeerId PeerId
constexpr HttpStatus InvalidIdentifier(0)
Stream & operator>>(Stream &s, OpaqueNetworkState &v)
scale::CompactInteger CompactInteger
std::list< libp2p::multi::Multiaddress > address
constexpr HttpStatus ErrorHasOccurred(20)
uint64_t Timestamp
Timestamp is milliseconds since UNIX Epoch.
The ID of the request is invalid.
libp2p::connection::Stream Stream
OpaqueNetworkState(libp2p::peer::PeerId peer_id, std::list< libp2p::multi::Multiaddress > address)
libp2p::peer::PeerId peer_id
constexpr HttpStatus DeadlineHasReached(10)