projects
/
crowdnode.js
/
.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9d9d10f
)
refactor: lift some arg and state mangement
author
AJ ONeal
<coolaj86@gmail.com>
Sat, 25 Jun 2022 12:36:01 +0000
(06:36 -0600)
committer
AJ ONeal
<coolaj86@gmail.com>
Sat, 25 Jun 2022 12:36:01 +0000
(06:36 -0600)
bin/crowdnode.js
patch
|
blob
|
history
diff --git
a/bin/crowdnode.js
b/bin/crowdnode.js
index b3c096f461642b7ffbe42ef5fb4eb1ce3bbe044c..4f8a4796a2e3b46c5948d3b0d0e816da124715b8 100755
(executable)
--- a/
bin/crowdnode.js
+++ b/
bin/crowdnode.js
@@
-206,7
+206,8
@@
async function main() {
}
if ("import" === subcommand) {
}
if ("import" === subcommand) {
- await importKey(null, args);
+ let keypath = args.shift() || "";
+ await importKey({ keypath });
process.exit(0);
return;
}
process.exit(0);
return;
}
@@
-319,7
+320,8
@@
async function main() {
// keeping rm for backwards compat
if ("rm" === subcommand || "delete" === subcommand) {
await initCrowdNode(insightBaseUrl);
// keeping rm for backwards compat
if ("rm" === subcommand || "delete" === subcommand) {
await initCrowdNode(insightBaseUrl);
- await removeKey({ defaultAddr, dashApi, insightBaseUrl }, args);
+ let [addr, filepath] = await mustGetAddr({ defaultAddr }, args);
+ await removeKey({ addr, dashApi, filepath, insightBaseUrl }, args);
process.exit(0);
return;
}
process.exit(0);
return;
}
@@
-393,7
+395,8
@@
async function stakeDash(
let err = await Fs.access(args[0]).catch(Object);
let addr;
if (!err) {
let err = await Fs.access(args[0]).catch(Object);
let addr;
if (!err) {
- addr = await importKey(null, [args[0]]);
+ let keypath = args.shift() || "";
+ addr = await importKey({ keypath });
} else if (forceGenerate) {
addr = await generateKey({ defaultKey: defaultAddr }, []);
} else {
} else if (forceGenerate) {
addr = await generateKey({ defaultKey: defaultAddr }, []);
} else {
@@
-882,11
+885,10
@@
async function promptPassphrase() {
/**
* Import and Encrypt
/**
* Import and Encrypt
- * @param {
Null} _
- * @param {
Array<String>} args
+ * @param {
Object} opts
+ * @param {
String} opts.keypath
*/
*/
-async function importKey(_, args) {
- let keypath = args.shift() || "";
+async function importKey({ keypath }) {
let key = await maybeReadKeyFileRaw(keypath);
if (!key?.wif) {
console.error(`no key found for '${keypath}'`);
let key = await maybeReadKeyFileRaw(keypath);
if (!key?.wif) {
console.error(`no key found for '${keypath}'`);
@@
-1387,12
+1389,12
@@
function isNamedLikeKey(name) {
/**
* @param {Object} opts
* @param {any} opts.dashApi - TODO
/**
* @param {Object} opts
* @param {any} opts.dashApi - TODO
- * @param {String} opts.defaultAddr
+ * @param {String} opts.addr
+ * @param {String} opts.filepath
* @param {String} opts.insightBaseUrl
* @param {Array<String>} args
*/
* @param {String} opts.insightBaseUrl
* @param {Array<String>} args
*/
-async function removeKey({ dashApi, defaultAddr, insightBaseUrl }, args) {
- let [addr, name] = await mustGetAddr({ defaultAddr }, args);
+async function removeKey({ addr, dashApi, filepath, insightBaseUrl }, args) {
let balanceInfo = await dashApi.getInstantBalance(addr);
let balanceDash = toDash(balanceInfo.balanceSat);
let balanceInfo = await dashApi.getInstantBalance(addr);
let balanceDash = toDash(balanceInfo.balanceSat);
@@
-1433,10
+1435,10
@@
async function removeKey({ dashApi, defaultAddr, insightBaseUrl }, args) {
}
let wifname = await findWif(addr);
}
let wifname = await findWif(addr);
- let f
ile
path = Path.join(keysDir, wifname);
- let wif = await maybeReadKeyPaths(
name
, { wif: true });
+ let f
ull
path = Path.join(keysDir, wifname);
+ let wif = await maybeReadKeyPaths(
filepath
, { wif: true });
- await Fs.unlink(f
ile
path).catch(function (err) {
+ await Fs.unlink(f
ull
path).catch(function (err) {
console.error(`could not remove ${filepath}: ${err.message}`);
process.exit(1);
});
console.error(`could not remove ${filepath}: ${err.message}`);
process.exit(1);
});