order status updates working
This commit is contained in:
3
cache.js
3
cache.js
@@ -77,7 +77,6 @@ async function latestBlock(chain) {
|
|||||||
export const vaults = new CacheDict('v')
|
export const vaults = new CacheDict('v')
|
||||||
export const vaultBalances = new CacheDict('vb')
|
export const vaultBalances = new CacheDict('vb')
|
||||||
export const prices = new CacheDict('p')
|
export const prices = new CacheDict('p')
|
||||||
export const orderStatuses = new CacheSet('o')
|
export const orderStatuses = new CacheDict('o')
|
||||||
export const vaultOpenOrders = new CacheDict('voo')
|
export const vaultOpenOrders = new CacheDict('voo')
|
||||||
export const orderFilled = new CacheDict('of')
|
export const orderFilled = new CacheDict('of')
|
||||||
export const trancheFilled = new CacheDict('tf')
|
|
||||||
|
|||||||
3
main.js
3
main.js
@@ -5,7 +5,6 @@ import {httpServer, io} from "./io.js";
|
|||||||
import {ensureVault, loginAddress} from "./vault.js";
|
import {ensureVault, loginAddress} from "./vault.js";
|
||||||
import {chainInfo, VAULT_INIT_CODE_HASH} from "./chain.js";
|
import {chainInfo, VAULT_INIT_CODE_HASH} from "./chain.js";
|
||||||
import {subPools, unsubPools} from "./pool.js";
|
import {subPools, unsubPools} from "./pool.js";
|
||||||
import {subVaultOrders, unsubVaultOrders} from "./order.js";
|
|
||||||
|
|
||||||
|
|
||||||
// setup socket.io
|
// setup socket.io
|
||||||
@@ -18,8 +17,6 @@ io.on("connection", (socket) => {
|
|||||||
socket.on('address', (chainId, address) => loginAddress(socket, chainId, address) )
|
socket.on('address', (chainId, address) => loginAddress(socket, chainId, address) )
|
||||||
socket.on('subPools', (chainId, addresses) => subPools(socket, chainId, addresses) )
|
socket.on('subPools', (chainId, addresses) => subPools(socket, chainId, addresses) )
|
||||||
socket.on('unsubPools', (chainId, addresses) => unsubPools(socket, chainId, addresses) )
|
socket.on('unsubPools', (chainId, addresses) => unsubPools(socket, chainId, addresses) )
|
||||||
socket.on('subVaultOrders', (chainId, address) => subVaultOrders(socket, chainId, address) )
|
|
||||||
socket.on('unsubVaultOrders', (chainId, address) => unsubVaultOrders(socket, chainId, address) )
|
|
||||||
socket.on('ensureVault', (chainId,owner,num) => ensureVault(socket, chainId, owner, num) )
|
socket.on('ensureVault', (chainId,owner,num) => ensureVault(socket, chainId, owner, num) )
|
||||||
socket.join('public')
|
socket.join('public')
|
||||||
socket.emit('welcome', {chainInfo, vaultInitCodeHash:VAULT_INIT_CODE_HASH})
|
socket.emit('welcome', {chainInfo, vaultInitCodeHash:VAULT_INIT_CODE_HASH})
|
||||||
|
|||||||
35
order.js
35
order.js
@@ -1,23 +1,36 @@
|
|||||||
import {redis, vaultOpenOrders} from "./cache.js";
|
import {orderFilled, orderStatuses, vaultOpenOrders} from "./cache.js"
|
||||||
|
import {applyFills} from "../web/src/blockchain/common.js"
|
||||||
|
|
||||||
|
|
||||||
export function subVaultOrders( socket, chainId, vault ) {
|
export function sendVaultOrders( socket, chainId, vault ) {
|
||||||
vaultOpenOrders.get(chainId, vault).then(async (orderIndexes)=>{
|
vaultOpenOrders.get(chainId, vault).then(async (orderIndexes)=>{
|
||||||
for( const orderIndex of JSON.parse(orderIndexes) ) {
|
const result = []
|
||||||
// there is a race condition here since we need multiple queries to get the complete order status,
|
if( orderIndexes !== null ) {
|
||||||
// so we diligently check for nulls and exclude such an order, since it was deleted and no longer active.
|
for (const orderIndex of JSON.parse(orderIndexes)) {
|
||||||
const status = orderStatus( chainId, vault, orderIndex )
|
// there is a race condition here since we need multiple queries to get the complete order status,
|
||||||
if( status != null ) {
|
// so we diligently check for nulls and exclude such an order, since it was deleted and no longer active.
|
||||||
|
const status = await orderStatus(chainId, vault, orderIndex)
|
||||||
|
if (status !== null)
|
||||||
|
result.push([orderIndex, status])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
socket.emit('os', chainId, vault, result)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unsubVaultOrders( socket, chainId, vault ) {
|
export function unsubVaultOrders( socket, chainId, vault ) {
|
||||||
|
console.log('todo: unsubVaultOrders') // todo
|
||||||
}
|
}
|
||||||
|
|
||||||
export function orderStatus( chainId, vault, orderIndex ) {
|
export async function orderStatus( chainId, vault, orderIndex ) {
|
||||||
|
const orderKey = `${vault}|${orderIndex}`
|
||||||
|
let status = await orderStatuses.get(chainId, orderKey)
|
||||||
|
if( status !== null ) {
|
||||||
|
status = JSON.parse(status)
|
||||||
|
const fills = await orderFilled.get(chainId, orderKey)
|
||||||
|
if (fills !== null) {
|
||||||
|
applyFills(status, JSON.parse(fills))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return status
|
||||||
}
|
}
|
||||||
|
|||||||
3
vault.js
3
vault.js
@@ -3,6 +3,7 @@ import {getAbi} from "./abi.js";
|
|||||||
import {getProvider, getSigner} from "./blockchain.js";
|
import {getProvider, getSigner} from "./blockchain.js";
|
||||||
import {vaultBalances, vaults} from './cache.js';
|
import {vaultBalances, vaults} from './cache.js';
|
||||||
import {chainInfo, VAULT_INIT_CODE_HASH} from "./chain.js";
|
import {chainInfo, VAULT_INIT_CODE_HASH} from "./chain.js";
|
||||||
|
import {sendVaultOrders} from "./order.js";
|
||||||
|
|
||||||
// Vault
|
// Vault
|
||||||
// address owner
|
// address owner
|
||||||
@@ -56,6 +57,8 @@ export async function loginAddress(socket, chainId, address) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
socket.emit('vaults', chainId, address, found)
|
socket.emit('vaults', chainId, address, found)
|
||||||
|
for( const vault of found )
|
||||||
|
sendVaultOrders(socket, chainId, vault)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user