Skip to content

Commit

Permalink
conflicts fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mohandast52 committed Jun 3, 2024
2 parents b12aed4 + 6156813 commit 50f6609
Show file tree
Hide file tree
Showing 37 changed files with 2,711 additions and 339 deletions.
541 changes: 541 additions & 0 deletions .gitleaks.toml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions .gitleaksignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ daf41a143aa8c483db584ba1e7222e8eafec1d3b:backend/controller.py:generic-api-key:2
af77e930289cbc87987567bff0efc25936484df2:backend/controller.py:generic-api-key:354b04972639d66053109596d3b73a1d91688964ebb:electron/constants/publishOptions.js:github-fine-grained-pat:3
b04972639d66053109596d3b73a1d91688964ebb:electron/constants/publishOptions.js:github-fine-grained-pat:3
af77e930289cbc87987567bff0efc25936484df2:backend/controller.py:generic-api-key:354
e7de9ce0b902ed6d68f8c5b033d044f39b08f5a1:operate/data/contracts/service_staking_token/contract.yaml:generic-api-key:10
d8149e9b5b7bd6a7ed7bc1039900702f1d4f287b:operate/services/manage.py:generic-api-key:405
d8149e9b5b7bd6a7ed7bc1039900702f1d4f287b:operate/services/manage.py:generic-api-key:406
d8149e9b5b7bd6a7ed7bc1039900702f1d4f287b:operate/services/manage.py:generic-api-key:454
d8149e9b5b7bd6a7ed7bc1039900702f1d4f287b:operate/services/manage.py:generic-api-key:455
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ E0611: no-name-in-module
R0903: Too few public methods

[IMPORTS]
ignored-modules=os,io
ignored-modules=os,io,psutil

[DESIGN]
# min-public-methods=1
Expand Down
4 changes: 2 additions & 2 deletions electron/constants/publishOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const publishOptions = {
provider: 'github',
owner: 'valory-xyz',
repo: 'olas-operate-app',
releaseType: 'draft',
token: process.env.GH_TOKEN,
private: false,
publishAutoUpdate: true,
releaseType: 'draft',
publishAutoUpdate: false,
};

module.exports = { publishOptions };
99 changes: 80 additions & 19 deletions electron/install.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
// Installation helpers.

const https = require('https');
const path = require('path');
const fs = require('fs');
const os = require('os');
const sudo = require('sudo-prompt');
const process = require('process');
const { spawnSync } = require('child_process');
const axios = require("axios")

const Docker = require('dockerode');
const { spawnSync } = require('child_process');

/**
* current version of the pearl release
* - use "" (nothing as a suffix) for latest release candidate, for example "0.1.0rc26"
* - use "alpha" for alpha release, for example "0.1.0rc26-alpha"
*/
const OlasMiddlewareVersion = '0.1.0rc26';
const OlasMiddlewareVersion = '0.1.0rc34';
const OperateDirectory = `${os.homedir()}/.operate`;
const VenvDir = `${OperateDirectory}/venv`;
const TempDir = `${OperateDirectory}/temp`;
const VersionFile = `${OperateDirectory}/version.txt`;
const LogFile = `${OperateDirectory}/logs.txt`;
const OperateInstallationLog = `${os.homedir()}/operate.log`;
Expand All @@ -27,6 +32,20 @@ const SudoOptions = {
name: 'Pearl',
env: Env,
};
const TendermintUrls = {
darwin: {
x64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_darwin_amd64.tar.gz",
arm64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_darwin_arm64.tar.gz",
},
linux: {
x64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_linux_amd64.tar.gz",
arm64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_linux_arm64.tar.gz",
},
win32: {
x64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_windows_amd64.tar.gz",
arm64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_windows_arm64.tar.gz"
}
}

function getBinPath(command) {
return spawnSync('/usr/bin/which', [command], { env: Env })
Expand Down Expand Up @@ -109,6 +128,46 @@ function installBrew() {
]);
}

function isTendermintInstalledUnix() {
return Boolean(getBinPath('tendermint'));
}

async function downloadFile(url, dest) {
const writer = fs.createWriteStream(dest);
try {
const response = await axios({
url,
method: 'GET',
responseType: 'stream'
});
response.data.pipe(writer);
return new Promise((resolve, reject) => {
writer.on('finish', resolve);
writer.on('error', reject);
});
} catch (err) {
fs.unlink(dest, () => { }); // Delete the file if there is an error
console.error('Error downloading the file:', err.message);
}
}

async function installTendermintUnix() {
const cwd = process.cwd()
process.chdir(TempDir)

console.log(appendLog(`Installing tendermint for ${os.platform()}-${process.arch}`))
const url = TendermintUrls[os.platform()][process.arch]

console.log(appendLog(`Downloading ${url}, might take a while...`))
await downloadFile(url, `${TempDir}/tendermint.tar.gz`)

console.log(appendLog(`Installing tendermint binary`))
await runCmdUnix("tar", ["-xvf", "tendermint.tar.gz"])
await runSudoUnix("install", "tendermint /usr/local/bin")
process.chdir(cwd)
}


function isDockerInstalledDarwin() {
return Boolean(getBinPath('docker'));
}
Expand Down Expand Up @@ -217,7 +276,7 @@ function versionBumpRequired() {
}

function removeLogFile() {
if (fs.existsSync()) {
if (fs.existsSync(LogFile)) {
fs.rmSync(LogFile);
}
}
Expand All @@ -241,13 +300,6 @@ async function setupDarwin(ipcChannel) {
installBrew();
}

console.log(appendLog('Checking docker installation'));
if (!isDockerInstalledDarwin()) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Installing docker'));
installDockerDarwin();
}

console.log(appendLog('Checking python installation'));
if (!isPythonInstalledDarwin()) {
ipcChannel.send('response', 'Installing Pearl Daemon');
Expand All @@ -259,6 +311,13 @@ async function setupDarwin(ipcChannel) {
await createDirectory(`${OperateDirectory}`);
await createDirectory(`${OperateDirectory}/temp`);

console.log(appendLog('Checking tendermint installation'));
if (!isTendermintInstalledUnix()) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Installing tendermint'));
await installTendermintUnix()
}

if (!fs.existsSync(VenvDir)) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Creating virtual environment'));
Expand Down Expand Up @@ -286,14 +345,9 @@ async function setupDarwin(ipcChannel) {
await installOperateCli('/opt/homebrew/bin/operate');
}

// TODO: Add Tendermint installation
async function setupUbuntu(ipcChannel) {
removeInstallationLogFile();
console.log(appendLog('Checking docker installation'));
if (!isDockerInstalledUbuntu()) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Installing docker'));
await installDockerUbuntu();
}

console.log(appendLog('Checking python installation'));
if (!isPythonInstalledUbuntu()) {
Expand All @@ -313,9 +367,11 @@ async function setupUbuntu(ipcChannel) {
await createDirectory(`${OperateDirectory}`);
await createDirectory(`${OperateDirectory}/temp`);

if (versionBumpRequired()) {
// removePreviousInstallation();
writeVersion();
console.log(appendLog('Checking tendermint installation'));
if (!isTendermintInstalledUnix()) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Installing tendermint'));
await installTendermintUnix()
}

if (!fs.existsSync(VenvDir)) {
Expand Down Expand Up @@ -379,4 +435,9 @@ module.exports = {
OperateDirectory,
OperateCmd,
Env,
dirs: {
VersionFile,
LogFile,
OperateInstallationLog,
},
};
103 changes: 100 additions & 3 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ const {
Menu,
Notification,
ipcMain,
dialog,
shell,
} = require('electron');
const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
const os = require('os');
const next = require('next');
const http = require('http');
const AdmZip = require('adm-zip');
const { TRAY_ICONS, TRAY_ICONS_PATHS } = require('./icons');

const {
setupDarwin,
setupUbuntu,
OperateCmd,
OperateDirectory,
startDocker,
Env,
dirs,
} = require('./install');
const { killProcesses } = require('./processes');
const { isPortAvailable, findAvailablePort } = require('./ports');
Expand Down Expand Up @@ -441,8 +444,6 @@ ipcMain.on('check', async function (event, _argument) {
}
}

startDocker(event.sender);

if (isDev) {
event.sender.send(
'response',
Expand Down Expand Up @@ -547,3 +548,99 @@ process.on('uncaughtException', (error) => {
});
});
});

// OPEN PATH
ipcMain.on('open-path', (_, filePath) => {
shell.openPath(filePath);
});

function getSanitizedLogs({ name, filePath, data }) {
const logs = filePath ? fs.readFileSync(filePath, 'utf-8') : data;
const tempDir = os.tmpdir();

const usernameRegex = /\/Users\/([^/]+)/g;
const sanitizedData = logs.replace(usernameRegex, '/Users/*****');

const sanitizedLogsFilePath = path.join(tempDir, name);
fs.writeFileSync(sanitizedLogsFilePath, sanitizedData);

return sanitizedLogsFilePath;
}

// EXPORT LOGS
ipcMain.handle('save-logs', async (_, data) => {
// version.txt
const versionFile = dirs.VersionFile;
// logs.txt
const logFile = getSanitizedLogs({ name: 'log.txt', filePath: dirs.LogFile });
// operate.log
const installationLog = getSanitizedLogs({
name: 'installation_log.txt',
filePath: dirs.OperateInstallationLog,
});

const tempDir = os.tmpdir();

// OS info
const osInfo = `
OS Type: ${os.type()}
OS Platform: ${os.platform()}
OS Arch: ${os.arch()}
OS Release: ${os.release()}
Total Memory: ${os.totalmem()}
Free Memory: ${os.freemem()}
`;
const osInfoFilePath = path.join(tempDir, 'os_info.txt');
fs.writeFileSync(osInfoFilePath, osInfo);

// Persistent store
let storeFilePath;
if (data.store) {
storeFilePath = path.join(tempDir, 'store.txt');
fs.writeFileSync(storeFilePath, JSON.stringify(data.store, null, 2));
}

// Other debug data: balances, addresses, etc.
let debugDataFilePath;
if (data.debugData) {
debugDataFilePath = getSanitizedLogs({
name: 'debug_data.txt',
data: JSON.stringify(data.debugData, null, 2),
});
}

// Create a zip archive
const zip = new AdmZip();
zip.addLocalFile(versionFile);
zip.addLocalFile(logFile);
zip.addLocalFile(installationLog);
zip.addLocalFile(osInfoFilePath);
zip.addLocalFile(storeFilePath);
zip.addLocalFile(debugDataFilePath);

// Show save dialog
const { filePath } = await dialog.showSaveDialog({
title: 'Save Logs',
defaultPath: path.join(os.homedir(), 'pearl_logs.zip'),
filters: [{ name: 'Zip Files', extensions: ['zip'] }],
});

let result;

if (filePath) {
// Write the zip file to the selected path
zip.writeZip(filePath);
result = { success: true, dirPath: path.dirname(filePath) };
} else {
result = { success: false };
}

// Remove temporary files
fs.unlinkSync(logFile);
fs.unlinkSync(installationLog);
fs.unlinkSync(osInfoFilePath);
if (storeFilePath) fs.unlinkSync(storeFilePath);
if (debugDataFilePath) fs.unlinkSync(debugDataFilePath);

return result;
});
2 changes: 2 additions & 0 deletions electron/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ contextBridge.exposeInMainWorld('electronAPI', {
setAppHeight: (height) => ipcRenderer.send('set-height', height),
showNotification: (title, description) =>
ipcRenderer.send('show-notification', title, description),
saveLogs: (data) => ipcRenderer.invoke('save-logs', data),
openPath: (filePath) => ipcRenderer.send('open-path', filePath),
});
2 changes: 1 addition & 1 deletion frontend/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type ChainData = {
export type Service = {
name: string;
hash: string;
keys: ServiceKeys;
keys: ServiceKeys[];
readme?: string;
ledger: LedgerConfig;
chain_data: ChainData;
Expand Down
Loading

0 comments on commit 50f6609

Please sign in to comment.