Skip to main content

Module engine

Module engine 

Source
Expand description

Policy engine for transaction rule enforcement.

This module provides the core policy engine that evaluates transactions against configured rules including whitelists, blacklists, and amount limits.

§Rule Evaluation Order

Rules are evaluated in strict priority order:

  1. Blacklist - Highest priority. If the recipient is blacklisted, DENY immediately.
  2. Whitelist - If whitelist is enabled and recipient is not whitelisted, DENY.
  3. Transaction Limit - If amount exceeds per-transaction limit, DENY.
  4. Allow - If all checks pass, the transaction is ALLOWED.

§Thread Safety

The DefaultPolicyEngine is Send + Sync and can be safely shared across threads.

§Example

use txgate_policy::engine::{PolicyEngine, DefaultPolicyEngine};
use txgate_policy::config::PolicyConfig;
use txgate_core::types::{ParsedTx, PolicyResult};
use alloy_primitives::U256;

// Create a policy config
let config = PolicyConfig::new()
    .with_blacklist(vec!["0xBAD".to_string()])
    .with_transaction_limit("ETH", U256::from(5_000_000_000_000_000_000u64));

// Create the engine
let engine = DefaultPolicyEngine::new(config).unwrap();

// Check a transaction
let tx = ParsedTx::default();
let result = engine.check(&tx);

Structs§

DefaultPolicyEngine
Default policy engine implementation.

Enums§

PolicyCheckResult
Detailed result of a policy check operation.

Traits§

PolicyEngine
Trait for policy engines that enforce transaction rules.