Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Migrate account command - Closes #557 #568

Merged
merged 11 commits into from
Aug 1, 2018
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,20 @@
"@oclif/plugin-help"
],
"topics": {
"account": {
"description": "Manages Lisk accounts."
},
"config": {
"description": "Manages Lisk Commander configuration."
},
"copyright": {
"description": "Displays copyright notice."
},
"help": {
"description": "Displays help."
},
"warranty": {
"description": "Displays warranty notice."
}
}
},
Expand Down
41 changes: 41 additions & 0 deletions src/commands/account/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* LiskHQ/lisk-commander
* Copyright © 2017–2018 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
import { cryptography } from 'lisk-elements';
import BaseCommand from '../../base';
import { createMnemonicPassphrase } from '../../utils/mnemonic';

export default class CreateCommand extends BaseCommand {
async run() {
const passphrase = createMnemonicPassphrase();
const { privateKey, publicKey } = cryptography.getKeys(passphrase);
const address = cryptography.getAddressFromPublicKey(publicKey);
this.print({
passphrase,
privateKey,
publicKey,
address,
});
}
}

CreateCommand.flags = {
...BaseCommand.flags,
};

CreateCommand.description = `
Returns a randomly-generated mnemonic passphrase with its corresponding public/private key pair and Lisk address.
`;
CreateCommand.examples = ['account:create'];
59 changes: 59 additions & 0 deletions src/commands/account/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* LiskHQ/lisk-commander
* Copyright © 2017–2018 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
import BaseCommand from '../../base';
import getAPIClient from '../../utils/api';
import query from '../../utils/query';

export default class GetCommand extends BaseCommand {
async run() {
const { args: { addresses } } = this.parse(GetCommand);
const req = addresses.map(address => ({
query: {
limit: 1,
address,
},
placeholder: {
address,
message: 'Address not found.',
},
}));
const client = getAPIClient(this.userConfig.api);
const results = await query(client, 'accounts', req);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I try an address which has a balance and one which doesn't I just get the error No accounts found using specified parameters. This is pretty unhelpful, but shouldn't I get information about the existing addresses without having to try again anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can think of three way of solving this, but it's not really good UX either...

  1. Ignore errors, unless all error
  2. create another key in the response like { data: [], errors: []}
  3. print error and returned value

1 will be hard to tell what went wrong to the user, and
considering it will be used in script, 2 and 3 will be harder to use.

any other idea to solve this? 😢

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the case where an address is valid but not in the blockchain is a different case to other errors. We could wrap that specific error and return an object that has no public key and no balance (therefore clear that it's never been used). With other errors it's more complicated. I guess it's more acceptable in that case to return an error if anything failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of empty response, we are creating the error on the commander side.
but im not sure it's a good idea to return an object that has no public key and no balance.
Any API change will affect this command to break, while currently it's pretty flexible

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did we do for list before?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no public key and no balance

I just meant an empty string and 0s.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current behavior is the same as before.
if we need to initialize them, we need to be fixed on those field.
maybe what we can do is to define empty object from key?
for example, we call query with object created with key. In account case, it would be
{account: '123L'} and in cause of empty response, return this

this.print(results);
}
}

GetCommand.args = [
{
name: 'addresses',
required: true,
description: 'Comma-separated address(es) to get information about.',
parse: input => input.split(','),
},
];

GetCommand.flags = {
...BaseCommand.flags,
};

GetCommand.description = `
Gets account information from the blockchain.
`;

GetCommand.examples = [
'account:get 3520445367460290306L',
'account:get 3520445367460290306L,2802325248134221536L',
];
53 changes: 53 additions & 0 deletions src/commands/account/show.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* LiskHQ/lisk-commander
* Copyright © 2017–2018 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
import { cryptography } from 'lisk-elements';
import { flags as flagParser } from '@oclif/command';
import BaseCommand from '../../base';
import getInputsFromSources from '../../utils/input';
import commonFlags from '../../utils/flags';

const processInput = ({ passphrase }) => {
const { privateKey, publicKey } = cryptography.getKeys(passphrase);
const address = cryptography.getAddressFromPublicKey(publicKey);
return {
privateKey,
publicKey,
address,
};
};

export default class ShowCommand extends BaseCommand {
async run() {
const { flags: { passphrase: passphraseSource } } = this.parse(ShowCommand);
const input = await getInputsFromSources({
passphrase: {
source: passphraseSource,
repeatPrompt: true,
},
});
this.print(processInput(input));
}
}

ShowCommand.flags = {
...BaseCommand.flags,
passphrase: flagParser.string(commonFlags.passphrase),
};

ShowCommand.description = `
Shows account information for a given passphrase.
`;
ShowCommand.examples = ['account:show'];
45 changes: 0 additions & 45 deletions src/commands_old/create_account.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/commands_old/create_transaction_cast_votes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ValidationError } from '../utils/error';
import getInputsFromSources from '../utils/input';
import { getData } from '../utils/input/utils';
import { createCommand, validatePublicKeys } from '../utils/helpers';
import commonOptions from '../utils/options';
import commonOptions from '../utils/flags';
import transactions from '../utils/transactions';

const description = `Creates a transaction which will cast votes (or unvotes) for delegate candidates using their public keys if broadcast to the network.
Expand Down
2 changes: 1 addition & 1 deletion src/commands_old/create_transaction_register_delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import { createCommand } from '../utils/helpers';
import getInputsFromSources from '../utils/input';
import commonOptions from '../utils/options';
import commonOptions from '../utils/flags';
import transactions from '../utils/transactions';

const description = `Creates a transaction which will register the account as a delegate candidate if broadcast to the network.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
validatePublicKeys,
} from '../utils/helpers';
import getInputsFromSources from '../utils/input';
import commonOptions from '../utils/options';
import commonOptions from '../utils/flags';
import transactions from '../utils/transactions';

const description = `Creates a transaction which will register the account as a multisignature account if broadcast to the network, using the following parameters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import { createCommand } from '../utils/helpers';
import getInputsFromSources from '../utils/input';
import commonOptions from '../utils/options';
import commonOptions from '../utils/flags';
import transactions from '../utils/transactions';

const description = `Creates a transaction which will register a second passphrase for the account if broadcast to the network.
Expand Down
2 changes: 1 addition & 1 deletion src/commands_old/create_transaction_transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
normalizeAmount,
validateAddress,
} from '../utils/helpers';
import commonOptions from '../utils/options';
import commonOptions from '../utils/flags';
import transactions from '../utils/transactions';

const description = `Creates a transaction which will transfer the specified amount to an address if broadcast to the network.
Expand Down
2 changes: 1 addition & 1 deletion src/commands_old/decrypt_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as cryptography from '../utils/cryptography';
import { ValidationError } from '../utils/error';
import { createCommand } from '../utils/helpers';
import getInputsFromSources from '../utils/input';
import commonOptions from '../utils/options';
import commonOptions from '../utils/flags';

const description = `Decrypts a previously encrypted message from a given sender public key for a known nonce using your secret passphrase.

Expand Down
2 changes: 1 addition & 1 deletion src/commands_old/decrypt_passphrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as cryptography from '../utils/cryptography';
import { ValidationError } from '../utils/error';
import { createCommand } from '../utils/helpers';
import getInputsFromSources, { getFirstLineFromString } from '../utils/input';
import commonOptions from '../utils/options';
import commonOptions from '../utils/flags';

const description = `Decrypts your secret passphrase using a password using the initialisation vector (IV) which was provided at the time of encryption.

Expand Down
2 changes: 1 addition & 1 deletion src/commands_old/encrypt_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as cryptography from '../utils/cryptography';
import { ValidationError } from '../utils/error';
import { createCommand } from '../utils/helpers';
import getInputsFromSources from '../utils/input';
import commonOptions from '../utils/options';
import commonOptions from '../utils/flags';

const description = `Encrypts a message for a given recipient public key using your secret passphrase.

Expand Down
2 changes: 1 addition & 1 deletion src/commands_old/encrypt_passphrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import * as cryptography from '../utils/cryptography';
import { createCommand } from '../utils/helpers';
import getInputsFromSources from '../utils/input';
import commonOptions from '../utils/options';
import commonOptions from '../utils/flags';

const description = `Encrypts your secret passphrase under a password.

Expand Down
55 changes: 0 additions & 55 deletions src/commands_old/show_account.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/commands_old/sign_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as cryptography from '../utils/cryptography';
import { ValidationError } from '../utils/error';
import { createCommand } from '../utils/helpers';
import getInputsFromSources from '../utils/input';
import commonOptions from '../utils/options';
import commonOptions from '../utils/flags';

const description = `Sign a message using your secret passphrase.

Expand Down
2 changes: 1 addition & 1 deletion src/commands_old/sign_transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ValidationError } from '../utils/error';
import { createCommand } from '../utils/helpers';
import getInputsFromSources from '../utils/input';
import { getStdIn } from '../utils/input/utils';
import commonOptions from '../utils/options';
import commonOptions from '../utils/flags';

const description = `Sign a transaction using your secret passphrase.

Expand Down
2 changes: 1 addition & 1 deletion src/commands_old/update_forging_status.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import getInputsFromSources from '../utils/input';
import { ValidationError } from '../utils/error';
import getAPIClient from '../utils/api';
import { createCommand } from '../utils/helpers';
import commonOptions from '../utils/options';
import commonOptions from '../utils/flags';

const description = `Updates the forging status of a node.

Expand Down
2 changes: 1 addition & 1 deletion src/commands_old/verify_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as cryptography from '../utils/cryptography';
import { ValidationError } from '../utils/error';
import { createCommand } from '../utils/helpers';
import getInputsFromSources from '../utils/input';
import commonOptions from '../utils/options';
import commonOptions from '../utils/flags';

const description = `Verify a message using the public key, the signature and the message.

Expand Down
Loading