Skip to content
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
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ COPY package*.json .
COPY schema.graphql .
COPY subgraph.yaml .
COPY networks.json .
COPY update-networks.js .
COPY src ./src

RUN npm ci
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"create": "dotenv -e .env -- sh -c 'graph create ${NETWORK_NAME:-bellecour}/${DEPLOY_ENV:+$DEPLOY_ENV-}poco-v5 --node ${GRAPHNODE_URL:-http://localhost:8020}'",
"deploy": "dotenv -e .env -- sh -c 'graph deploy ${NETWORK_NAME:-bellecour}/${DEPLOY_ENV:+$DEPLOY_ENV-}poco-v5 --node ${GRAPHNODE_URL:-http://localhost:8020} --ipfs ${IPFS_URL:-http://localhost:5001} --network ${NETWORK_NAME:-bellecour} --version-label ${VERSION_LABEL:-dev}'",
"deploy-studio": "dotenv -e .env -- sh -c 'graph deploy ${SUBGRAPH_SLUG} --deploy-key ${SUBGRAPH_DEPLOY_KEY} --network ${SUBGRAPH_NETWORK_NAME} --version-label ${VERSION_LABEL}'",
"all": "npm run build && npm run create && npm run deploy",
"update-networks": "node update-networks.js",
"all": "npm run update-networks && npm run build && npm run create && npm run deploy",
"stop-test-stack": "cd test-stack && docker compose down --remove-orphans --volumes",
"start-test-stack": "npm run stop-test-stack && cd test-stack && export NETWORK_NAME=${NETWORK_NAME:-bellecour} && tsx prepare-test-env.ts && docker compose build && docker compose up -d",
"check-format": "prettier \"(src|tests|test-stack)/**/*.{js,ts}\" --check",
Expand Down Expand Up @@ -58,4 +59,4 @@
"dependencies": {
"@iexec/poco": "^5.5.0"
}
}
}
73 changes: 73 additions & 0 deletions update-networks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';

// Get current file directory in ESM
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const { NETWORK_NAME, START_BLOCK } = process.env; // Get the network name from env

// Path to the networks.json file (one directory up)
const networksFilePath = join(__dirname, 'networks.json');

/**
* Update networks.json file with the current block number
*/
async function updateNetworksFile() {
if (!NETWORK_NAME) {
console.warn(
'No NETWORK_NAME environment variable provided. The networks.json file will not be updated.',
);
return;
}
if (!START_BLOCK) {
console.warn(
'No START_BLOCK environment variable provided. The networks.json file will not be updated.',
);
return;
}

if (!existsSync(networksFilePath)) {
console.warn(`networks.json file not found at ${networksFilePath}`);
return;
}

try {
// Read the current networks.json file
const networksData = JSON.parse(readFileSync(networksFilePath, 'utf8'));

// Check if the specified network exists in the file
if (networksData[NETWORK_NAME]) {
console.log(`Updating startBlock for network '${NETWORK_NAME}' to ${START_BLOCK}`);

// Update all startBlock values for the specified network
Object.keys(networksData[NETWORK_NAME]).forEach((contract) => {
networksData[NETWORK_NAME][contract].startBlock = parseInt(START_BLOCK, 10);
});

// Write the updated networks.json file
writeFileSync(networksFilePath, JSON.stringify(networksData, null, 4));
console.log(`Successfully updated ${networksFilePath}`);
} else {
console.warn(`Network '${NETWORK_NAME}' not found in networks.json. File unchanged.`);
}
} catch (error) {
console.error(`Error updating networks.json file: ${error}`);
}
}

/**
* Main function to orchestrate the process
*/
async function main() {
try {
await updateNetworksFile();
} catch (error) {
console.error(error);
process.exit(1);
}
}

// Run the main function
main();
Loading