forked from Vero-protocol/vero-core-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
65 lines (53 loc) · 2.27 KB
/
Copy pathmain.ts
File metadata and controls
65 lines (53 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* main.ts — Entry point for the engine-bridge service.
*
* Orchestrates the RpcClient, EventPropagator, ZkStateSyncer,
* AlertChannelService, and HeartbeatMonitor into a running process.
*/
import { RpcClient } from "./rpc-client";
import { EventPropagator } from "./event-propagator";
import { ZkStateSyncer } from "./zk-state-syncer";
import { HeartbeatMonitor } from "./heartbeat-monitor";
import { AlertChannelService, WebhookAlertChannel, ConsoleAlertChannel } from "./alert-channel";
async function main() {
const rpcUrls = (process.env.RPC_URLS || "https://soroban-testnet.stellar.org").split(",");
const contractId = process.env.CONTRACT_ID || "";
const port = parseInt(process.env.PORT || "8080", 10);
const cursor = process.env.EVENT_CURSOR;
const webhookUrl = process.env.ALERT_WEBHOOK_URL || "";
console.log("[Bridge] Starting service...");
console.log(`[Bridge] RPC URLs: ${rpcUrls.join(", ")}`);
console.log(`[Bridge] Contract: ${contractId}`);
console.log(`[Bridge] Webhook: ${webhookUrl || "none (console only)"}`);
const rpc = new RpcClient(rpcUrls);
const propagator = new EventPropagator(rpc, contractId, cursor);
// Alert channel service — console by default, webhook if configured
const alertChannels: (ConsoleAlertChannel | WebhookAlertChannel)[] = [new ConsoleAlertChannel()];
if (webhookUrl) {
alertChannels.push(new WebhookAlertChannel({ url: webhookUrl }));
}
const alertService = new AlertChannelService({ channels: alertChannels });
const syncer = new ZkStateSyncer(propagator, { port });
const heartbeat = new HeartbeatMonitor(rpc, propagator, { alertService });
heartbeat.start();
propagator.start();
await syncer.ready;
console.log(`[Bridge] ZK State Syncer listening on port ${syncer.getPort()}`);
// Graceful shutdown
const shutdown = async () => {
console.log("[Bridge] Shutting down...");
heartbeat.stop();
propagator.stop();
await syncer.close();
process.exit(0);
};
process.on("SIGINT", shutdown);
process.on("SIGTERM", shutdown);
}
if (require.main === module || (process.argv[1] && process.argv[1].endsWith("index.js"))) {
main().catch(err => {
console.error("[Bridge] Fatal error:", err);
process.exit(1);
});
}
export { main };