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

fix: add script to substitute envs in /src code #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ It will stop indexing the old code, and start the new one in its place.

### filling .env

There are contract addresses in `.env.exmaple` that must be chosen
based on the network. Put them into a `.env` for proper usage
The subgraph can't load a `.env` by itself because all handlers are compiled and stored in IPFS.
In this scenario, the environment variables have to be already loaded in the code itself. A script in the
root called `replace-env.js` is provided and used in the scripts to handle this problem.


There are contract addresses in `.env.exmaple` that must be chosen
based on the network. Put them into a `.env` for proper usage.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
},
"scripts": {
"codegen": "graph codegen",
"build": "graph build",
"build": "node replace-env.js && graph build",
"prepare:sepolia": "mustache config/sepolia.json subgraph.template.yaml > subgraph.yaml",
"prepare:arb-sepolia": "mustache config/arb-sepolia.json subgraph.template.yaml > subgraph.yaml",
"deploy": "graph deploy --node https://api.studio.thegraph.com/deploy/ tap-v2",
"deploy": "node replace-env && graph deploy --node https://api.studio.thegraph.com/deploy/ tap-v2",
"create-local": "graph create --node http://localhost:8020/ tap-v2",
"remove-local": "graph remove --node http://localhost:8020/ tap-v2",
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 tap-v2",
Expand Down
11 changes: 11 additions & 0 deletions replace-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require('fs');
const path = require('path');
require('dotenv').config();

const filePath = path.resolve(__dirname, './src/tap-utils.ts');
let fileContent = fs.readFileSync(filePath, 'utf8');

fileContent = fileContent.replace(/{COLLECTOR_ADDRESS}/g, process.env.COLLECTOR_ADDRESS);

fs.writeFileSync(filePath, fileContent);
console.log('Environment variables replaced in mapping files.');
5 changes: 2 additions & 3 deletions src/tap-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {
const ZERO_BI = BigInt.fromI32(0)
const ZERO_AD = Address.zero()


export const TAP_COLLECTOR = Address.fromString(String(process.env.COLLECTOR_ADDRESS));
export const TAP_COLLECTOR = Address.fromString("{COLLECTOR_ADDRESS}");

export function createOrLoadPayer(id: Bytes): Payer {
let payer = Payer.load(id)
Expand Down Expand Up @@ -99,4 +98,4 @@ export function createOrLoadDataService(id: Bytes): DataService {
dataService.save()
}
return dataService as DataService
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,11 @@ [email protected]:
docker-modem "^1.0.8"
tar-fs "~1.16.3"

dotenv@^16.4.5:
version "16.4.7"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.7.tgz#0e20c5b82950140aa99be360a8a5f52335f53c26"
integrity sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==

[email protected]:
version "3.1.8"
resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.8.tgz#758d32910c78047585c7ef1f92f9ee041c1c190b"
Expand Down