feat(backend): implement BridgePayoutEvent webhook listener (#33) - #997
Open
acmvisuals1 wants to merge 1 commit into
Open
feat(backend): implement BridgePayoutEvent webhook listener (#33)#997acmvisuals1 wants to merge 1 commit into
acmvisuals1 wants to merge 1 commit into
Conversation
…e#33) Closes Fracverse#33 ## Summary Adds a background daemon that polls the Stellar Horizon API for Soroban contract events with the BridgePay topic, persists them with exactly-once semantics, and fans out bridge.payout webhook dispatches to all active registered endpoints. ## Changes ### backend/src/bridge_event_listener.rs (new) - BridgeListenerConfig::from_env() — reads STELLAR_CONTRACT_ID, STELLAR_HORIZON_URL, BRIDGE_LISTENER_POLL_INTERVAL_SECS; returns None when contract ID is absent so the daemon self-disables - BridgeEventListenerService — poll loop with tokio::select! and a watch::Receiver<bool> shutdown channel for graceful termination - run_once() — full poll → parse → persist → webhook cycle - latest_persisted_ledger() — fixed fetch_optional → fetch_one (COALESCE always returns a row; old code skipped every poll cycle silently) - fetch_events() — Horizon HTTP poll with correct 19-digit zero-padded cursor format {seq:019}-0000000000 - persist_event() — INSERT … ON CONFLICT DO NOTHING for exactly-once DB persistence keyed on (contract_id, ledger_sequence, tx_hash, event_index) - enqueue_webhook() — fan-out via WebhookDispatcherService - extract_str() / extract_i64() — handle plain strings and Horizon wrapper objects ({id:…}, {value:…}) - 23 inline unit tests ### backend/src/api.rs - GET /api/bridge/events — paginated query with contract_id, owner_address, from_ledger, to_ledger, page, page_size filters - BridgeEventQuery, BridgeEventRow, BridgeEventsResponse types - Route added to public_routes in create_router ### backend/src/lib.rs - pub mod bridge_event_listener - pub use BridgeEventListenerService, BridgeListenerConfig ### backend/src/main.rs - Creates tokio::sync::watch shutdown channel - Starts BridgeEventListenerService gated on STELLAR_CONTRACT_ID being set - Graceful shutdown tied to Ctrl-C via axum::serve::with_graceful_shutdown ### backend/migrations/20260724000000_create_bridge_payout_events.{up,down}.sql - bridge_payout_events table with unique index for dedup - Indexes on ledger_sequence for efficient pagination ### backend/tests/bridge_event_listener_test.rs (new) - 29 integration tests: config validation, topic filtering, parse_event fidelity, extract helpers, cursor format, HTTP endpoint routing, method rejection, Horizon page deserialisation ### .github/workflows/backend.yml - postgres:16 with --health-cmd pg_isready health check - DATABASE_URL env var set at job level - cargo test --all-features
|
@acmvisuals1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
@acmvisuals1 |
Contributor
|
@acmvisuals1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #942
Summary
Adds a background daemon that polls the Stellar Horizon API for Soroban contract events with the BridgePay topic, persists them with exactly-once semantics, and fans out bridge.payout webhook dispatches to all active registered endpoints.
Changes
backend/src/bridge_event_listener.rs (new)
backend/src/api.rs
backend/src/lib.rs
backend/src/main.rs
backend/migrations/20260724000000_create_bridge_payout_events.{up,down}.sql
backend/tests/bridge_event_listener_test.rs (new)
.github/workflows/backend.yml
pr #942