feat(daemon): add support for zcash.conf -rpcport

This commit is contained in:
George Lima 2019-05-13 22:18:52 -03:00
parent 026e00ad5e
commit b921ca71a1
3 changed files with 27 additions and 11 deletions

View File

@ -67,17 +67,24 @@ export const generateArgsFromConf = (obj: ZcashConfFile): Array<string> => Objec
return acc.concat(`-${key}=${String(obj[key])}`);
}, []);
export const parseCmdArgs = (
cmd: string,
): { user: string, password: string, isTestnet: boolean } => {
type ParseCmdArgsPayload = { user: string, password: string, port: string, isTestnet: boolean };
export const parseCmdArgs = (cmd: string): ParseCmdArgsPayload => {
const splitArgs = cmd.split(' ');
const rpcUserInArgs = splitArgs.find(x => x.startsWith('-rpcuser'));
const rpcPasswordInArgs = splitArgs.find(x => x.startsWith('-rpcpassword'));
const testnetInArgs = splitArgs.find(x => x.startsWith('-testnet'));
const rpcPortInArgs = splitArgs.find(x => x.startsWith('-rpcport'));
const rpcUser = rpcUserInArgs ? rpcUserInArgs.replace('-rpcuser=', '') : '';
const rpcPassword = rpcPasswordInArgs ? rpcPasswordInArgs.replace('-rpcpassword=', '') : '';
const rpcPort = rpcPortInArgs ? rpcPortInArgs.replace('-rpcport=', '') : '';
return { user: rpcUser, password: rpcPassword, isTestnet: Boolean(testnetInArgs) };
return {
user: rpcUser,
password: rpcPassword,
port: rpcPort,
isTestnet: Boolean(testnetInArgs),
};
};

View File

@ -91,6 +91,7 @@ const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve
mainWindow.webContents.on('dom-ready', () => {
isWindowOpened = true;
});
store.delete('rpcport');
const processName = path.join(getBinariesPath(), getOsFolder(), ZCASHD_PROCESS_NAME);
const isRelaunch = Boolean(process.argv.find(arg => arg === '--relaunch'));
@ -146,6 +147,7 @@ const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve
}
}
if (optionsFromZcashConf.rpcport) store.set('rpcport', optionsFromZcashConf.rpcport);
if (optionsFromZcashConf.rpcuser) store.set('rpcuser', optionsFromZcashConf.rpcuser);
if (optionsFromZcashConf.rpcpassword) store.set('rpcpassword', optionsFromZcashConf.rpcpassword);
@ -157,7 +159,9 @@ const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve
// Command line args override zcash.conf
const [{ cmd }] = await findProcess('name', ZCASHD_PROCESS_NAME);
const { user, password, isTestnet: isTestnetFromCmd } = parseCmdArgs(cmd);
const {
user, password, port, isTestnet: isTestnetFromCmd,
} = parseCmdArgs(cmd);
store.set(
ZCASH_NETWORK,
@ -166,6 +170,7 @@ const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve
if (user) store.set('rpcuser', user);
if (password) store.set('rpcpassword', password);
if (port) store.set('rpcport', port);
return resolve();
}

View File

@ -7,12 +7,16 @@ import { METHODS, type APIMethods } from './utils';
import store from '../config/electron-store';
import { isTestnet } from '../config/is-testnet';
const getRPCConfig = () => ({
host: '127.0.0.1',
port: isTestnet() ? 18232 : 8232,
user: store.get('rpcuser'),
password: store.get('rpcpassword'),
});
const getRPCConfig = () => {
const rpcport = store.get('rpcport');
return {
host: '127.0.0.1',
port: rpcport || (isTestnet() ? 18232 : 8232),
user: store.get('rpcuser'),
password: store.get('rpcpassword'),
};
};
const getMessage = (statusCode, isECONNREFUSED) => {
if (isECONNREFUSED) {