This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Migrate account command - Closes #557 #568
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2599b49
:seedling: Migrate account commands
shuse2 31dcb88
:seedling: Migrate account get function
shuse2 7721eb2
:bug: Fix output of the address and arg name
shuse2 97d9e43
:recycle: Update to latest config branch
shuse2 5f92f3b
:recycle: Update name and remove object assign
shuse2 a6ecaa7
:recycle: Update get to return array and change phrases in src and test
shuse2 9a8430d
:seedling: Add query placeholder and fix test phrases
shuse2 5bde694
:fire: Remove migrated files
shuse2 bc49ed7
:fire: Remove usage of utils/cryptography
shuse2 bcf4416
:recycle: Update placeholder message
shuse2 db6143e
:recycle: Update to consistent import
shuse2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
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', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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...
key
in the response like { data: [], errors: []}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? 😢
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just meant an empty string and 0s.
There was a problem hiding this comment.
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