mirror of
https://github.com/alexbosworth/balanceofsatoshis.git
synced 2026-08-13 12:33:37 +02:00
merge changes
This commit is contained in:
parent
73867048bb
commit
169d527429
15 changed files with 53 additions and 78 deletions
|
|
@ -249,6 +249,10 @@ Use any shorthand you'd like when choosing this profile node name
|
|||
You can also set `cert_path` and `macaroon_path` to the path of the relevant
|
||||
files instead.
|
||||
|
||||
The BOS directory path can be overriden with an environment variable:
|
||||
|
||||
`BOS_DATA_PATH=/path/to/bos/data/dir`
|
||||
|
||||
#### Umbrel Saved Node
|
||||
|
||||
*Note: Umbrel is not FOSS software, use at your own risk.*
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
const {join} = require('path');
|
||||
|
||||
const asyncAuto = require('async/auto');
|
||||
const {returnResult} = require('asyncjs-util');
|
||||
|
||||
const {homePath} = require('../storage');
|
||||
|
||||
const flatten = arr => [].concat(...arr);
|
||||
const {isArray} = Array;
|
||||
const {parse} = JSON;
|
||||
const tagFilePath = () => join(...[homePath({}), 'tags.json']);
|
||||
const tagFilePath = () => homePath({file: 'tags.json'}).path;
|
||||
const uniq = arr => Array.from(new Set(arr));
|
||||
|
||||
/** Get icons for public keys from tags
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
const {homedir} = require('os');
|
||||
const {join} = require('path');
|
||||
const {platform} = require('os');
|
||||
const {publicEncrypt} = require('crypto');
|
||||
const {readFile} = require('fs');
|
||||
|
|
@ -20,9 +19,9 @@ const getMacaroon = require('./get_macaroon');
|
|||
const getPath = require('./get_path');
|
||||
const {getSavedCredentials} = require('./../nodes');
|
||||
const getSocket = require('./get_socket');
|
||||
const {homePath} = require('../storage');
|
||||
const {noSpendPerms} = require('./constants');
|
||||
const {permissionEntities} = require('./constants');
|
||||
const {homePath} = require('../storage');
|
||||
|
||||
const config = 'config.json';
|
||||
const defaultLndDirPath = process.env.BOS_DEFAULT_LND_PATH;
|
||||
|
|
@ -67,7 +66,8 @@ module.exports = (args, cbk) => {
|
|||
return cbk(null, defaultNodeName);
|
||||
}
|
||||
|
||||
const path = join(...[homePath({}), config]);
|
||||
// Look for a config file to see if there is a default node
|
||||
const {path} = homePath({file: config});
|
||||
|
||||
return fs.getFile(path, (err, res) => {
|
||||
// Exit early on errors, there is no config found
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
const {homedir} = require('os');
|
||||
const {join} = require('path');
|
||||
const {randomBytes} = require('crypto');
|
||||
|
||||
const asyncAuto = require('async/auto');
|
||||
|
|
@ -16,7 +14,7 @@ const makeId = () => randomBytes(32).toString('hex');
|
|||
const makeTag = (alias, id) => ({alias, id});
|
||||
const {parse} = JSON;
|
||||
const stringify = obj => JSON.stringify(obj, null, 2);
|
||||
const tagFilePath = () => join(...[homePath({}), 'tags.json']);
|
||||
const tagFilePath = () => homePath({file: 'tags.json'}).path;
|
||||
const uniq = arr => Array.from(new Set(arr));
|
||||
|
||||
/** Adjust tags
|
||||
|
|
@ -82,7 +80,7 @@ module.exports = (args, cbk) => {
|
|||
|
||||
// Register the home directory
|
||||
registerHomeDir: ['validate', ({}, cbk) => {
|
||||
return args.fs.makeDirectory(join(...[homePath({})]), err => {
|
||||
return args.fs.makeDirectory(homePath({}).path, err => {
|
||||
// Ignore errors, the directory may already be there
|
||||
return cbk();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"home": ".bos"
|
||||
}
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
const {homedir} = require('os');
|
||||
const {join} = require('path');
|
||||
|
||||
const asyncAuto = require('async/auto');
|
||||
|
|
@ -38,7 +37,7 @@ module.exports = ({fs, node}, cbk) => {
|
|||
|
||||
// Remove credentials file
|
||||
removeCredentials: ['validate', ({}, cbk) => {
|
||||
const path = join(...[homePath({}), node, credentialsFileName]);
|
||||
const path = join(...[homePath({}).path, node, credentialsFileName]);
|
||||
|
||||
return fs.removeFile(path, err => {
|
||||
if (!!err) {
|
||||
|
|
@ -51,9 +50,7 @@ module.exports = ({fs, node}, cbk) => {
|
|||
|
||||
// Remove credentials directory
|
||||
removeDirectory: ['removeCredentials', ({}, cbk) => {
|
||||
const path = join(...[homePath({}), node]);
|
||||
|
||||
return fs.removeDirectory(path, err => {
|
||||
return fs.removeDirectory(homePath({file: node}).path, err => {
|
||||
if (!!err) {
|
||||
return cbk([503, 'FailedToRemoveCredentialsDirectory', {err}]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
const {homedir} = require('os');
|
||||
const {join} = require('path');
|
||||
|
||||
const asyncAuto = require('async/auto');
|
||||
|
|
@ -6,7 +5,6 @@ const {returnResult} = require('asyncjs-util');
|
|||
|
||||
const {homePath} = require('../storage');
|
||||
|
||||
|
||||
const credentials = 'credentials.json';
|
||||
const {isArray} = Array;
|
||||
const {parse} = JSON;
|
||||
|
|
@ -54,7 +52,7 @@ module.exports = ({fs, node}, cbk) => {
|
|||
|
||||
// Get the credentials file
|
||||
getFile: ['validate', ({}, cbk) => {
|
||||
const path = join(...[homePath({}), node, credentials]);
|
||||
const path = join(...[homePath({}).path, node, credentials]);
|
||||
|
||||
return fs.getFile(path, (err, res) => {
|
||||
// Exit early on errors, there is no credential found
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
const {homedir} = require('os');
|
||||
const {join} = require('path');
|
||||
|
||||
const asyncAuto = require('async/auto');
|
||||
const asyncFilter = require('async/filter');
|
||||
const asyncMap = require('async/map');
|
||||
|
|
@ -58,9 +55,7 @@ module.exports = ({fs, network}, cbk) => {
|
|||
},
|
||||
|
||||
// Data directory
|
||||
dataDir: ['validate', ({}, cbk) => {
|
||||
return cbk(null, join(...[homePath({})]));
|
||||
}],
|
||||
dataDir: ['validate', ({}, cbk) => cbk(null, homePath({}).path)],
|
||||
|
||||
// Check that the data directory exists
|
||||
checkDataDir: ['dataDir', ({dataDir}, cbk) => {
|
||||
|
|
@ -81,9 +76,7 @@ module.exports = ({fs, network}, cbk) => {
|
|||
getDirs: ['checkDataDir', 'dataDir', ({dataDir}, cbk) => {
|
||||
return fs.getDirectoryFiles(dataDir, (err, files) => {
|
||||
return asyncFilter(files, (file, cbk) => {
|
||||
const path = join(...[homePath({}), file]);
|
||||
|
||||
return fs.getFileStatus(path, (err, res) => {
|
||||
return fs.getFileStatus(homePath({file}).path, (err, res) => {
|
||||
if (!!err) {
|
||||
return cbk([503, 'UnexpectedErrCheckingForNodeDir', {err}]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
const {homedir} = require('os');
|
||||
const {join} = require('path');
|
||||
|
||||
const asyncAuto = require('async/auto');
|
||||
const {generateKeyPair} = require('crypto');
|
||||
const {privateDecrypt} = require('crypto');
|
||||
|
|
@ -96,7 +93,7 @@ module.exports = (args, cbk) => {
|
|||
|
||||
// Make sure the home directory is there
|
||||
registerHomeDir: ['validate', ({}, cbk) => {
|
||||
return args.fs.makeDirectory(join(...[homePath({})]), err => {
|
||||
return args.fs.makeDirectory(homePath({}).path, err => {
|
||||
// Ignore errors, the directory may already be there
|
||||
return cbk();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
const {join} = require('path');
|
||||
const {homedir} = require('os');
|
||||
|
||||
const asyncAuto = require('async/auto');
|
||||
const {returnResult} = require('asyncjs-util');
|
||||
|
|
@ -61,9 +60,7 @@ module.exports = (args, cbk) => {
|
|||
|
||||
// Make sure the node directory is there
|
||||
registerDirectory: ['validate', ({}, cbk) => {
|
||||
const nodeDirectory = join(...[homePath({}), args.node]);
|
||||
|
||||
return args.fs.makeDirectory(nodeDirectory, err => {
|
||||
return args.fs.makeDirectory(homePath({file: args.node}).path, err => {
|
||||
// Ignore errors, the directory may already be there
|
||||
return cbk();
|
||||
});
|
||||
|
|
@ -79,7 +76,7 @@ module.exports = (args, cbk) => {
|
|||
socket: args.socket,
|
||||
});
|
||||
|
||||
const path = join(...[homePath({}), args.node, credentials]);
|
||||
const path = join(...[homePath({}).path, args.node, credentials]);
|
||||
|
||||
return args.fs.writeFile(path, file, err => {
|
||||
if (!!err) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
const {homedir} = require('os');
|
||||
const {join} = require('path');
|
||||
|
||||
const asyncAuto = require('async/auto');
|
||||
const {decodeFirst} = require('cbor');
|
||||
const inquirer = require('inquirer');
|
||||
|
|
@ -62,7 +59,7 @@ module.exports = ({ask, cryptography, fs, logger, node}, cbk) => {
|
|||
|
||||
// Make sure the home directory is there
|
||||
registerHomeDirectory: ['validate', ({}, cbk) => {
|
||||
return fs.makeDirectory(join(...[homePath({})]), err => {
|
||||
return fs.makeDirectory(homePath({}).path, err => {
|
||||
// Ignore errors, the directory may already be there
|
||||
return cbk();
|
||||
});
|
||||
|
|
@ -293,9 +290,10 @@ module.exports = ({ask, cryptography, fs, logger, node}, cbk) => {
|
|||
nodeDir: [
|
||||
'details',
|
||||
'nodeName',
|
||||
'registerHomeDirectory', ({nodeName}, cbk) =>
|
||||
'registerHomeDirectory',
|
||||
({nodeName}, cbk) =>
|
||||
{
|
||||
return fs.makeDirectory(join(...[homePath({}), nodeName]), err => {
|
||||
return fs.makeDirectory(homePath({file: nodeName}).path, err => {
|
||||
// Ignore errors, the directory may already be there
|
||||
return cbk();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,11 +4,18 @@ const {join} = require('path');
|
|||
const home = join(...[homedir(), '.bos']);
|
||||
|
||||
/** Get the path of the bos storage directory
|
||||
|
||||
{
|
||||
file: <File Name String>
|
||||
}
|
||||
|
||||
@returns
|
||||
{
|
||||
home: <Home directory path String>
|
||||
path: <Home Directory Path String>
|
||||
}
|
||||
*/
|
||||
module.exports = ({}) => {
|
||||
return process.env.BOS_DIRECTORY || home;
|
||||
module.exports = ({file}) => {
|
||||
const dir = process.env.BOS_DATA_PATH || home;
|
||||
|
||||
return {path: join(...[dir, file].filter(n => !!n))};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
const {homedir} = require('os');
|
||||
const {join} = require('path');
|
||||
|
||||
const asyncAuto = require('async/auto');
|
||||
const asyncMap = require('async/map');
|
||||
const asyncMapSeries = require('async/mapSeries');
|
||||
|
|
@ -59,7 +56,7 @@ const pubKeyHexLength = 66;
|
|||
const rateDivisor = 1e6;
|
||||
const sample = a => !!a.length ? a[Math.floor(Math.random()*a.length)] : null;
|
||||
const sumOf = arr => arr.reduce((sum, n) => sum + n);
|
||||
const tagFilePath = () => join(...[homePath({}), 'tags.json']);
|
||||
const tagFilePath = () => homePath({file: 'tags.json'}).path;
|
||||
const times = 6;
|
||||
const tokAsBigTok = tokens => !tokens ? undefined : (tokens / 1e8).toFixed(8);
|
||||
const topOf = arr => arr.slice(0, Math.ceil(arr.length / 2));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
const {homedir} = require('os');
|
||||
const {join} = require('path');
|
||||
|
||||
const asyncAuto = require('async/auto');
|
||||
const {returnResult} = require('asyncjs-util');
|
||||
|
||||
|
|
@ -9,7 +6,7 @@ const {homePath} = require('../storage');
|
|||
const defaultTags = {tags: []};
|
||||
const {isArray} = Array;
|
||||
const {parse} = JSON;
|
||||
const tagFilePath = () => join(...[homePath({}), 'tags.json']);
|
||||
const tagFilePath = () => homePath({file: 'tags.json'}).path;
|
||||
|
||||
/** Get tagged nodes
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
const {homedir} = require('os');
|
||||
const {join} = require('path');
|
||||
|
||||
const asyncAuto = require('async/auto');
|
||||
const asyncReflect = require('async/reflect');
|
||||
const {Bot} = require('grammy');
|
||||
|
|
@ -43,22 +40,9 @@ module.exports = ({fs, proxy}, cbk) => {
|
|||
return cbk();
|
||||
},
|
||||
|
||||
// Get proxy agent
|
||||
getProxy: ['validate', ({}, cbk) => {
|
||||
// Exit early if not using a proxy
|
||||
if (!proxy) {
|
||||
return cbk();
|
||||
}
|
||||
|
||||
return getSocksProxy({fs, path: proxy}, cbk);
|
||||
}],
|
||||
|
||||
// Home directory path
|
||||
path: ['validate', ({}, cbk) => cbk(null, join(...[homePath({})]))],
|
||||
|
||||
// Ask for an API key
|
||||
apiKey: ['path', ({path}, cbk) => {
|
||||
return fs.getFile(join(...[path, botKeyFile]), (err, res) => {
|
||||
apiKey: ['validate', ({}, cbk) => {
|
||||
return fs.getFile(homePath({file: botKeyFile}).path, (err, res) => {
|
||||
// Exit early when resetting the API key
|
||||
if (!!err || !res || !res.toString() || !!fs.is_reset_state) {
|
||||
const token = interaction.api_token_prompt;
|
||||
|
|
@ -72,6 +56,16 @@ module.exports = ({fs, proxy}, cbk) => {
|
|||
});
|
||||
}],
|
||||
|
||||
// Get proxy agent
|
||||
getProxy: ['validate', ({}, cbk) => {
|
||||
// Exit early if not using a proxy
|
||||
if (!proxy) {
|
||||
return cbk();
|
||||
}
|
||||
|
||||
return getSocksProxy({fs, path: proxy}, cbk);
|
||||
}],
|
||||
|
||||
// Create the bot
|
||||
createBot: ['apiKey', 'getProxy', ({apiKey, getProxy}, cbk) => {
|
||||
const {key} = apiKey;
|
||||
|
|
@ -96,19 +90,21 @@ module.exports = ({fs, proxy}, cbk) => {
|
|||
}],
|
||||
|
||||
// Make the home directory if it's not already present
|
||||
makeDir: ['apiKey', 'path', 'test', asyncReflect(({path}, cbk) => {
|
||||
return fs.makeDirectory(path, cbk);
|
||||
makeDir: ['apiKey', 'test', asyncReflect(({}, cbk) => {
|
||||
return fs.makeDirectory(homePath({}).path, cbk);
|
||||
})],
|
||||
|
||||
// Save the bot API key so it doesn't need to be entered next run
|
||||
saveKey: ['apiKey', 'path', 'makeDir', ({apiKey, path}, cbk) => {
|
||||
saveKey: ['apiKey', 'makeDir', ({apiKey}, cbk) => {
|
||||
// Exit early when API key is already saved
|
||||
if (!!apiKey.is_saved) {
|
||||
return cbk();
|
||||
}
|
||||
|
||||
const {path} = homePath({file: botKeyFile}).path;
|
||||
|
||||
// Ignore errors when making directory, it may already be present
|
||||
return fs.writeFile(join(...[path, botKeyFile]), apiKey.key, err => {
|
||||
return fs.writeFile(path, apiKey.key, err => {
|
||||
if (!!err) {
|
||||
return cbk([503, 'FailedToSaveTelegramApiToken', {err}]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue