+async function load(psuedoState, args) {
+ let name = args.shift();
+
+ // TODO factor out the common bits from generate?
+ let pk = new Dashcore.PrivateKey();
+
+ let pub = pk.toAddress().toString();
+ let wif = pk.toWIF();
+
+ let filepath = `./${pub}.wif`;
+ let note = "";
+ if (name) {
+ filepath = name;
+ note = `\n(for pubkey address ${pub})`;
+ }
+
+ let err = await Fs.access(filepath).catch(Object);
+ if (!err) {
+ console.info(`'${filepath}' already exists (will not overwrite)`);
+ } else {
+ await Fs.writeFile(filepath, wif, "utf8");
+ console.info(`Generated ${filepath} ${note}`);
+ }
+
+ let desiredAmountDash = parseFloat(args.shift() || 0);
+ let desiredAmountDuff = Math.round(desiredAmountDash * DUFFS);
+ let effectiveDuff = desiredAmountDuff;
+ let effectiveDash = "";
+ if (!effectiveDuff) {
+ effectiveDuff = CrowdNode.stakeMinimum + signupTotal + feeEstimate;
+ effectiveDash = toDash(effectiveDuff);
+ // Round to the nearest mDash
+ // ex: 0.50238108 => 0.50300000
+ effectiveDuff = toDuff(Math.ceil(effectiveDash * 1000) / 1000);
+ effectiveDash = toDash(effectiveDuff);
+ }
+
+ console.info(``);
+ showQr(pub, effectiveDuff);
+ console.info(``);
+ console.info(
+ `Use the QR Code above to load ${effectiveDuff} (Đ${effectiveDash}) onto your staking key.`,
+ );
+ console.info(``);
+ console.info(`(waiting...)`);
+ console.info(``);
+ let payment = await Ws.waitForVout(psuedoState.insightBaseUrl, pub, 0);
+ console.info(`Received ${payment.satoshis}`);
+ process.exit(0);
+}
+