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
Merged

Conversation

shuse2
Copy link
Contributor

@shuse2 shuse2 commented Jun 29, 2018

Description

Migration from

lisk create account
lisk show account

npm t
./bin/run account:create
./bin/run account:show
./bin/run account:get

Review checklist

@shuse2 shuse2 requested a review from willclarktech June 29, 2018 14:07
@shuse2 shuse2 assigned shuse2 and unassigned willclarktech Jun 30, 2018
@shuse2 shuse2 changed the base branch from 2.0.0 to 556_migrate_config_command June 30, 2018 09:39
@shuse2 shuse2 force-pushed the 557-migrate_account_command branch 2 times, most recently from ae21d46 to c0597d5 Compare June 30, 2018 11:12
@shuse2 shuse2 force-pushed the 556_migrate_config_command branch 2 times, most recently from 4669cd4 to 865d40c Compare July 16, 2018 13:22
@shuse2 shuse2 force-pushed the 557-migrate_account_command branch from c0597d5 to abc9bdf Compare July 18, 2018 09:35
@shuse2 shuse2 changed the base branch from 556_migrate_config_command to 2.0.0 July 27, 2018 11:36
@shuse2 shuse2 requested a review from yatki July 27, 2018 11:36
@shuse2 shuse2 force-pushed the 557-migrate_account_command branch from abc9bdf to 492729b Compare July 27, 2018 11:50
package.json Outdated
@@ -57,7 +57,8 @@
"@oclif/plugin-help"
],
"topics": {
"config": { "description": "Manages Lisk Commander configuration." }
"config": { "description": "Manages Lisk Commander configuration." },
"account": { "description": "Manages account." }
Copy link
Contributor

Choose a reason for hiding this comment

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

"Manages Lisk accounts."?

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 was thinking ahead that it should be able to create non-lisk accounts too, but i guess it's too ahead now

package.json Outdated
@@ -57,7 +57,8 @@
"@oclif/plugin-help"
],
"topics": {
"config": { "description": "Manages Lisk Commander configuration." }
"config": { "description": "Manages Lisk Commander configuration." },
"account": { "description": "Manages account." }
Copy link
Contributor

Choose a reason for hiding this comment

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

These are formatted differently to the message for the help command (try ./bin/run).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, maybe something like

"config": { "description": "manage configuration for lisk" },
"account": { "description": "manage account for lisk" }

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather change the help message to conform to the pattern we have here.

};

CreateCommand.description = `
Returns a randomly-generated mnemonic passphrase with its corresponding public key and address.
Copy link
Contributor

Choose a reason for hiding this comment

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

its corresponding public/private key pair and Lisk address

name: 'addresses',
required: true,
description:
'Comma separated address(es) which you want to get the information of.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Comma-separated address(es) to get information about.?

address,
}));
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

import BaseCommand from '../../base';
import getInputsFromSources from '../../utils/input';
import cryptography from '../../utils/cryptography';
import commonOptions from '../../utils/options';
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to rename this commonFlags and utils/flags to be more herouku-consistent?

});

describe('account:get account', () => {
const account = '3520445367460290306L';
Copy link
Contributor

Choose a reason for hiding this comment

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

address

]);
return expect(printMethodStub).to.be.calledWithExactly(queryResult);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Error case? Is there a maximum number of addresses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently there is no maximum (each request is separated)

const queryResult = {
address: account,
name: 'i am owner',
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Now I have to know whether I'm calling this command with one address or more than one in order to process it properly (or do some format check). If I'm using this command as part of a script that generates a variable number of addresses, that might not be obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mmm maybe it will have better UX by always returning the array?

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 so.

...defaultAddress,
});
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

What about warning if the passphrase is not a valid mnemonic? Beyond the scope of this issue?

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 think #337 is the issue

package.json Outdated
@@ -57,8 +57,11 @@
"@oclif/plugin-help"
],
"topics": {
"help": { "description": "Displays help for Lisk Commander." },
"warranty": { "description": "Displays warranty notice for Lisk Commander." },
"copyright": { "description": "Displays copyright notice for Lisk Commander." },
Copy link
Contributor

Choose a reason for hiding this comment

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

All these for Lisk Commanders seem a bit redundant.

address,
}));
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.

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.

@@ -44,53 +44,57 @@ describe('account:get command', () => {
});

describe('account:get account', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

account:get address

package.json Outdated
"config": { "description": "Manages Lisk Commander configuration." },
"account": { "description": "Manages account." }
"account": { "description": "Manages Lisk accounts." }
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer alphabetical order (to match order displayed by oclif).

},
placeholder: {
address,
message: 'No data was returned.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest "Address not found."

@shuse2 shuse2 force-pushed the 557-migrate_account_command branch from 9dbe2e3 to bcf4416 Compare August 1, 2018 11:38
Copy link
Contributor

@willclarktech willclarktech left a comment

Choose a reason for hiding this comment

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

Looking good, would just be nice to align the import style of lisk-elements/cryptography in config:set.

@shuse2 shuse2 merged commit 104f5f3 into 2.0.0 Aug 1, 2018
@shuse2 shuse2 deleted the 557-migrate_account_command branch August 1, 2018 15:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants