forked from xlnfinance/xln
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxln.ts
More file actions
64 lines (56 loc) · 2.13 KB
/
xln.ts
File metadata and controls
64 lines (56 loc) · 2.13 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
#!/usr/bin/env bun
/**
* XLN CLI Entry Point
*
* This is the main entry point to run xln server.
* Runtime is a pure library with no side effects.
* Uses BrowserVM by default (external RPC not yet supported).
*
* Usage:
* bun run xln.ts → start server with BrowserVM
* NO_DEMO=1 bun run xln.ts → start server without demo prompt
* bun run xln.ts --no-demo → same as above
*/
import * as runtime from './runtime/runtime';
import { ensureBrowserVM } from './runtime/scenarios/boot';
import { startRuntimeWsServer } from './runtime/ws-server';
const { main, startJEventWatcher } = runtime;
// Main execution
(async () => {
try {
// Initialize BrowserVM first (default mode)
console.log('🔧 Initializing BrowserVM...');
const browserVM = await ensureBrowserVM();
console.log(`✅ BrowserVM ready (Depository: ${browserVM.getDepositoryAddress()})`);
// Start runtime
const env = await main();
if (env) {
const noDemoFlag = process.env['NO_DEMO'] === '1' || process.argv.includes('--no-demo');
// Start j-watcher (will detect BrowserVM and skip external RPC)
await startJEventWatcher(env);
const wsPort = process.env['WS_PORT'];
if (wsPort) {
const runtimeId = env.runtimeId || process.env['WS_RUNTIME_ID'] || 'hub';
const host = process.env['WS_HOST'] || '0.0.0.0';
const requireAuth = process.env['WS_REQUIRE_AUTH'] === '1';
startRuntimeWsServer({
host,
port: Number(wsPort),
serverId: runtimeId,
requireAuth,
});
}
if (!noDemoFlag) {
console.log('✅ Node.js environment initialized.');
console.log('💡 Demo removed - use scenarios/ahb.ts or scenarios/grid.ts instead');
console.log('💡 To skip this message, use: NO_DEMO=1 bun run xln.ts or --no-demo flag');
} else {
console.log('✅ Node.js environment initialized (NO_DEMO mode)');
console.log('💡 Use scenarios.ahb(env) or scenarios.grid(env) for demos');
}
}
} catch (error) {
console.error('❌ An error occurred:', error);
process.exit(1);
}
})();