pub trait PolicyEngine: Send + Sync {
// Required method
fn check(&self, tx: &ParsedTx) -> Result<PolicyResult, PolicyError>;
}Expand description
Trait for policy engines that enforce transaction rules.
Implementors of this trait can check transactions against policy rules.
§Thread Safety
All implementations must be Send + Sync to allow concurrent access
from multiple request handlers.
§Example
use txgate_policy::engine::PolicyEngine;
use txgate_core::types::{ParsedTx, PolicyResult};
use txgate_core::error::PolicyError;
fn process_transaction(engine: &dyn PolicyEngine, tx: &ParsedTx) -> Result<(), PolicyError> {
let result = engine.check(tx)?;
if result.is_allowed() {
// Transaction approved
}
Ok(())
}Required Methods§
Sourcefn check(&self, tx: &ParsedTx) -> Result<PolicyResult, PolicyError>
fn check(&self, tx: &ParsedTx) -> Result<PolicyResult, PolicyError>
Check if a transaction is allowed by policy rules.
Evaluates the transaction against all configured policy rules in order
of priority (blacklist > whitelist > tx_limit).
§Arguments
tx- The parsed transaction to check
§Returns
Ok(PolicyResult::Allowed)- Transaction passes all policy checksOk(PolicyResult::Denied { rule, reason })- Transaction denied by a ruleErr(PolicyError)- Policy evaluation failed (e.g., database error)
§Errors
Returns PolicyError if policy evaluation fails due to:
- Invalid policy configuration