Skip to main content

PolicyEngine

Trait PolicyEngine 

Source
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§

Source

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 checks
  • Ok(PolicyResult::Denied { rule, reason }) - Transaction denied by a rule
  • Err(PolicyError) - Policy evaluation failed (e.g., database error)
§Errors

Returns PolicyError if policy evaluation fails due to:

  • Invalid policy configuration

Implementors§