Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate provided dAPI names to the scripts #191

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/deploy-communal-api3readerproxyv1.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const hre = require('hardhat');
const api3Contracts = require('@api3/contracts');
const { validateDapiName } = require('./utils');

async function main() {
const dapiName = process.env.DAPI_NAME;
if (!dapiName) {
throw new Error('Environment variable DAPI_NAME is not defined');
}
validateDapiName(dapiName);
const chainId = hre.network.config.chainId;
const api3ReaderProxyV1Address = api3Contracts.computeCommunalApi3ReaderProxyV1Address(chainId, dapiName);
if ((await hre.ethers.provider.getCode(api3ReaderProxyV1Address)) === '0x') {
Expand Down
2 changes: 2 additions & 0 deletions scripts/deploy-dapp-specific-api3readerproxyv1-unsafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// proxies with arbirary dApp aliases to be deployed.
const hre = require('hardhat');
const api3Contracts = require('@api3/contracts');
const { validateDapiName } = require('./utils');

// Unlike the `@api3/contracts` version, the below does not throw due to
// `dappAlias` not being recognized
Expand All @@ -20,6 +21,7 @@ async function main() {
if (!dapiName) {
throw new Error('Environment variable DAPI_NAME is not defined');
}
validateDapiName(dapiName);
const dappAlias = process.env.DAPP_ALIAS;
if (!dappAlias) {
throw new Error('Environment variable DAPP_ALIAS is not defined');
Expand Down
2 changes: 2 additions & 0 deletions scripts/deploy-dapp-specific-api3readerproxyv1.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const hre = require('hardhat');
const api3Contracts = require('@api3/contracts');
const { validateDapiName } = require('./utils');

async function main() {
const dapiName = process.env.DAPI_NAME;
if (!dapiName) {
throw new Error('Environment variable DAPI_NAME is not defined');
}
validateDapiName(dapiName);
const dappAlias = process.env.DAPP_ALIAS;
if (!dappAlias) {
throw new Error('Environment variable DAPP_ALIAS is not defined');
Expand Down
2 changes: 2 additions & 0 deletions scripts/print-communal-api3readerproxyv1-address.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const hre = require('hardhat');
const api3Contracts = require('@api3/contracts');
const { validateDapiName } = require('./utils');

async function main() {
const dapiName = process.env.DAPI_NAME;
if (!dapiName) {
throw new Error('Environment variable DAPI_NAME is not defined');
}
validateDapiName(dapiName);
const chainId = hre.network.config.chainId;
const api3ReaderProxyV1Address = api3Contracts.computeCommunalApi3ReaderProxyV1Address(chainId, dapiName);
console.log(`The address of the communal Api3ReaderProxyV1 for ${dapiName} is ${api3ReaderProxyV1Address}`);
Expand Down
2 changes: 2 additions & 0 deletions scripts/print-dapp-specific-api3readerproxyv1-address.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const hre = require('hardhat');
const api3Contracts = require('@api3/contracts');
const { validateDapiName } = require('./utils');

async function main() {
const dapiName = process.env.DAPI_NAME;
if (!dapiName) {
throw new Error('Environment variable DAPI_NAME is not defined');
}
validateDapiName(dapiName);
const dappAlias = process.env.DAPP_ALIAS;
if (!dappAlias) {
throw new Error('Environment variable DAPP_ALIAS is not defined');
Expand Down
15 changes: 15 additions & 0 deletions scripts/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const api3DapiManagement = require('@api3/dapi-management');

module.exports = {
validateDapiName: (dapiName) => {
const dapi = api3DapiManagement.dapis.find((dapi) => dapi.name === dapiName);
if (!dapi) {
throw new Error(`dAPI with name ${dapiName} does not exist`);
}
if (dapi.stage === 'deprecated') {
console.warn(`dAPI with name ${dapiName} is deprecated`);
} else if (dapi.stage !== 'active') {
throw new Error(`dAPI with name ${dapiName} is not active, its current state is ${dapi.stage}`);
}
},
};
Loading