Decentralised Art Server
High-performance C++ backend that exposes HTML interface and a secure REST API for managing Performative Transactions entities
 
Loading...
Searching...
No Matches
events_feed.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <optional>
6#include <string>
7#include <vector>
8#include <format>
9
10#include <nlohmann/json.hpp>
11
12#include "parser.hpp"
13
14namespace dcn::events
15{
16 constexpr std::size_t DEFAULT_FEED_LIMIT = 100;
17 constexpr std::size_t MAX_FEED_LIMIT = 256;
18 constexpr std::size_t DEFAULT_STREAM_LIMIT = 500;
19 constexpr std::size_t MAX_STREAM_LIMIT = 2048;
20
21 struct CursorKey
22 {
23 int chain_id = 1;
24 std::string chain_namespace = "eth";
25 std::int64_t created_at_ms = 0;
26 std::int64_t block_number = 0;
27 std::int64_t tx_index = 0;
28 std::string feed_id;
29 };
30
31 struct FeedItem
32 {
33 std::string feed_id;
34 std::string event_type;
35 std::string status;
36 bool visible = true;
37 std::string tx_hash;
38 std::int64_t block_number = 0;
39 std::int64_t tx_index = 0;
40 std::int64_t log_index = 0;
41 std::string history_cursor;
42 std::int64_t created_at_ms = 0;
43 std::int64_t updated_at_ms = 0;
45 nlohmann::json payload;
46 };
47
48 struct FeedQuery
49 {
51 std::optional<std::string> before_cursor = std::nullopt;
52 std::optional<std::string> event_type = std::nullopt;
54 };
55
56 struct FeedPage
57 {
58 std::vector<FeedItem> items;
59 std::optional<std::string> next_before_cursor = std::nullopt;
60 bool has_more = false;
61 };
62
64 {
65 std::int64_t since_seq = 0;
66 std::size_t limit = 200;
67 };
68
70 {
71 std::int64_t stream_seq = 0;
72 std::string event_type;
73 std::string status;
74 std::string feed_id;
75 std::string history_cursor;
76 std::int64_t created_at_ms = 0;
77 nlohmann::json payload;
78 };
79
81 {
82 std::vector<StreamDelta> deltas;
83 std::optional<std::int64_t> last_seq = std::nullopt;
84 std::int64_t min_available_seq = 0;
85 std::int64_t replay_floor_seq = 0;
86 bool stale_since_seq = false;
87 bool has_more = false;
88 };
89
91 {
92 public:
93 virtual ~IFeedRepository() = default;
94
95 virtual FeedPage getFeedPage(const FeedQuery & query) const = 0;
96 virtual StreamPage getStreamPage(const StreamQuery & query) const = 0;
97 virtual std::int64_t minAvailableStreamSeq() const = 0;
98 };
99}
100
101namespace dcn::parse
102{
103 Result<events::CursorKey> parseHistoryCursor(const std::string & cursor);
104}
105
106template <>
107struct std::formatter<dcn::events::CursorKey> : std::formatter<std::string> {
108 auto format(const dcn::events::CursorKey & cursor, format_context& ctx) const {
109 return std::formatter<std::string>::format(
110 std::format("c{}:{}:{}:{}",
111 cursor.created_at_ms,
112 cursor.block_number,
113 cursor.tx_index,
114 cursor.feed_id),
115 ctx);
116 }
117};
Definition events_feed.hpp:91
virtual std::int64_t minAvailableStreamSeq() const =0
virtual StreamPage getStreamPage(const StreamQuery &query) const =0
virtual ~IFeedRepository()=default
virtual FeedPage getFeedPage(const FeedQuery &query) const =0
Definition decoded_event.hpp:11
constexpr std::size_t DEFAULT_FEED_LIMIT
Definition events_feed.hpp:16
constexpr std::size_t DEFAULT_STREAM_LIMIT
Definition events_feed.hpp:18
constexpr std::size_t MAX_STREAM_LIMIT
Definition events_feed.hpp:19
constexpr std::size_t MAX_FEED_LIMIT
Definition events_feed.hpp:17
Definition hex.hpp:28
Result< events::CursorKey > parseHistoryCursor(const std::string &cursor)
Definition events_feed.cpp:6
Definition decentralised_art.hpp:35
Definition events_feed.hpp:22
std::int64_t tx_index
Definition events_feed.hpp:27
std::string chain_namespace
Definition events_feed.hpp:24
std::int64_t created_at_ms
Definition events_feed.hpp:25
int chain_id
Definition events_feed.hpp:23
std::int64_t block_number
Definition events_feed.hpp:26
std::string feed_id
Definition events_feed.hpp:28
Definition events_feed.hpp:32
std::int64_t updated_at_ms
Definition events_feed.hpp:43
std::int64_t log_index
Definition events_feed.hpp:40
nlohmann::json payload
Definition events_feed.hpp:45
std::int64_t block_number
Definition events_feed.hpp:38
std::string feed_id
Definition events_feed.hpp:33
int projector_version
Definition events_feed.hpp:44
std::int64_t tx_index
Definition events_feed.hpp:39
std::int64_t created_at_ms
Definition events_feed.hpp:42
std::string history_cursor
Definition events_feed.hpp:41
std::string tx_hash
Definition events_feed.hpp:37
std::string status
Definition events_feed.hpp:35
std::string event_type
Definition events_feed.hpp:34
bool visible
Definition events_feed.hpp:36
Definition events_feed.hpp:57
bool has_more
Definition events_feed.hpp:60
std::vector< FeedItem > items
Definition events_feed.hpp:58
std::optional< std::string > next_before_cursor
Definition events_feed.hpp:59
Definition events_feed.hpp:49
std::optional< std::string > event_type
Definition events_feed.hpp:52
std::optional< std::string > before_cursor
Definition events_feed.hpp:51
bool include_unfinalized
Definition events_feed.hpp:53
std::size_t limit
Definition events_feed.hpp:50
Definition events_feed.hpp:70
std::string history_cursor
Definition events_feed.hpp:75
std::string event_type
Definition events_feed.hpp:72
std::int64_t created_at_ms
Definition events_feed.hpp:76
std::string feed_id
Definition events_feed.hpp:74
std::int64_t stream_seq
Definition events_feed.hpp:71
std::string status
Definition events_feed.hpp:73
nlohmann::json payload
Definition events_feed.hpp:77
Definition events_feed.hpp:81
std::optional< std::int64_t > last_seq
Definition events_feed.hpp:83
std::vector< StreamDelta > deltas
Definition events_feed.hpp:82
std::int64_t replay_floor_seq
Definition events_feed.hpp:85
bool stale_since_seq
Definition events_feed.hpp:86
std::int64_t min_available_seq
Definition events_feed.hpp:84
bool has_more
Definition events_feed.hpp:87
Definition events_feed.hpp:64
std::size_t limit
Definition events_feed.hpp:66
std::int64_t since_seq
Definition events_feed.hpp:65
auto format(const dcn::events::CursorKey &cursor, format_context &ctx) const
Definition events_feed.hpp:108