initial database migration, watcher.js
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user