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:
- Blacklist - Highest priority. If the recipient is blacklisted, DENY immediately.
- Whitelist - If whitelist is enabled and recipient is not whitelisted, DENY.
- Transaction Limit - If amount exceeds per-transaction limit, DENY.
- 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§
- Default
Policy Engine - Default policy engine implementation.
Enums§
- Policy
Check Result - Detailed result of a policy check operation.
Traits§
- Policy
Engine - Trait for policy engines that enforce transaction rules.