Skip to content

Commit

Permalink
include rpcnode
Browse files Browse the repository at this point in the history
  • Loading branch information
fewensa committed Jul 31, 2024
1 parent 6b040af commit 7ed89c2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
4 changes: 1 addition & 3 deletions examples/src/bridges.mainnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ configure:
indexer: https://apollo.helixbridge.app/graphql
relayGasLimit: 600000
rpcnodes:
- name: arbitrum
rpc: https://arb1.arbitrum.io/rpc
fixedGasPrice: 10
- include: arbitrum.yml
- name: polygon
rpc: https://polygon-rpc.com
bridges:
Expand Down
3 changes: 3 additions & 0 deletions examples/src/includes/mainnet/nodes/arbitrum.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: arbitrum
rpc: https://arb1.arbitrum.io/rpc
fixedGasPrice: 10
43 changes: 42 additions & 1 deletion src/generator/generate_configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async function refactorConfig(options) {
includeFileContent = await fs.readFile(pathOfIncludeFromDataPath, 'utf8');
}
// check group file
const pathOfGroupInclude = arg.datapath(`/src/includes/${group}/configures/${include}`);
const pathOfGroupInclude = arg.datapath(`/src/includes/${group}/bridges/${include}`);
if (fs.existsSync(pathOfGroupInclude)) {
includeFileContent = await fs.readFile(pathOfGroupInclude, 'utf8');
}
Expand All @@ -97,6 +97,47 @@ async function refactorConfig(options) {
nbdgs.push(...includeConfigs);
}
configure.bridges = nbdgs;


const nrnds = [];
for (const rpcnode of configure.rpcnodes) {
const include = rpcnode.include;
if (!include) {
nrnds.push(rpcnode);
continue;
}
const keys = Object.keys(rpcnode);
if (keys.length > 1) {
throw new Error(`include mode please do not add other fields: [${keys.join(', ')}]`)
}

let includeFileContent;
if (fs.existsSync(include)) {
includeFileContent = await fs.readFile(include, 'utf8');
}
// check path from datapath
const pathOfIncludeFromDataPath = arg.datapath(`/src/${include}`);
if (fs.existsSync(pathOfIncludeFromDataPath)) {
includeFileContent = await fs.readFile(pathOfIncludeFromDataPath, 'utf8');
}
// check group file
const pathOfGroupInclude = arg.datapath(`/src/includes/${group}/nodes/${include}`);
if (fs.existsSync(pathOfGroupInclude)) {
includeFileContent = await fs.readFile(pathOfGroupInclude, 'utf8');
}
if (!includeFileContent) {
throw new Error(`include file ${include} not found, please check your path`);
}
const includeConfigs = YAML.parse(includeFileContent);
if (!includeConfigs) {
continue;
}
if (configure.rpcnodes.findIndex(item => item.name === includeConfigs.name) > -1) {
throw new Error(`duplicated node {name: ${includeConfigs.name}}`);
}
nrnds.push(includeConfigs);
}
configure.rpcnodes = nrnds;
}

async function _fillEncryptedPrivateKey(options) {
Expand Down

0 comments on commit 7ed89c2

Please sign in to comment.