Skip to content

Commit

Permalink
update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbosworth committed Nov 22, 2019
1 parent 28e9b2e commit 5cb7654
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 98 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Versions

## Version 5.3.0
## Version 5.3.1

- Add `chart-fees-earned` to show a chart of fees earned

Expand Down
15 changes: 13 additions & 2 deletions lnd/get_cert.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const {homedir} = require('os');
const {join} = require('path');
const {platform} = require('os');

const asyncAuto = require('async/auto');
const {returnResult} = require('asyncjs-util');

const lndDirectory = require('./lnd_directory');

const certPath = ['tls.cert'];
const {path} = lndDirectory({});

/** Get cert for node
Expand All @@ -15,14 +16,18 @@ const {path} = lndDirectory({});
getFile: <Get File Function>
}
[node]: <Node Name String>
os: {
homedir: <Home Directory Function> () => <Home Directory Path String>
platform: <Platform Function> () => <Platform Name String>
}
}
@returns via cbk or Promise
{
[cert]: <Cert File Base64 Encoded String>
}
*/
module.exports = ({fs, node}, cbk) => {
module.exports = ({fs, node, os}, cbk) => {
return new Promise((resolve, reject) => {
return asyncAuto({
// Check arguments
Expand All @@ -31,6 +36,10 @@ module.exports = ({fs, node}, cbk) => {
return cbk([400, 'ExpectedFileSystemMethodsToGetCertForNode']);
}

if (!os) {
return cbk([400, 'ExpectedOperatingSystemMethodsToGetCertForNode']);
}

return cbk();
},

Expand All @@ -40,6 +49,8 @@ module.exports = ({fs, node}, cbk) => {
return cbk();
}

const {path} = lndDirectory({os});

return fs.getFile(join(...[path].concat(certPath)), (err, cert) => {
if (!!err) {
return cbk([503, 'UnexpectedErrorGettingCertFileData', {err}]);
Expand Down
12 changes: 10 additions & 2 deletions lnd/get_macaroon.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const lndDirectory = require('./lnd_directory');
const defaults = [['bitcoin', 'litecoin'], ['mainnet', 'testnet']];
const macDirs = ['data', 'chain'];
const macName = 'admin.macaroon';
const {path} = lndDirectory({});

/** Get macaroon for node
Expand All @@ -19,14 +18,18 @@ const {path} = lndDirectory({});
getFile: <Get File Function> (path, cbk) => {}
}
[node]: <Node Name String>
os: {
homedir: <Home Directory Function> () => <Home Directory Path String>
platform: <Platform Function> () => <Platform Name String>
}
}
@returns via cbk or Promise
{
[macaroon]: <Base64 Encoded Macaroon String>
}
*/
module.exports = ({fs, node}, cbk) => {
module.exports = ({fs, node, os}, cbk) => {
return new Promise((resolve, reject) => {
return asyncAuto({
// Check arguments
Expand All @@ -35,6 +38,10 @@ module.exports = ({fs, node}, cbk) => {
return cbk([400, 'ExpectedFileSystemMethodsToGetMacaroon']);
}

if (!os) {
return cbk([400, 'ExpectedOperatingSystemMethodsToGetMacaroon']);
}

return cbk();
},

Expand All @@ -47,6 +54,7 @@ module.exports = ({fs, node}, cbk) => {

const [chains, nets] = defaults;
let defaultMacaroon;
const {path} = lndDirectory({os});

const all = chains.map(chain => {
return nets.map(network => ({chain, network}));
Expand Down
13 changes: 11 additions & 2 deletions lnd/get_socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const lndDirectory = require('./lnd_directory');
const applicationOptions = 'Application Options';
const confPath = ['lnd.conf'];
const {keys} = Object;
const {path} = lndDirectory({});
const scheme = 'rpc://';

/** Get RPC socket for a node
Expand All @@ -20,14 +19,18 @@ const scheme = 'rpc://';
getFile: <Get Filesystem File Function> (path, cbk) => {}
}
[node]: <Saved Node Name String>
os: {
homedir: <Home Directory Function> () => <Home Directory Path String>
platform: <Platform Function> () => <Platform Name String>
}
}
@returns via cbk or Promise
{
[socket]: <RPC Socket String>
}
*/
module.exports = ({fs, node}, cbk) => {
module.exports = ({fs, node, os}, cbk) => {
return new Promise((resolve, reject) => {
return asyncAuto({
// Check arguments
Expand All @@ -36,6 +39,10 @@ module.exports = ({fs, node}, cbk) => {
return cbk([400, 'ExpectedFilesystemMethodsToGetSocketInfoForNode']);
}

if (!os) {
return cbk([400, 'ExpectedOperatingSystemMethodsToGetNodeSocket']);
}

return cbk();
},

Expand All @@ -46,6 +53,8 @@ module.exports = ({fs, node}, cbk) => {
return cbk();
}

const {path} = lndDirectory({os});

return fs.getFile(join(...[path].concat(confPath)), (err, conf) => {
// Don't report errors, the conf file is either there or not
return cbk(null, conf);
Expand Down
12 changes: 8 additions & 4 deletions lnd/lnd_credentials.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const {homedir} = require('os');
const {platform} = require('os');
const {publicEncrypt} = require('crypto');
const {readFile} = require('fs');
const {spawn} = require('child_process');
Expand All @@ -12,6 +14,8 @@ const getMacaroon = require('./get_macaroon');
const {getSavedCredentials} = require('./../nodes');
const getSocket = require('./get_socket');

const fs = {getFile: readFile};
const os = {homedir, platform};
const socket = 'localhost:10009';

/** LND credentials
Expand All @@ -35,22 +39,22 @@ module.exports = ({logger, key, node}, cbk) => {
return new Promise((resolve, reject) => {
return asyncAuto({
// Get the default cert
getCert: cbk => getCert({node, fs: {getFile: readFile}}, cbk),
getCert: cbk => getCert({fs, node, os}, cbk),

// Get the default macaroon
getMacaroon: cbk => getMacaroon({node, fs: {getFile: readFile}}, cbk),
getMacaroon: cbk => getMacaroon({fs, node, os}, cbk),

// Get the node credentials, if applicable
getNodeCredentials: cbk => {
if (!node) {
return cbk();
}

return getSavedCredentials({node, fs: {getFile: readFile}}, cbk);
return getSavedCredentials({fs, node}, cbk);
},

// Get the socket out of the ini file
getSocket: cbk => getSocket({node, fs: {getFile: readFile}}, cbk),
getSocket: cbk => getSocket({fs, node, os}, cbk),

// Node credentials
nodeCredentials: ['getNodeCredentials', ({getNodeCredentials}, cbk) => {
Expand Down
34 changes: 26 additions & 8 deletions lnd/lnd_directory.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
const {homedir} = require('os');
const {join} = require('path');
const {platform} = require('os');

const platforms = require('./platforms');

/** LND directory path
{}
{
os: {
homedir: <Home Directory Function> () => <Home Directory Path String>
platform: <Platform Function> () => <Platform Name String>
}
}
@throws
<Error>
@returns
{
path: <LND Directory Path String>
}
*/
module.exports = ({}) => {
switch (platform()) {
module.exports = ({os}) => {
if (!os) {
throw new Error('ExpectedOperatingSytemMethodsToDetermineLndDirectory');
}

if (!os.homedir) {
throw new Error('ExpectedHomedirFunctionToDetermineLndDirectory');
}

if (!os.platform) {
throw new Error('ExpectedPlatformFunctionToDetermineLndDirectory');
}

switch (os.platform()) {
case platforms.macOS:
return {path: join(homedir(), 'Library', 'Application Support', 'Lnd')};
return {path: join(os.homedir(), 'Library', 'Application Support', 'Lnd')};

case platforms.windows:
return {path: join(homedir(), 'Lnd')};
return {path: join(os.homedir(), 'Lnd')};

default:
return {path: join(homedir(), '.lnd')};
return {path: join(os.homedir(), '.lnd')};
}
};
2 changes: 1 addition & 1 deletion nodes/get_saved_credentials.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {join} = require('path');
const {homedir} = require('os');
const {join} = require('path');

const asyncAuto = require('async/auto');
const {returnResult} = require('asyncjs-util');
Expand Down
Loading

0 comments on commit 5cb7654

Please sign in to comment.