openzeppelin_monitor/models/blockchain/midnight/
monitor.rs

1//! Midnight monitor data structures.
2//!
3//! This module provides data structures for monitoring and matching transactions
4//! on the Midnight blockchain. It includes types for representing monitor matches,
5//! parameters, and configuration.
6
7use serde::{Deserialize, Serialize};
8
9use crate::models::{MatchConditions, MidnightTransaction, Monitor, SecretValue};
10
11/// Result of a successful monitor match on an Midnight chain
12///
13/// This struct represents the result of a successful match between a monitor
14/// configuration and a transaction on the Midnight blockchain. It contains
15/// information about the matched transaction, conditions, and decoded arguments.
16#[derive(Debug, Clone, Deserialize, Serialize)]
17pub struct MonitorMatch {
18	/// Monitor configuration that triggered the match
19	pub monitor: Monitor,
20
21	/// Transaction that triggered the match
22	pub transaction: MidnightTransaction,
23
24	/// Network slug that the transaction was sent from
25	pub network_slug: String,
26
27	/// Conditions that were matched
28	pub matched_on: MatchConditions,
29
30	/// Decoded arguments from the matched conditions
31	pub matched_on_args: Option<MatchArguments>,
32}
33
34/// Collection of decoded parameters from matched conditions
35///
36/// This struct represents a collection of decoded parameters from a function
37/// or event signature, including the signature itself and its arguments.
38#[derive(Debug, Clone, Deserialize, Serialize)]
39pub struct MatchParamsMap {
40	/// Function or event signature
41	pub signature: String,
42
43	/// Decoded argument values
44	pub args: Option<Vec<MatchParamEntry>>,
45
46	/// Raw function/event signature as bytes
47	pub hex_signature: Option<String>,
48}
49
50/// Single decoded parameter from a function or event
51///
52/// This struct represents a single decoded parameter from a function or event,
53/// including its name, value, type, and whether it's indexed (for events).
54#[derive(Debug, Clone, Deserialize, Serialize)]
55pub struct MatchParamEntry {
56	/// Parameter name
57	pub name: String,
58
59	/// Parameter value
60	pub value: String,
61
62	/// Whether this is an indexed parameter (for events)
63	pub indexed: bool,
64
65	/// Parameter type (uint256, address, etc)
66	pub kind: String,
67}
68
69/// Arguments matched from functions and events
70///
71/// This struct contains collections of matched function and event arguments,
72/// organized by their respective types.
73#[derive(Debug, Clone, Deserialize, Serialize)]
74pub struct MatchArguments {
75	/// Matched function arguments
76	pub functions: Option<Vec<MatchParamsMap>>,
77
78	/// Matched event arguments
79	pub events: Option<Vec<MatchParamsMap>>,
80}
81
82/// Midnight-specific configuration
83///
84/// This configuration is used for additional fields in the monitor configuration
85/// that are specific to Midnight. It includes viewing keys for decrypting
86/// transaction data.
87#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
88pub struct MonitorConfig {
89	/// List of hex encoded viewing keys for decrypting transaction data
90	#[serde(default)]
91	pub viewing_keys: Vec<SecretValue>,
92}