diff --git a/src/handlers/processControl.js b/src/handlers/processControl.js index 9655621..8edcc80 100644 --- a/src/handlers/processControl.js +++ b/src/handlers/processControl.js @@ -77,8 +77,8 @@ export class ProcessControl { // Open issue: https://github.com/codex-storage/nim-codex/issues/1206 // So we're setting them here. "persistence", - `--eth-provider=https://rpc.testnet.codex.storage`, - `--eth-private-key=eth.key` + `--eth-provider=${this.codexGlobals.getEthProvider()}`, + `--eth-private-key=eth.key`, // duplicated in configService. ]; await this.shell.spawnDetachedProcess(executable, workingDir, args); }; diff --git a/src/main.js b/src/main.js index 4dfc13a..c10ebcb 100644 --- a/src/main.js +++ b/src/main.js @@ -109,7 +109,12 @@ export async function main() { const configService = new ConfigService(fsService, osService); const codexApp = new CodexApp(configService); const pathSelector = new PathSelector(uiService, new MenuLoop(), fsService); - const ethersService = new EthersService(fsService, configService); + const ethersService = new EthersService( + fsService, + configService, + osService, + shellService, + ); const marketplaceSetup = new MarketplaceSetup( uiService, configService, diff --git a/src/services/codexGlobals.js b/src/services/codexGlobals.js index d3344f2..1c2ac57 100644 --- a/src/services/codexGlobals.js +++ b/src/services/codexGlobals.js @@ -13,5 +13,5 @@ export class CodexGlobals { getEthProvider = () => { return "https://rpc.testnet.codex.storage"; - } + }; } diff --git a/src/services/configService.js b/src/services/configService.js index c287fa2..84d0d7e 100644 --- a/src/services/configService.js +++ b/src/services/configService.js @@ -94,22 +94,18 @@ export class ConfigService { this.fs.writeFile( this.getCodexConfigFilePath(), `data-dir="${datadir}"${nl}` + - `log-level="TRACE"${nl}` + - `log-file="${codexLogFile}"${nl}` + - `storage-quota=${this.config.storageQuota}${nl}` + - `disc-port=${this.config.ports.discPort}${nl}` + - `listen-addrs=["/ip4/0.0.0.0/tcp/${this.config.ports.listenPort}"]${nl}` + - `api-port=${this.config.ports.apiPort}${nl}` + - `nat="extip:${publicIp}"${nl}` + - `api-cors-origin="*"${nl}` + - `bootstrap-node=[${bootNodes}]${nl}` + - // Marketplace client parameters: - // `[persistence]${nl}` + - //`eth-provider="${ethProvider}"${nl}` + - // `eth-provider="https://rpc.testnet.codex.storage"${nl}` + - // //`eth-private-key="${ethKeyFile}"${nl}` + - // `eth-private-key="notafile.no"${nl}` + - `${nl}` + `log-level="TRACE"${nl}` + + `log-file="${codexLogFile}"${nl}` + + `storage-quota=${this.config.storageQuota}${nl}` + + `disc-port=${this.config.ports.discPort}${nl}` + + `listen-addrs=["/ip4/0.0.0.0/tcp/${this.config.ports.listenPort}"]${nl}` + + `api-port=${this.config.ports.apiPort}${nl}` + + `nat="extip:${publicIp}"${nl}` + + `api-cors-origin="*"${nl}` + + `bootstrap-node=[${bootNodes}]${nl}` + + // Marketplace client parameters cannot be set via config file. + // Open issue: https://github.com/codex-storage/nim-codex/issues/1206 + `${nl}`, ); }; } diff --git a/src/services/ethersService.js b/src/services/ethersService.js index abb1352..870a39b 100644 --- a/src/services/ethersService.js +++ b/src/services/ethersService.js @@ -1,10 +1,12 @@ -import { ethers } from 'ethers'; +import { ethers } from "ethers"; import crypto from "crypto"; export class EthersService { - constructor(fsService, configService) { + constructor(fsService, configService, osService, shellService) { this.fs = fsService; this.configService = configService; + this.os = osService; + this.shell = shellService; } getOrCreateEthKey = () => { @@ -27,6 +29,14 @@ export class EthersService { const keys = this.generateKey(); this.fs.writeFile(paths.key, keys.key); this.fs.writeFile(paths.address, keys.address); + + if (this.os.isWindows()) { + const username = this.os.getUsername(); + this.shell.run(`icacls ${paths.key} /inheritance:r >nul 2>&1`); + this.shell.run(`icacls ${paths.key} /grant:r ${username}:F >nul 2>&1`); + } else { + this.shell.run(`chmod 600 "${paths.key}"`); + } }; generateKey = () => { diff --git a/src/services/osService.js b/src/services/osService.js index f3b4449..aa05d71 100644 --- a/src/services/osService.js +++ b/src/services/osService.js @@ -33,4 +33,8 @@ export class OsService { terminateProcess = (pid) => { process.kill(pid, "SIGTERM"); }; + + getUsername = () => { + return os.userInfo().username; + }; }