Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into josh/open-source-reqs
Browse files Browse the repository at this point in the history
  • Loading branch information
truemiller committed May 27, 2024
2 parents 405c4bb + 4ba7466 commit 6d0aa6a
Show file tree
Hide file tree
Showing 40 changed files with 1,148 additions and 481 deletions.
2 changes: 1 addition & 1 deletion electron/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const process = require('process');
const { spawnSync } = require('child_process');
const Docker = require('dockerode');

const Version = '0.1.0rc22';
const Version = '0.1.0rc24';
const OperateDirectory = `${os.homedir()}/.operate`;
const VenvDir = `${OperateDirectory}/venv`;
const VersionFile = `${OperateDirectory}/version.txt`;
Expand Down
43 changes: 33 additions & 10 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ let appConfig = {
next: 3000,
},
prod: {
operate: 8000,
operate: 8765,
next: 3000,
},
},
Expand Down Expand Up @@ -270,6 +270,21 @@ async function launchDaemon() {
});
return data;
}

// Free up backend port if already occupied
try {
await fetch(`http://localhost:${appConfig.ports.prod.operate}/api`);
console.log('Killing backend server!');
let endpoint = fs
.readFileSync(`${OperateDirectory}/operate.kill`)
.toString()
.trimLeft()
.trimRight();
await fetch(`http://localhost:${appConfig.ports.prod.operate}/${endpoint}`);
} catch (err) {
console.log('Backend not running!');
}

const check = new Promise(function (resolve, _reject) {
operateDaemon = spawn(
OperateCmd,
Expand All @@ -281,6 +296,14 @@ async function launchDaemon() {
{ env: Env },
);
operateDaemonPid = operateDaemon.pid;
fs.appendFileSync(
`${OperateDirectory}/operate.pip`,
`${operateDaemon.pid}`,
{
encoding: 'utf-8',
},
);

operateDaemon.stderr.on('data', (data) => {
if (data.toString().includes('Uvicorn running on')) {
resolve({ running: true, error: null });
Expand Down Expand Up @@ -337,6 +360,10 @@ async function launchNextApp() {
process.env.NODE_ENV === 'production'
? process.env.FORK_URL
: process.env.DEV_RPC,
NEXT_PUBLIC_BACKEND_PORT:
process.env.NODE_ENV === 'production'
? appConfig.ports.prod.operate
: appConfig.ports.dev.operate,
},
});
await nextApp.prepare();
Expand All @@ -360,7 +387,10 @@ async function launchNextAppDev() {
'yarn',
['dev:frontend', '--port', appConfig.ports.dev.next],
{
env: { ...process.env },
env: {
...process.env,
NEXT_PUBLIC_BACKEND_PORT: appConfig.ports.dev.operate,
},
},
);
nextAppProcessPid = nextAppProcess.pid;
Expand Down Expand Up @@ -444,15 +474,8 @@ ipcMain.on('check', async function (event, _argument) {
await launchNextAppDev();
} else {
event.sender.send('response', 'Starting Pearl Daemon');
const daemonPortAvailable = await isPortAvailable(
appConfig.ports.prod.operate,
);
if (!daemonPortAvailable) {
appConfig.ports.prod.operate = await findAvailablePort({
...PORT_RANGE,
});
}
await launchDaemon();

event.sender.send('response', 'Starting Frontend Server');
const frontendPortAvailable = await isPortAvailable(
appConfig.ports.prod.next,
Expand Down
8 changes: 8 additions & 0 deletions electron/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ const schema = {
type: 'boolean',
default: false,
},
firstStakingRewardAchieved: {
type: 'boolean',
default: false,
},
firstRewardNotificationShown: {
type: 'boolean',
default: false,
},
};

const setupStoreIpc = async (ipcChannel, mainWindow) => {
Expand Down
1 change: 1 addition & 0 deletions frontend/abi/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './agentMech';
export * from './erc20';
export * from './gnosisSafe';
export * from './mechActivityChecker';
export * from './multicall3';
export * from './serviceRegistryL2';
export * from './serviceRegistryTokenUtility';
Expand Down
44 changes: 44 additions & 0 deletions frontend/abi/mechActivityChecker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export const MECH_ACTIVITY_CHECKER_ABI = [
{
inputs: [
{ internalType: 'address', name: '_agentMech', type: 'address' },
{ internalType: 'uint256', name: '_livenessRatio', type: 'uint256' },
],
stateMutability: 'nonpayable',
type: 'constructor',
},
{ inputs: [], name: 'ZeroMechAgentAddress', type: 'error' },
{ inputs: [], name: 'ZeroValue', type: 'error' },
{
inputs: [],
name: 'agentMech',
outputs: [{ internalType: 'address', name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [{ internalType: 'address', name: 'multisig', type: 'address' }],
name: 'getMultisigNonces',
outputs: [{ internalType: 'uint256[]', name: 'nonces', type: 'uint256[]' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{ internalType: 'uint256[]', name: 'curNonces', type: 'uint256[]' },
{ internalType: 'uint256[]', name: 'lastNonces', type: 'uint256[]' },
{ internalType: 'uint256', name: 'ts', type: 'uint256' },
],
name: 'isRatioPass',
outputs: [{ internalType: 'bool', name: 'ratioPass', type: 'bool' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'livenessRatio',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
];
Loading

0 comments on commit 6d0aa6a

Please sign in to comment.