Compare commits
5 Commits
7f4c301491
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd37554b7d | ||
|
|
0a9b0cc631 | ||
| eca99567d8 | |||
| c95c26afd7 | |||
| 008b6793d1 |
15
cache.js
15
cache.js
@@ -1,12 +1,19 @@
|
||||
import {createClient} from "redis";
|
||||
|
||||
export const redis = createClient({
|
||||
|
||||
async function createRedisClient() {
|
||||
const client = createClient({
|
||||
url: process.env.DEXORDER_REDIS_URL || 'redis://localhost:6379',
|
||||
returnBuffers: false,
|
||||
})
|
||||
})
|
||||
client.on('error', (err) => console.log('Redis Client Error', err));
|
||||
await client.connect();
|
||||
return client
|
||||
}
|
||||
|
||||
redis.on('error', (err) => console.log('Redis Client Error', err));
|
||||
await redis.connect();
|
||||
|
||||
export const redis = await createRedisClient()
|
||||
export const redisSubscriber = await createRedisClient()
|
||||
|
||||
|
||||
export class CacheSet {
|
||||
|
||||
6
chain.js
6
chain.js
@@ -5,11 +5,15 @@ export const chainInfo = JSON.parse(fs.readFileSync('../contract/version.json'))
|
||||
console.log('chainInfo', chainInfo)
|
||||
|
||||
export async function joinChain( socket, chainId ) {
|
||||
try {
|
||||
if (socket.chainId)
|
||||
socket.leave(socket.chainId)
|
||||
socket.join(chainId)
|
||||
socket.chainId = chainId
|
||||
const items = await marks.items(chainId);
|
||||
for (let [token,mark] of items)
|
||||
for (let [token, mark] of items)
|
||||
socket.emit('mark.usd', chainId, token, mark)
|
||||
} catch (e) {
|
||||
console.error('joinChain', e)
|
||||
}
|
||||
}
|
||||
|
||||
10
faucet.js
10
faucet.js
@@ -6,6 +6,16 @@ import {metadata} from "./metadata.js";
|
||||
|
||||
|
||||
export async function gib( chainId, owner, vault, tokenAmounts ) {
|
||||
try {
|
||||
return await doGib( chainId, owner, vault, tokenAmounts )
|
||||
}
|
||||
catch (e) {
|
||||
console.error('gib failed', e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function doGib( chainId, owner, vault, tokenAmounts ) {
|
||||
if (!owner || !vault) return
|
||||
if (chainId === 421614) {
|
||||
// Arbitrum-Sepolia
|
||||
|
||||
11
init.js
Normal file
11
init.js
Normal file
@@ -0,0 +1,11 @@
|
||||
export function initLog(app) {
|
||||
process.on('uncaughtException', (err) => {
|
||||
console.error('Uncaught Exception:', err);
|
||||
process.exit(1); // Exit with code 1
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
||||
process.exit(1); // Exit with code 1
|
||||
});
|
||||
}
|
||||
10
io.js
10
io.js
@@ -1,7 +1,7 @@
|
||||
import {createServer} from "http";
|
||||
import {Server} from "socket.io";
|
||||
import { createAdapter } from "@socket.io/redis-adapter";
|
||||
import {redis} from "./cache.js";
|
||||
import {redis, redisSubscriber} from "./cache.js";
|
||||
import {fileURLToPath} from "url";
|
||||
import path from "path";
|
||||
import express from "express";
|
||||
@@ -29,12 +29,14 @@ app.set('views', path.join(__dirname, 'views')); // Set the views directory
|
||||
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
app.use(cors())
|
||||
app.use((err, req, res, next) => {
|
||||
console.error(err.stack);
|
||||
res.status(500).send('Something went wrong!');
|
||||
});
|
||||
|
||||
initSnapShare(app)
|
||||
|
||||
export const httpServer = createServer(app)
|
||||
export const io = new Server(httpServer, socketIoOptions)
|
||||
const pubClient = redis.duplicate();
|
||||
await pubClient.connect()
|
||||
const adapter = createAdapter(pubClient, redis, {/*key:'socket.io'*/})
|
||||
const adapter = createAdapter(redis, redisSubscriber, {/*key:'socket.io'*/})
|
||||
io.adapter(adapter)
|
||||
|
||||
2
main.js
2
main.js
@@ -1,8 +1,10 @@
|
||||
import 'dotenv/config'
|
||||
import {httpServer} from "./io.js";
|
||||
import {initIO} from "./route.js";
|
||||
import {initLog} from "./init.js";
|
||||
|
||||
|
||||
initLog();
|
||||
initIO();
|
||||
|
||||
const port = parseInt(process.env.DEXORDER_PORT) || 3001;
|
||||
|
||||
25
maxmind.js
25
maxmind.js
@@ -3,6 +3,8 @@ import path from 'path';
|
||||
import {extract} from "tar";
|
||||
import {Reader} from '@maxmind/geoip2-node';
|
||||
|
||||
const ENABLE_MAXMIND=false
|
||||
|
||||
let ipdb = null
|
||||
function setDbFile(file) {
|
||||
const dbBuffer = fs.readFileSync(file);
|
||||
@@ -112,6 +114,11 @@ async function downloadAndExtractMaxmindData(url, outputDir, tempDir, username,
|
||||
* @return {Promise<void>} Resolves when the data check and optional update process is completed.
|
||||
*/
|
||||
async function checkAndUpdateMaxmindData(outputDir, tempDir, url, username, password) {
|
||||
if (username === '' || password === '') {
|
||||
console.log('No MaxMind credentials provided. Skipping MaxMind database update.');
|
||||
return
|
||||
}
|
||||
|
||||
console.log('Checking for MaxMind database updates.');
|
||||
|
||||
// Ensure the output directory exists
|
||||
@@ -146,21 +153,25 @@ async function checkAndUpdateMaxmindData(outputDir, tempDir, url, username, pass
|
||||
|
||||
const url = 'https://download.maxmind.com/geoip/databases/GeoIP2-Country/download?suffix=tar.gz';
|
||||
const outputDirectory = './maxmind';
|
||||
const username = '1102431';
|
||||
const password = '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';
|
||||
// const username = process.env.MAXMIND_ACCOUNT_NUMBER;
|
||||
// const password = process.env.MAXMIND_LICENSE_KEY;
|
||||
// const username = '1102431';
|
||||
// const password = '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';
|
||||
const username = process.env.MAXMIND_ACCOUNT_NUMBER;
|
||||
const password = process.env.MAXMIND_LICENSE_KEY;
|
||||
|
||||
await checkAndUpdateMaxmindData(outputDirectory, '/tmp', url, username, password);
|
||||
if( ENABLE_MAXMIND ) {
|
||||
|
||||
await checkAndUpdateMaxmindData(outputDirectory, '/tmp', url, username, password);
|
||||
|
||||
|
||||
setInterval(async () => {
|
||||
setInterval(async () => {
|
||||
try {
|
||||
await checkAndUpdateMaxmindData(outputDirectory, '/tmp', url, username, password);
|
||||
} catch (error) {
|
||||
console.error('Error during MaxMind database update:', error);
|
||||
}
|
||||
}, 24 * 60 * 60 * 1000 + 1000); // 1 day + 1 second
|
||||
}, 24 * 60 * 60 * 1000 + 1000); // 1 day + 1 second
|
||||
|
||||
}
|
||||
|
||||
|
||||
export function countryForIP(ipAddress) {
|
||||
|
||||
11
pool.js
11
pool.js
@@ -19,18 +19,23 @@ export function unsubPools( socket, chainId, addresses ) {
|
||||
|
||||
|
||||
export async function subOHLCs( socket, chainId, poolPeriods) {
|
||||
try {
|
||||
console.log('subOHLCs', chainId, poolPeriods)
|
||||
for(const key of poolPeriods) {
|
||||
for (const key of poolPeriods) {
|
||||
const room = `${chainId}|${key}`;
|
||||
socket.join(room)
|
||||
let ohlc = await ohlcs.get(chainId,key);
|
||||
let ohlc = await ohlcs.get(chainId, key);
|
||||
console.log('got ohlc', ohlc)
|
||||
if (typeof(ohlc)==='string') {
|
||||
if (typeof (ohlc) === 'string') {
|
||||
ohlc = JSON.parse(ohlc)
|
||||
}
|
||||
socket.emit('ohlc', chainId, key, ohlc)
|
||||
console.log('joined room', room)
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error('subOHLCs', e)
|
||||
}
|
||||
}
|
||||
|
||||
export function unsubOHLCs( socket, chainId, poolPeriods ) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta property="og:title" content="Dexorder Trade Setup">
|
||||
<meta property="og:description" content="Trade this setup on Dexorder">
|
||||
<meta property="og:image" content="{{{imageUrl}}}">
|
||||
<meta property="og:url" content="https://dexorder.com/">
|
||||
<meta property="og:url" content="https://app.dexorder.com/">
|
||||
<meta property="og:type" content="website">
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
|
||||
Reference in New Issue
Block a user