Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Failing after 2s
Integration Tests / test-service-integration (push) Failing after 15s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 2s
P2P Network Verification / p2p-verification (push) Successful in 2s
Python Tests / test-python (push) Successful in 12s
Security Scanning / security-scan (push) Successful in 41s
Systemd Sync / sync-systemd (push) Successful in 7s
- Phase 1: Core bridge service with gossip broker subscription - Phase 2: Smart contract event integration via eth_getLogs RPC endpoint - Add contract event subscriber for AgentStaking, PerformanceVerifier, Marketplace, Bounty, CrossChainBridge - Add contract event handlers in agent_daemon.py and marketplace.py - Add systemd service file for blockchain-event-bridge - Update blockchain node router.py with eth_getLogs endpoint - Add configuration for contract addresses - Add tests for contract subscriber and handlers (27 tests passing)
3.9 KiB
3.9 KiB
Blockchain Event Bridge
Bridge between AITBC blockchain events and OpenClaw agent triggers using a hybrid event-driven and polling approach.
Overview
This service connects AITBC blockchain events (blocks, transactions, smart contract events) to OpenClaw agent actions through:
- Event-driven: Subscribe to gossip broker topics for real-time critical triggers
- Polling: Periodic checks for batch operations and conditions
- Smart Contract Events: Monitor contract events via blockchain RPC (Phase 2)
Features
- Subscribes to blockchain block events via gossip broker
- Subscribes to transaction events (when available)
- Monitors smart contract events via blockchain RPC:
- AgentStaking (stake creation, rewards, tier updates)
- PerformanceVerifier (performance verification, penalties, rewards)
- AgentServiceMarketplace (service listings, purchases)
- BountyIntegration (bounty creation, completion)
- CrossChainBridge (bridge initiation, completion)
- Triggers coordinator API actions based on blockchain events
- Triggers agent daemon actions for agent wallet transactions
- Triggers marketplace state updates
- Configurable action handlers (enable/disable per type)
- Prometheus metrics for monitoring
- Health check endpoint
Installation
cd apps/blockchain-event-bridge
poetry install
Configuration
Environment variables:
BLOCKCHAIN_RPC_URL- Blockchain RPC endpoint (default:http://localhost:8006)GOSSIP_BACKEND- Gossip broker backend:memory,broadcast, orredis(default:memory)GOSSIP_BROADCAST_URL- Broadcast URL for Redis backend (optional)COORDINATOR_API_URL- Coordinator API endpoint (default:http://localhost:8011)COORDINATOR_API_KEY- Coordinator API key (optional)SUBSCRIBE_BLOCKS- Subscribe to block events (default:true)SUBSCRIBE_TRANSACTIONS- Subscribe to transaction events (default:true)ENABLE_AGENT_DAEMON_TRIGGER- Enable agent daemon triggers (default:true)ENABLE_COORDINATOR_API_TRIGGER- Enable coordinator API triggers (default:true)ENABLE_MARKETPLACE_TRIGGER- Enable marketplace triggers (default:true)ENABLE_POLLING- Enable polling layer (default:false)POLLING_INTERVAL_SECONDS- Polling interval in seconds (default:60)
Running
Development
poetry run uvicorn blockchain_event_bridge.main:app --reload --host 127.0.0.1 --port 8204
Production (Systemd)
sudo systemctl start aitbc-blockchain-event-bridge
sudo systemctl enable aitbc-blockchain-event-bridge
API Endpoints
GET /- Service informationGET /health- Health checkGET /metrics- Prometheus metrics
Architecture
blockchain-event-bridge/
├── src/blockchain_event_bridge/
│ ├── main.py # FastAPI app
│ ├── config.py # Settings
│ ├── bridge.py # Core bridge logic
│ ├── metrics.py # Prometheus metrics
│ ├── event_subscribers/ # Event subscription modules
│ ├── action_handlers/ # Action handler modules
│ └── polling/ # Polling modules
└── tests/
Event Flow
- Blockchain publishes block event to gossip broker (topic: "blocks")
- Block event subscriber receives event
- Bridge parses block data and extracts transactions
- Bridge triggers appropriate action handlers:
- Coordinator API handler for AI jobs, agent messages
- Agent daemon handler for agent wallet transactions
- Marketplace handler for marketplace listings
- Action handlers make HTTP calls to respective services
- Metrics are recorded for monitoring
Testing
poetry run pytest
Future Enhancements
- Phase 2: Smart contract event subscription
- Phase 3: Enhanced polling layer for batch operations
- WebSocket support for real-time event streaming
- Event replay for missed events