initial database migration, watcher.js

This commit is contained in:
Tim Olson
2023-08-30 17:46:22 -04:00
parent 2a0133e605
commit 97234c955f
11 changed files with 779 additions and 3 deletions

View File

@@ -3,7 +3,7 @@ import {ethers} from "ethers";
const providers = {} // indexed by chain id
export function provider(chainId) {
export function getProvider(chainId) {
let result = providers[chainId]
if( result === undefined ) {
const rpc_url = process.env['DEXORDER_RPC_URL_'+chainId]
@@ -19,3 +19,24 @@ export function provider(chainId) {
return result
}
const signers = {} // indexed by chain id, value is an array to be used in round-robin fashion
const signerIndexes = {}
export function signer(chainId) {
let chainSigners = signers[chainId]
if (chainSigners === undefined) {
chainSigners = []
const private_keys = process.env['DEXORDER_ACCOUNTS_' + chainId]
for (const match of private_keys.matchAll(/([^,]+),?/g))
chainSigners.push(new ethers.Wallet(match[1]))
signers[chainId] = chainSigners
signerIndexes[chainId] = 0
}
const result = chainSigners[signerIndexes[chainId]]
signerIndexes[chainId]++
if( signerIndexes[chainId] >= chainSigners.length )
signerIndexes[chainId] = 0
return result
}