feat(daemom): add support for custom rpcconnect
This commit is contained in:
parent
b921ca71a1
commit
bdbe60e9cd
|
@ -67,24 +67,23 @@ export const generateArgsFromConf = (obj: ZcashConfFile): Array<string> => Objec
|
|||
return acc.concat(`-${key}=${String(obj[key])}`);
|
||||
}, []);
|
||||
|
||||
type ParseCmdArgsPayload = { user: string, password: string, port: string, isTestnet: boolean };
|
||||
type ParseCmdArgsPayload = {
|
||||
rpcuser: string,
|
||||
rpcpassword: string,
|
||||
rpcconnect: string,
|
||||
rpcport: string,
|
||||
testnet: string,
|
||||
};
|
||||
|
||||
const ARGS = ['rpcuser', 'rpcpassword', 'testnet', 'rpcport', 'rpcconnect'];
|
||||
|
||||
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'));
|
||||
return ARGS.reduce((acc, cur) => {
|
||||
const configKey = `-${cur}`;
|
||||
const inArgs = splitArgs.find(x => x.startsWith(configKey));
|
||||
|
||||
const rpcUser = rpcUserInArgs ? rpcUserInArgs.replace('-rpcuser=', '') : '';
|
||||
const rpcPassword = rpcPasswordInArgs ? rpcPasswordInArgs.replace('-rpcpassword=', '') : '';
|
||||
const rpcPort = rpcPortInArgs ? rpcPortInArgs.replace('-rpcport=', '') : '';
|
||||
|
||||
return {
|
||||
user: rpcUser,
|
||||
password: rpcPassword,
|
||||
port: rpcPort,
|
||||
isTestnet: Boolean(testnetInArgs),
|
||||
};
|
||||
return { ...acc, [cur]: inArgs ? inArgs.replace(`${configKey}=`, '') : '' };
|
||||
}, {});
|
||||
};
|
||||
|
|
|
@ -91,6 +91,7 @@ const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve
|
|||
mainWindow.webContents.on('dom-ready', () => {
|
||||
isWindowOpened = true;
|
||||
});
|
||||
store.delete('rpcconnect');
|
||||
store.delete('rpcport');
|
||||
|
||||
const processName = path.join(getBinariesPath(), getOsFolder(), ZCASHD_PROCESS_NAME);
|
||||
|
@ -147,6 +148,7 @@ const runDaemon: () => Promise<?ChildProcess> = () => new Promise(async (resolve
|
|||
}
|
||||
}
|
||||
|
||||
if (optionsFromZcashConf.rpcconnect) store.set('rpcconnect', optionsFromZcashConf.rpcconnect);
|
||||
if (optionsFromZcashConf.rpcport) store.set('rpcport', optionsFromZcashConf.rpcport);
|
||||
if (optionsFromZcashConf.rpcuser) store.set('rpcuser', optionsFromZcashConf.rpcuser);
|
||||
if (optionsFromZcashConf.rpcpassword) store.set('rpcpassword', optionsFromZcashConf.rpcpassword);
|
||||
|
@ -160,17 +162,20 @@ 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, port, isTestnet: isTestnetFromCmd,
|
||||
} = parseCmdArgs(cmd);
|
||||
rpcuser, rpcpassword, rpcconnect, rpcport, testnet: isTestnetFromCmd,
|
||||
} = parseCmdArgs(
|
||||
cmd,
|
||||
);
|
||||
|
||||
store.set(
|
||||
ZCASH_NETWORK,
|
||||
isTestnetFromCmd || optionsFromZcashConf.testnet === '1' ? TESTNET : MAINNET,
|
||||
isTestnetFromCmd === '1' || optionsFromZcashConf.testnet === '1' ? TESTNET : MAINNET,
|
||||
);
|
||||
|
||||
if (user) store.set('rpcuser', user);
|
||||
if (password) store.set('rpcpassword', password);
|
||||
if (port) store.set('rpcport', port);
|
||||
if (rpcuser) store.set('rpcuser', rpcuser);
|
||||
if (rpcpassword) store.set('rpcpassword', rpcpassword);
|
||||
if (rpcport) store.set('rpcport', rpcport);
|
||||
if (rpcconnect) store.set('rpcconnect', rpcconnect);
|
||||
|
||||
return resolve();
|
||||
}
|
||||
|
|
|
@ -9,9 +9,10 @@ import { isTestnet } from '../config/is-testnet';
|
|||
|
||||
const getRPCConfig = () => {
|
||||
const rpcport = store.get('rpcport');
|
||||
const rpcconnect = store.get('rpcconnect');
|
||||
|
||||
return {
|
||||
host: '127.0.0.1',
|
||||
host: rpcconnect || '127.0.0.1',
|
||||
port: rpcport || (isTestnet() ? 18232 : 8232),
|
||||
user: store.get('rpcuser'),
|
||||
password: store.get('rpcpassword'),
|
||||
|
|
Loading…
Reference in New Issue