x402_facilitator_local/lib.rs
1//! Local facilitator implementation for the x402 payment protocol.
2//!
3//! This crate provides [`FacilitatorLocal`], a [`Facilitator`](x402_types::facilitator::Facilitator)
4//! implementation that validates x402 payment payloads and performs on-chain settlements
5//! using registered scheme handlers.
6//!
7//! # Architecture
8//!
9//! The local facilitator uses a scheme-based architecture:
10//!
11//! 1. **Chain Registry**: Manages blockchain providers and connections ([`x402_types::chain::ChainRegistry`])
12//! 2. **Scheme Blueprints**: Defines available payment schemes ([`x402_types::scheme::SchemeBlueprints`])
13//! 3. **Scheme Registry**: Combines chains and schemes into executable handlers ([`x402_types::scheme::SchemeRegistry`])
14//! 4. **FacilitatorLocal**: Routes requests to the appropriate scheme handler ([`FacilitatorLocal`])
15//!
16//! # Modules
17//!
18//! - [`facilitator_local`] - Core facilitator implementation
19//! - [`handlers`] - HTTP endpoints for the x402 protocol
20//! - [`util`] - Utilities for graceful shutdown and telemetry
21//!
22//! # Example
23//!
24//! ```ignore
25//! use x402_facilitator_local::{FacilitatorLocal, handlers};
26//! use x402_types::chain::ChainRegistry;
27//! use x402_types::scheme::{SchemeBlueprints, SchemeRegistry};
28//! use x402_chain_eip155::{V1Eip155Exact, V2Eip155Exact};
29//! use std::sync::Arc;
30//!
31//! #[tokio::main]
32//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
33//! // Initialize chain registry
34//! let chain_registry = ChainRegistry::from_config(&chains_config).await?;
35//!
36//! // Register schemes
37//! let scheme_blueprints = SchemeBlueprints::new()
38//! .and_register(V1Eip155Exact)
39//! .and_register(V2Eip155Exact);
40//!
41//! // Build scheme registry
42//! let scheme_registry = SchemeRegistry::build(
43//! chain_registry,
44//! scheme_blueprints,
45//! &schemes_config,
46//! );
47//!
48//! // Create facilitator
49//! let facilitator = FacilitatorLocal::new(scheme_registry);
50//! let state = Arc::new(facilitator);
51//!
52//! // Create HTTP routes
53//! let app = axum::Router::new()
54//! .merge(handlers::routes().with_state(state));
55//!
56//! // Run server
57//! let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?;
58//! axum::serve(listener, app).await?;
59//!
60//! Ok(())
61//! }
62//! ```
63
64pub mod facilitator_local;
65pub mod handlers;
66pub mod util;
67
68pub use facilitator_local::*;
69pub use handlers::*;