refactored watcher; produces logs

This commit is contained in:
Tim Olson
2023-09-01 18:58:04 -04:00
parent 97234c955f
commit 2e1d2aaa96
9 changed files with 238 additions and 68 deletions

26
main.js
View File

@@ -1,14 +1,25 @@
import 'dotenv/config'
import { createServer } from "http";
import { Server } from "socket.io"
import {lookupToken} from "./token.js";
import {startWatcher} from "./watcher.js";
import {chains} from "./blockchain.js";
import {watchErc20Transfer, watchVaultCreated} from "./vault.js";
import {httpServer, io} from "./io.js";
const options = {}
if( process.env.DEXORDER_CORS )
options['cors'] = {origin:process.env.DEXORDER_CORS}
const httpServer = createServer()
const io = new Server(httpServer, options)
// setup watcher
const filterCallbacks = [
// format is [[className, eventName, ...eventArgs], callback(provider, database, logInfo)]
[['VaultDeployer','VaultCreated', null, null], watchVaultCreated],
[['ERC20', 'Transfer'], watchErc20Transfer],
]
for( const chain of Object.values(chains) )
await startWatcher( chain.id, 1000, filterCallbacks )
// setup socket.io
io.on("connection", (socket) => {
// initially, only anonymous messages are allowed
@@ -23,4 +34,3 @@ io.on("connection", (socket) => {
const port = parseInt(process.env.DEXORDER_PORT) || 3000;
httpServer.listen(port)
console.log('Started server on port '+port)
console.log(options)