From 675f4b6becaf6a95c31211f633a5c2f425e026b1 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 11 Jul 2024 14:22:51 -0400 Subject: [PATCH] chainInfo fix --- chain.js | 74 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/chain.js b/chain.js index 9e5fbf2..cabec99 100644 --- a/chain.js +++ b/chain.js @@ -15,39 +15,47 @@ const _chains = [ ] for (const chain of _chains) { - const path = `../contract/broadcast/Deploy.sol/${chain.id}/run-latest.json`; - let deployment - try { - deployment = JSON.parse(fs.readFileSync(path, 'utf8')) //null synchronous is ok we only do this once on init - } - catch { - console.log(`warning: could not read deployment files for ${chain.id}`) - continue - } - let maybeFactory = null - for (const tx of deployment.transactions) { - if (tx.contractName === 'VaultFactory') - chain.factory = tx.contractAddress - else if (tx.contractName === 'QueryHelper') - chain.helper = tx.contractAddress - else if (tx.contractName === null) { - if( maybeFactory !== null ) { - console.warn('Multiple broadcast deployments found with a null contractAddress') - maybeFactory = -1 // prevent ever using the null labeled contracts + fs.readdir('../contract/broadcast', (err, files) => { + if (err) throw err; + for (const deploymentClassDir of files) { + if (deploymentClassDir.startsWith('Deploy') && deploymentClassDir.endsWith('.sol')) { + const path = `${deploymentClassDir}/${chain.id}/run-latest.json`; + let deployment + try { + deployment = JSON.parse(fs.readFileSync(path, 'utf8')) //null synchronous is ok we only do this once on init + } + catch { + console.log(`warning: could not read deployment files for ${chain.id}`) + continue + } + let maybeFactory = null + for (const tx of deployment.transactions) { + if (tx.contractName === 'VaultFactory') + chain.factory = tx.contractAddress + else if (tx.contractName === 'QueryHelper') + chain.helper = tx.contractAddress + else if (tx.contractName === null) { + if( maybeFactory !== null ) { + console.warn('Multiple broadcast deployments found with a null contractAddress') + maybeFactory = -1 // prevent ever using the null labeled contracts + } + else if (maybeFactory !== -1) + maybeFactory = tx.contractAddress + } + } + if (chain.factory === undefined) { + if ( maybeFactory !== null && maybeFactory !== -1) + chain.factory = maybeFactory + else + throw Error(`No VaultFactory deployment found for chainId ${chain.id} ${path}`) + } + if (chain.helper === undefined) + throw Error(`No QueryHelper deployment found for chainId ${chain.id} ${path}`) + console.log('VaultFactory', chain.factory) + console.log('QueryHelper', chain.helper) + chainInfo[chain.id] = chain + } - else if (maybeFactory !== -1) - maybeFactory = tx.contractAddress } - } - if (chain.factory === undefined) { - if ( maybeFactory !== null && maybeFactory !== -1) - chain.factory = maybeFactory - else - throw Error(`No VaultFactory deployment found for chainId ${chain.id} ${path}`) - } - if (chain.helper === undefined) - throw Error(`No QueryHelper deployment found for chainId ${chain.id} ${path}`) - console.log('VaultFactory', chain.factory) - console.log('QueryHelper', chain.helper) - chainInfo[chain.id] = chain + }); }