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
local_evm_source.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <cstddef>
5#include <cstdint>
6#include <utility>
7#include <vector>
8
9#include <asio.hpp>
10
12#include "evm.hpp"
13
14namespace dcn::events
15{
16 // Adapts the in-process EVM into an EmittedLogRecord source. Keeps the evm
17 // module generic: the ephemeral-entity rewrite stays a policy flag applied
18 // by ingestion, not baked into the EVM. All blocks are reported finalized
19 // immediately (local EVM has no reorg/finality staging).
20 class LocalEvmSource final : public IEmittedLogSource
21 {
22 public:
23 LocalEvmSource(evm::EVM & evm, int chain_id)
24 : _evm(evm)
25 , _chain_id(chain_id)
26 {
27 }
28
29 int chainId() const override { return _chain_id; }
30 bool ephemeralEntities() const override { return true; }
31
32 asio::awaitable<SourcePoll> pollSince(std::uint64_t cursor, std::size_t limit) override
33 {
34 std::vector<evm::EVM::EmittedLogRecord> records = co_await _evm.getLogsSince(cursor, limit);
35 const std::int64_t head = co_await _evm.getHeadBlockNumber();
36
37 std::int64_t max_block = std::max<std::int64_t>(head, 0);
38 for(const auto & record : records)
39 {
40 max_block = std::max<std::int64_t>(max_block, record.block_number);
41 }
42
43 const std::uint64_t next_cursor = records.empty() ? cursor : records.back().seq + 1;
44
45 co_return SourcePoll{
46 .records = std::move(records),
47 .finality = FinalityHeights{
48 .head = max_block,
49 .safe = max_block,
50 .finalized = max_block
51 },
52 .next_cursor = next_cursor
53 };
54 }
55
56 private:
57 evm::EVM & _evm;
58 int _chain_id;
59 };
60}
Definition emitted_log_source.hpp:30
int chainId() const override
Definition local_evm_source.hpp:29
asio::awaitable< SourcePoll > pollSince(std::uint64_t cursor, std::size_t limit) override
Definition local_evm_source.hpp:32
LocalEvmSource(evm::EVM &evm, int chain_id)
Definition local_evm_source.hpp:23
bool ephemeralEntities() const override
Definition local_evm_source.hpp:30
Definition evm.hpp:45
Definition decoded_event.hpp:11
Definition evm.hpp:43
Definition events_ingest.hpp:12
Definition emitted_log_source.hpp:19