feat(zcash.conf): add parseZcashConf helper

This commit is contained in:
George Lima 2019-02-04 13:10:32 -03:00
parent 695e46ffee
commit 9d170ab368
1 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,28 @@
// @flow
import fs from 'fs';
import { locateZcashConf } from './locate-zcash-conf';
import { filterObjectNullKeys } from '../../app/utils/filter-object-null-keys';
export const parseZcashConf = (): Promise<Array<string>> => new Promise((resolve, reject) => {
fs.readFile(locateZcashConf(), (err, file) => {
// TODO: Maybe we can create the zcash.conf on the fly here
if (err) return reject(err);
const fileString = file.toString();
const optionsFromZcashConf = filterObjectNullKeys(
fileString.split('\n').reduce((acc, cur) => {
const [key, value] = cur.split('=');
return { ...acc, [key]: value };
}, {}),
);
resolve(
Object.keys(optionsFromZcashConf).reduce(
(acc, key) => acc.concat(`-${key}=${optionsFromZcashConf[key]}`),
[],
),
);
});
});