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

remove message about missing file file #131

Merged
merged 1 commit into from
Aug 22, 2024
Merged
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
136 changes: 69 additions & 67 deletions src/commands/offchain/start.ts
Original file line number Diff line number Diff line change
@@ -1,98 +1,100 @@
import Chalk from 'chalk'
import { store, get as storeGet, set as storeSet } from '../../store'
import { execSync } from 'child_process'
const fs = require('fs')
import Chalk from "chalk";
import { store, get as storeGet, set as storeSet } from "../../store";
import { execSync } from "child_process";
const fs = require("fs");

const headPrivateIdentity = `${store.system.homedir}/.bls/network/keys/head/priv.bin`
const workerPrivateIdentity = `${store.system.homedir}/.bls/network/keys/worker1/priv.bin`
const headPrivateIdentity = `${store.system.homedir}/.bls/network/keys/head/priv.bin`;
const workerPrivateIdentity = `${store.system.homedir}/.bls/network/keys/worker1/priv.bin`;

const runtimePath = `${store.system.homedir}/.bls/runtime`
const runtimePath = `${store.system.homedir}/.bls/runtime`;

const readFirstLineSync = (filePath: string) => {
try {
const fileContent = fs.readFileSync(filePath, 'utf8')
const lines = fileContent.split(/\r?\n/) // This regex handles both Windows (\r\n) and UNIX (\n) line endings
return lines[0] || '' // Return an empty string if the first line does not exist
const fileContent = fs.readFileSync(filePath, "utf8");
const lines = fileContent.split(/\r?\n/); // This regex handles both Windows (\r\n) and UNIX (\n) line endings
return lines[0] || ""; // Return an empty string if the first line does not exist
} catch (error: any) {
console.error(`Error reading the file: ${error.message}`)
return '' // Return an empty string if an error occurs
// console.error(`Error reading the file: ${error.message}`)
return ""; // Return an empty string if an error occurs
}
}
};

const peerIdFile = `${store.system.homedir}/.bls/network/keys/head/peerid.txt`;
const headNodePeerId = readFirstLineSync(peerIdFile);

const peerIdFile = `${store.system.homedir}/.bls/network/keys/head/peerid.txt`
const headNodePeerId = readFirstLineSync(peerIdFile)
// I don't think it matters at the moment
if (!headNodePeerId) {
console.log('The file is empty or does not exist.')
// console.log('The file is empty or does not exist.')
}

const headCommand = [
'--peer-db',
'/tmp/b7s/head-peer-db',
'--function-db',
'/tmp/b7s/head-fdb',
'--log-level',
'debug',
'--port',
'9527',
'--role',
'head',
'--workspace',
'/tmp/debug/head',
'--private-key',
"--peer-db",
"/tmp/b7s/head-peer-db",
"--function-db",
"/tmp/b7s/head-fdb",
"--log-level",
"debug",
"--port",
"9527",
"--role",
"head",
"--workspace",
"/tmp/debug/head",
"--private-key",
headPrivateIdentity,
'--rest-api',
':6000'
].join(' ')
"--rest-api",
":6000",
].join(" ");

const workerCommand = [
'--peer-db',
'/tmp/b7s/worker-peer-db',
'--function-db',
'/tmp/b7s/worker-fdb',
'--log-level',
'debug',
'--port',
'0',
'--role',
'worker',
'--runtime',
"--peer-db",
"/tmp/b7s/worker-peer-db",
"--function-db",
"/tmp/b7s/worker-fdb",
"--log-level",
"debug",
"--port",
"0",
"--role",
"worker",
"--runtime",
runtimePath,
'--workspace',
'/tmp/debug/worker',
'--private-key',
"--workspace",
"/tmp/debug/worker",
"--private-key",
workerPrivateIdentity,
'--boot-nodes',
`/ip4/0.0.0.0/tcp/9527/p2p/${headNodePeerId}`
].join(' ')
"--boot-nodes",
`/ip4/0.0.0.0/tcp/9527/p2p/${headNodePeerId}`,
].join(" ");

export const run = (agentType: string = 'head') => {
let type = 'head'
export const run = (agentType: string = "head") => {
let type = "head";

switch (agentType) {
case 'worker':
type = 'worker'
break
case 'head':
type = 'head'
break
case "worker":
type = "worker";
break;
case "head":
type = "head";
break;
default:
type = 'head'
break
type = "head";
break;
}

console.log(`${Chalk.yellow('Off-Chain')} ... starting ${type} node`)
console.log(`${Chalk.yellow("Off-Chain")} ... starting ${type} node`);

try {
execSync(
`cd ${store.system.homedir}/.bls/network; ./b7s ${
type == 'head' ? headCommand : workerCommand
type == "head" ? headCommand : workerCommand
}`,
{
stdio: 'inherit'
}
)
process.exit(0)
stdio: "inherit",
},
);
process.exit(0);
} catch (error) {
process.exit(0)
process.exit(0);
}
}
};
Loading