openzeppelin_monitor/models/blockchain/
mod.rs

1//! Blockchain-specific model implementations.
2//!
3//! This module contains type definitions and implementations for different
4//! blockchain platforms (EVM, Stellar, Midnight, etc). Each submodule implements the
5//! platform-specific logic for blocks, transactions, and event monitoring.
6
7use serde::{Deserialize, Serialize};
8
9pub mod evm;
10pub mod midnight;
11pub mod stellar;
12
13/// Supported blockchain platform types
14#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
15#[serde(deny_unknown_fields)]
16pub enum BlockChainType {
17	/// Ethereum Virtual Machine based chains
18	EVM,
19	/// Stellar blockchain
20	Stellar,
21	/// Midnight blockchain
22	Midnight,
23}
24
25/// Block data from different blockchain platforms
26#[derive(Debug, Clone, Serialize, Deserialize)]
27pub enum BlockType {
28	/// EVM block and transaction data
29	///
30	/// # Note
31	/// Box is used here to equalize the enum variants
32	EVM(Box<evm::EVMBlock>),
33	/// Stellar ledger and transaction data
34	///
35	/// # Note
36	/// Box is used here to equalize the enum variants
37	Stellar(Box<stellar::StellarBlock>),
38	/// Midnight block and transaction data
39	///
40	/// # Note
41	/// Box is used here to equalize the enum variants
42	Midnight(Box<midnight::MidnightBlock>),
43}
44
45impl BlockType {
46	pub fn number(&self) -> Option<u64> {
47		match self {
48			BlockType::EVM(b) => b.number(),
49			BlockType::Stellar(b) => b.number(),
50			BlockType::Midnight(b) => b.number(),
51		}
52	}
53}
54
55/// Transaction data from different blockchain platforms
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[allow(clippy::large_enum_variant)]
58pub enum TransactionType {
59	/// EVM transaction
60	EVM(evm::EVMTransaction),
61	/// Stellar transaction
62	Stellar(Box<stellar::StellarTransaction>),
63	/// Midnight transaction
64	Midnight(midnight::MidnightTransaction),
65}
66
67/// Contract spec from different blockchain platforms
68#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
69#[serde(untagged)]
70pub enum ContractSpec {
71	/// EVM contract spec
72	EVM(evm::EVMContractSpec),
73	/// Stellar contract spec
74	Stellar(stellar::StellarContractSpec),
75	/// Midnight contract spec
76	Midnight,
77}
78
79/// Monitor match results from different blockchain platforms
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub enum MonitorMatch {
82	/// Matched conditions from EVM chains
83	///
84	/// # Note
85	/// Box is used here to equalize the enum variants
86	EVM(Box<evm::EVMMonitorMatch>),
87	/// Matched conditions from Stellar chains
88	///
89	/// # Note
90	/// Box is used here to equalize the enum variants
91	Stellar(Box<stellar::StellarMonitorMatch>),
92	/// Matched conditions from Midnight chains
93	///
94	/// # Note
95	/// Box is used here to equalize the enum variants
96	Midnight(Box<midnight::MidnightMonitorMatch>),
97}
98
99/// Chain-specific configuration
100#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
101pub struct ChainConfiguration {
102	/// Midnight-specific configuration
103	#[serde(skip_serializing_if = "Option::is_none")]
104	pub midnight: Option<midnight::MidnightMonitorConfig>,
105
106	/// EVM-specific configuration
107	#[serde(skip_serializing_if = "Option::is_none")]
108	pub evm: Option<evm::EVMMonitorConfig>,
109
110	/// Stellar-specific configuration
111	#[serde(skip_serializing_if = "Option::is_none")]
112	pub stellar: Option<stellar::StellarMonitorConfig>,
113}
114
115/// Structure to hold block processing results
116///
117/// This is used to pass the results of block processing to the trigger handler
118#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct ProcessedBlock {
120	pub block_number: u64,
121	pub network_slug: String,
122	pub processing_results: Vec<MonitorMatch>,
123}