From 5fc34f611bea84eeeb28ca3bc0261bc870ac20e5 Mon Sep 17 00:00:00 2001 From: George Lima Date: Thu, 7 Mar 2019 16:11:45 -0300 Subject: [PATCH 1/4] fix(api): add default value to user/password --- services/api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/api.js b/services/api.js index dc603a70..8b80cb31 100644 --- a/services/api.js +++ b/services/api.js @@ -11,8 +11,8 @@ const RPC = { host: '127.0.0.1', // port: isDev ? 18232 : 8232, port: 18232, // TODO: Test purposes only - user: store.get('rpcuser'), - password: store.get('rpcpassword'), + user: store.get('rpcuser') || '', + password: store.get('rpcpassword') || '', }; const client = got.extend({ From c22fbb4eb34a93a7d8c3a7d3a0d35bdda4deb993 Mon Sep 17 00:00:00 2001 From: George Lima Date: Thu, 7 Mar 2019 16:13:05 -0300 Subject: [PATCH 2/4] fix(parse-zcash-conf): remove side-effects from zcashParse method --- config/daemon/parse-zcash-conf.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/config/daemon/parse-zcash-conf.js b/config/daemon/parse-zcash-conf.js index 2625c202..de8036ec 100644 --- a/config/daemon/parse-zcash-conf.js +++ b/config/daemon/parse-zcash-conf.js @@ -4,7 +4,6 @@ import fs from 'fs'; import { locateZcashConf } from './locate-zcash-conf'; import { filterObjectNullKeys } from '../../app/utils/filter-object-null-keys'; -import store from '../electron-store'; type ZcashConfFile = { testnet: ?string, @@ -32,14 +31,15 @@ type ZcashConfFile = { paytxfee: ?string, }; -export const parseZcashConf = (): Promise> => new Promise((resolve, reject) => { +export const parseZcashConf = (): Promise => new Promise((resolve, reject) => { fs.readFile(locateZcashConf(), (err, file) => { if (err) return reject(err); const fileString = file.toString(); + /* eslint-disable no-unused-vars */ // $FlowFixMe - const { rpcuser, rpcpassword, ...payload }: ZcashConfFile = filterObjectNullKeys( + const payload: ZcashConfFile = filterObjectNullKeys( fileString.split('\n').reduce((acc, cur) => { if (!cur) return acc; @@ -52,14 +52,18 @@ export const parseZcashConf = (): Promise> => new Promise((resolve }, {}), ); - store.set('rpcuser', rpcuser || ''); - store.set('rpcpassword', rpcpassword || ''); - - // $FlowFixMe - resolve(Object.keys(payload).reduce((acc, key) => acc.concat(`-${key}=${payload[key]}`), [])); + resolve(payload); }); }); +/* eslint-disable-next-line max-len */ +export const generateArgsFromConf = (obj: ZcashConfFile): Array => Object.keys(obj).reduce((acc, key) => { + // We can omit the credentials for the command line + if (key === 'rpcuser' || key === 'rpcpassword') return acc; + + return acc.concat(`-${key}=${String(obj[key])}`); +}, []); + export const parseCmdArgs = (cmd: string): { user: string, password: string } => { const rpcUserInArgs = cmd.split(' ').find(x => x.startsWith('-rpcuser')); const rpcPasswordInArgs = cmd.split(' ').find(x => x.startsWith('-rpcpassword')); From db6cf6200ea8d4231d10cc36b34de9143e69c7c3 Mon Sep 17 00:00:00 2001 From: George Lima Date: Thu, 7 Mar 2019 16:15:41 -0300 Subject: [PATCH 3/4] fix(daemon): improve user/password definition for embedded daemon --- config/daemon/zcashd-child-process.js | 33 ++++++++++++--------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/config/daemon/zcashd-child-process.js b/config/daemon/zcashd-child-process.js index 952c553f..66770592 100644 --- a/config/daemon/zcashd-child-process.js +++ b/config/daemon/zcashd-child-process.js @@ -19,7 +19,7 @@ import getDaemonName from './get-daemon-name'; import fetchParams from './run-fetch-params'; import log from './logger'; import store from '../electron-store'; -import { parseZcashConf, parseCmdArgs } from './parse-zcash-conf'; +import { parseZcashConf, parseCmdArgs, generateArgsFromConf } from './parse-zcash-conf'; const getDaemonOptions = ({ username, password, optionsFromZcashConf }) => { /* @@ -70,7 +70,10 @@ const runDaemon: () => Promise = () => new Promise(async (resolve const [, isRunning] = await eres(processExists(ZCASHD_PROCESS_NAME)); // This will parse and save rpcuser and rpcpassword in the store - const [, optionsFromZcashConf = []] = await eres(parseZcashConf()); + const [, optionsFromZcashConf] = await eres(parseZcashConf()); + + if (optionsFromZcashConf.rpcuser) store.set('rpcuser', optionsFromZcashConf.rpcuser); + if (optionsFromZcashConf.rpcpassword) store.set('rpcpassword', optionsFromZcashConf.rpcpassword); if (isRunning) { log('Already is running!'); @@ -85,28 +88,22 @@ const runDaemon: () => Promise = () => new Promise(async (resolve return resolve(); } - const hasCredentials = store.has('rpcuser') && store.has('rpcpassword'); + if (!optionsFromZcashConf.rpcuser) store.set('rpcuser', uuid()); + if (!optionsFromZcashConf.rpcpassword) store.set('rpcpassword', uuid()); - const rpcCredentials = hasCredentials - ? { - username: store.get('rpcuser'), - password: store.get('rpcpassword'), - } - : { - username: uuid(), - password: uuid(), - }; + const rpcCredentials = { + username: store.get('rpcuser'), + password: store.get('rpcpassword'), + }; if (isDev) log('Rpc Credentials', rpcCredentials); - if (!hasCredentials) { - store.set('rpcuser', rpcCredentials.username); - store.set('rpcpassword', rpcCredentials.password); - } - const childProcess = cp.spawn( processName, - await getDaemonOptions({ ...rpcCredentials, optionsFromZcashConf }), + await getDaemonOptions({ + ...rpcCredentials, + optionsFromZcashConf: generateArgsFromConf(optionsFromZcashConf), + }), { stdio: ['ignore', 'pipe', 'pipe'], }, From b57a7e811646ee9ee71000de3d80c77397a745a4 Mon Sep 17 00:00:00 2001 From: George Lima Date: Thu, 7 Mar 2019 16:22:36 -0300 Subject: [PATCH 4/4] bump: 0.4.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b0ca03dd..1d9c1c07 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zec-react-wallet", - "version": "0.4.4", + "version": "0.4.5", "description": "Zcash Reference Wallet", "main": "config/main.js", "license": "MIT",