Skip to content

Commit

Permalink
feat(cli): enhance create output
Browse files Browse the repository at this point in the history
This improves the output of the `xucli create` command to provide
clearer information to the user about how they should proceed and the
outcome of the command.

Closes #1210.
  • Loading branch information
sangaman committed Sep 10, 2019
1 parent 90c129f commit a3e94f1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
8 changes: 4 additions & 4 deletions docs/api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 37 additions & 8 deletions lib/cli/commands/create.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,60 @@
import readline from 'readline';
import { Arguments } from 'yargs';
import { CreateNodeRequest, CreateNodeResponse } from '../../proto/xudrpc_pb';
import { callback, loadXudInitClient } from '../command';
import { CreateNodeRequest } from '../../proto/xudrpc_pb';
import readline from 'readline';

export const command = 'create';

export const describe = 'create an xud node';

export const builder = {};

const formatOutput = (response: CreateNodeResponse.AsObject) => {
if (response.seedMnemonicList.length === 24) {
const WORDS_PER_ROW = 4;
const numberedMnemonic = response.seedMnemonicList.map((value, index) => {
return `${index >= 9 ? '' : ' '}${index + 1}. ${value.padEnd(10)}`;
});
console.log('----------------------BEGIN XUD SEED---------------------');
for (let n = 0; n < response.seedMnemonicList.length / WORDS_PER_ROW; n += 1) {
console.log(numberedMnemonic.slice(n * WORDS_PER_ROW, (n + 1) * WORDS_PER_ROW).join(' '));
}
console.log('-----------------------END XUD SEED----------------------\n');

if (response.initializedLndsList.length) {
console.log(`The following lnd wallets were initialized: ${response.initializedLndsList.join(', ')}`);
}
if (response.initializedRaiden) {
console.log('The wallet for raiden was initialized');
}

console.log(`
Please write down your 24 word mnemonic. It will allow you to recover your xud
key and funds for the initialized wallets listed above should you forget your
password or lose your device. Keep it somewhere safe, it is your ONLY backup.
`);
} else {
console.log('xud was initialized without a seed because no wallets could be initialized.');
}
};

export const handler = (argv: Arguments) => {
const rl = readline.createInterface({
input: process.stdin,
terminal: true,
});

process.stdout.write('Enter master xud password: ');
console.log('You are creating an xud key and underlying wallets secured by a single password.');
process.stdout.write('Enter a password: ');
rl.question('', (password1) => {
process.stdout.write('\n');
process.stdout.write('Re-enter password: ');
process.stdout.write('\nRe-enter password: ');
rl.question('', (password2) => {
process.stdout.write('\n');
process.stdout.write('\n\n');
rl.close();
if (password1 === password2) {
const request = new CreateNodeRequest();
request.setPassword(argv.password);
loadXudInitClient(argv).createNode(request, callback(argv));
request.setPassword(password1);
loadXudInitClient(argv).createNode(request, callback(argv, formatOutput));
} else {
console.log('Passwords do not match, please try again');
}
Expand Down
3 changes: 2 additions & 1 deletion lib/proto/xudrpc.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lib/proto/xudrpc_grpc_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion proto/xudrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@ import "annotations.proto";
package xudrpc;

service XudInit {
/* Creates an xud identity node key and underlying wallets. The node key and
* wallets are derived from a single seed and encrypted using a single
* password provided as a parameter to the call. */
rpc CreateNode(CreateNodeRequest) returns (CreateNodeResponse) { }

/* Unlocks and decrypts the xud node key and any underlying wallets. */
rpc UnlockNode(UnlockNodeRequest) returns (UnlockNodeResponse) { }
}

message CreateNodeRequest {
// The password in utf-8 with which to encrypt the new xud node key as well
// as underlying client wallets such as lnd.
// as any uninitialized underlying wallets.
string password = 1;
}
message CreateNodeResponse {
// The 24 word mnemonic to recover the xud identity key and underlying wallets
repeated string seed_mnemonic = 1;
// The list of lnd clients that were initialized.
repeated string initialized_lnds = 2;
Expand Down

0 comments on commit a3e94f1

Please sign in to comment.