USD marks
This commit is contained in:
5
cache.js
5
cache.js
@@ -37,6 +37,10 @@ export class CacheDict {
|
||||
async contains(chain, key) {
|
||||
return await redis.hExists(`${chain}|${this.series}`, key)
|
||||
}
|
||||
|
||||
async items(chain) {
|
||||
return Object.entries(await redis.hGetAll(`${chain}|${this.series}`)).map(([k, v]) => [k, v === null ? null : '' + v])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,3 +87,4 @@ export const vaultOpenOrders = new CacheDict('voo')
|
||||
export const vaultRecentlyClosedOrders = new CacheDict('vrco')
|
||||
export const orderFilled = new CacheDict('of')
|
||||
export const ohlcs = new CacheDict('ohlc')
|
||||
export const marks = new CacheDict('mark.usd')
|
||||
|
||||
11
chain.js
11
chain.js
@@ -1,4 +1,15 @@
|
||||
import fs from "fs";
|
||||
import {marks} from "./cache.js";
|
||||
|
||||
export const chainInfo = JSON.parse(fs.readFileSync('../contract/version.json')).chainInfo
|
||||
console.log('chainInfo', chainInfo)
|
||||
|
||||
export async function joinChain( socket, chainId ) {
|
||||
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)
|
||||
socket.emit('mark.usd', chainId, token, mark)
|
||||
}
|
||||
|
||||
2
route.js
2
route.js
@@ -4,6 +4,7 @@ import {requestVault, loginAddress} from "./vault.js";
|
||||
import {subOHLCs, subPools, unsubOHLCs, unsubPools} from "./pool.js";
|
||||
import {gib} from "./faucet.js";
|
||||
import {approveRegion, approveTOS} from "./approval.js";
|
||||
import {joinChain} from "./chain.js";
|
||||
|
||||
// Server route handling
|
||||
|
||||
@@ -21,6 +22,7 @@ export function initIO() {
|
||||
socket.on('gib', async (chainId, owner, vault, tokenAmounts) => await gib(chainId, owner, vault, tokenAmounts))
|
||||
socket.on('approveTOS', (time, version, callback) => approveTOS(socket, time, version, callback))
|
||||
socket.on('approveRegion', (bypass) => approveRegion(socket, bypass))
|
||||
socket.on('chain', async (chainId) => await joinChain(socket, chainId))
|
||||
socket.join('public')
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user