openzeppelin_monitor/services/filter/expression/evaluation.rs
1//! This module contains the `ConditionEvaluator` trait and the `EvaluationError` enum.
2//! The `ConditionEvaluator` trait defines methods for getting base parameters, comparing values,
3//! and getting the kind of a value from a JSON value.
4//! The `ConditionEvaluator` trait is implemented by specific evaluators that provide the logic
5//! for evaluating conditions based on the context of the chain.
6
7use super::error::EvaluationError;
8use crate::services::filter::expression::ast::{ComparisonOperator, LiteralValue};
9
10/// The `ConditionEvaluator` trait defines methods for evaluating conditions in filter expressions.
11pub trait ConditionEvaluator {
12 /// Gets the raw string value and kind for a base variable name
13 fn get_base_param(&self, name: &str) -> Result<(&str, &str), EvaluationError>;
14
15 /// Performs the final comparison between the left resolved value (after all path traversal) and the literal value
16 fn compare_final_values(
17 &self,
18 left_kind: &str,
19 left_resolved_value: &str,
20 operator: &ComparisonOperator,
21 right_literal: &LiteralValue,
22 ) -> Result<bool, EvaluationError>;
23
24 /// Gets the chain-specific kind of a value from a JSON value
25 fn get_kind_from_json_value(&self, value: &serde_json::Value) -> String;
26}