Make contract manager evm chains accept rpc urls

This commit is contained in:
Amin Moghaddam 2023-08-28 12:14:40 +02:00 committed by Ali Behjati
parent 9cec35b251
commit 497a52bb94
3 changed files with 23 additions and 3 deletions

View File

@ -26,7 +26,11 @@ async function main() {
contract instanceof EvmContract ||
contract instanceof CosmWasmContract
) {
console.log(`${contract.getId()} ${await contract.getTotalFee()}`);
try {
console.log(`${contract.getId()} ${await contract.getTotalFee()}`);
} catch (e) {
console.error(e);
}
}
}
}

View File

@ -264,7 +264,23 @@ export class EvmChain extends Chain {
);
}
/**
* Returns the chain rpc url with any environment variables replaced or throws an error if any are missing
*/
getRpcUrl(): string {
const envMatches = this.rpcUrl.match(/\$ENV_\w+/);
if (envMatches) {
for (const envMatch of envMatches) {
const envName = envMatch.replace("$ENV_", "");
const envValue = process.env[envName];
if (!envValue) {
throw new Error(
`Missing env variable ${envName} required for chain ${this.id} rpc: ${this.rpcUrl}`
);
}
this.rpcUrl = this.rpcUrl.replace(envMatch, envValue);
}
}
return this.rpcUrl;
}

View File

@ -319,12 +319,12 @@
- id: saigon
wormholeChainName: ronin
mainnet: false
rpcUrl: https://api-gateway.skymavis.com/rpc/testnet?apikey=put-me-here-from-ronin-wallet
rpcUrl: https://api-gateway.skymavis.com/rpc/testnet?apikey=$ENV_RONIN_API_KEY
networkId: 2021
type: EvmChain
- id: ronin
wormholeChainName: ronin
mainnet: true
rpcUrl: https://api-gateway.skymavis.com/rpc?apikey=put-me-here-from-ronin-wallet
rpcUrl: https://api-gateway.skymavis.com/rpc?apikey=$ENV_RONIN_API_KEY
networkId: 2020
type: EvmChain