refactored watcher; produces logs
This commit is contained in:
26
main.js
26
main.js
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user