Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/8 add cli commands for parce related data #56

Merged
merged 7 commits into from
Mar 11, 2019

Conversation

h0n9
Copy link
Contributor

@h0n9 h0n9 commented Mar 10, 2019

  • Modification on 'transfer' operation to make it fully functional
  • Support for 6 of parcel-related operations
  • Minor modification on codes' structures for ease of development

MakeMessage -> Sign Payload -> Signature, SigningPubKey, Signer(Address), Payload, etc..
(unfortunately verification on amoabci server's checkTx() is not supported yet)

type Message struct {
	Command       string          `json:"command"`
	Signer        crypto.Address  `json:"signer"`
	SigningPubKey p256.PubKeyP256 `json:"singingPubKey"`
	Signature     cmn.HexBytes    `json:"signature"`
	Payload       json.RawMessage `json:"payload"`
	Nonce         uint32          `json:"nonce"`
}
/* Commands (expected hierarchy)
 *
 * amocli |- tx |- transfer --to <address> --amount <uint64>
 *		|
 *		|- register --target <file> --custody <key>
 *		|- request --target <file> --payment <uint64>
 *		|- cancel --target <file>
 *		|
 *		|- grant --target <file> --grantee <address> --custody <key>
 *		|- revoke --target <file> --grantee <address>
 *		|- discard --target <file>
 */

resolves #8

- restructure tx-related functions's folder structure
- add signing option for future use
  (user can choose which key to use for signing the tx)
- add register, request, cancel operations
- add grant, revoke, discard operations

- decrypt key when making message(rpc)
- add linebreak between CLI operations
@h0n9 h0n9 self-assigned this Mar 10, 2019
@h0n9 h0n9 requested a review from Lbird March 10, 2019 18:52
@h0n9
Copy link
Contributor Author

h0n9 commented Mar 10, 2019

After parcel-related operations' descriptions on rpc.md are fully set, each of operation's description on CLI is planned to get improved for better understanding.

@@ -51,3 +60,72 @@ func SaveKeyList(path string, keyList map[string]Key) error {

return nil
}

func GetKeyToSign(path string) (Key, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why don''t you change the name to 'SelectKey...'?

return key, errors.New("The key doesn't exist")
}

key = keyList[nickname]
Copy link
Contributor

Choose a reason for hiding this comment

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

recommend refactoring. not very clear distinction between getkey...() and check().

return key, err
}

nickname = strings.Replace(nickname, "\r\n", "", -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

is it necessary? what about using Trim()?

keyStatus := Check(nickname, path)
switch keyStatus {
case NoExists:
return key, errors.New("The key doesn't exist")
Copy link
Contributor

Choose a reason for hiding this comment

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

purpose of this function is to select one of the existing keys, then this error message is confusing. what? doesn't exist?

return key, nil
}

func GetDecryptedKey(key *Key) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

this function "transforms" the key that we already have. what about renaming it to "decrypt key".


"github.com/amolabs/amoabci/amo/operation"
atypes "github.com/amolabs/amoabci/amo/types"
)

// Transfer handles transfer transaction
func Transfer(to types.Address, amount *atypes.Currency) (*ctypes.ResultBroadcastTxCommit, error) {
return RPCBroadcastTxCommit(MakeMessage(operation.TxTransfer, operation.Transfer{
func Transfer(to crypto.Address, amount *atypes.Currency, sign bool) (*ctypes.ResultBroadcastTxCommit, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

after we start to support signed transaction, signing a transaction should be mandatory. an unsigned transaction will be not an option. and this comment applies to other transactions: register, request, ...

@@ -16,20 +22,62 @@ var (
)

// MakeMessage handles making tx message
func MakeMessage(t string, payload interface{}) types.Tx {
func MakeMessage(t string, nonce uint32, payload interface{}, sign bool) (types.Tx, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

refer to the comment to the Transfer() function.

@@ -16,20 +22,62 @@ var (
)

// MakeMessage handles making tx message
func MakeMessage(t string, payload interface{}) types.Tx {
func MakeMessage(t string, nonce uint32, payload interface{}, sign bool) (types.Tx, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Think about this situation: we got a key to sign a transaction, but we don't care how. we just got a key. then, we just need a function to make a formed or formatted message. one unit of a code does one thing: make something from the prepared ingredients. think about layers or hierarchy of functions.

- change functions' name to make their feature clear
- set 'sign' to default
- reconsider and restructure hierarchy of functions
   (remove dependecy between 'client' and 'cmd' functions)
@h0n9 h0n9 requested a review from Lbird March 11, 2019 10:21
@Lbird Lbird merged commit e44826b into master Mar 11, 2019
@h0n9 h0n9 deleted the feature/8_add_cli_commands_for_parce-related_data branch March 11, 2019 13:26
@h0n9 h0n9 mentioned this pull request Mar 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add cli commands for parcel-related data
2 participants