This repository was archived by the owner on Feb 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (30 loc) · 1.37 KB
/
server.js
File metadata and controls
37 lines (30 loc) · 1.37 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
// src/server.js
import http from 'http';
import { WALLET_ADDRESSES, PROVIDERS, SUBSCAN_URLS, PORT } from './config/config.js';
import { connectToProviders, getInitialBalances, subscribeToBalanceChanges } from './services/polkadotService.js';
import { checkCardanoWallets } from './services/cardanoService.js';
function logInitialBalances(balances, addresses, providers) {
balances.forEach((balances, walletIndex) => {
balances.forEach((balance, providerIndex) => {
console.log(`Initial balance for wallet ${addresses[walletIndex]} on provider ${providers[providerIndex].name}: ${balance}`);
});
});
}
async function main() {
const apis = await connectToProviders(PROVIDERS.map(provider => provider.url));
const previousBalances = await getInitialBalances(apis, WALLET_ADDRESSES);
logInitialBalances(previousBalances, WALLET_ADDRESSES, PROVIDERS);
const subscriptions = subscribeToBalanceChanges(apis, WALLET_ADDRESSES, previousBalances, PROVIDERS, SUBSCAN_URLS);
// Check Cardano wallets
await checkCardanoWallets();
// Create an HTTP server and bind it to the specified port
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Server is running');
});
server.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}`);
});
}
main().catch(console.error);