server works with backend via redis, serves chainInfo, more

This commit is contained in:
Tim Olson
2023-10-04 03:42:21 -04:00
parent e36f7812eb
commit c05c9b9c16
12 changed files with 404 additions and 209 deletions

View File

@@ -1,23 +1,13 @@
import {ethers} from "ethers";
export const chains = {}
const _chainInfo = [
{id:42161, name:'Arbitrum'},
]
for( const chain of _chainInfo )
chains[chain.id] = chain
const providers = {} // indexed by chain id
export function getProvider(chainId) {
let result = providers[chainId]
if( result === undefined ) {
let rpc_url = process.env['DEXORDER_RPC_URL_'+chainId]
if( rpc_url === undefined ) {
console.error(`WARNING: No provider found for chainId ${chainId}. Using localhost.`)
rpc_url = 'http://localhost:8545'
}
if( rpc_url === undefined )
throw Error(`WARNING: No provider found for chainId ${chainId}. Using localhost.`)
result = rpc_url.startsWith('ws') ?
new ethers.WebSocketProvider(rpc_url, chainId) :
new ethers.JsonRpcProvider(rpc_url, chainId)