From 545d6c59637109eb7b5e4a45709fe65174aa548c Mon Sep 17 00:00:00 2001 From: kevinh2810 Date: Fri, 20 Mar 2020 18:22:41 +0800 Subject: [PATCH 1/5] adding function for HD wallet testing --- cmd/transaction/cmd.go | 90 ++++++++++++++++++++++++++++++++++++ cmd/transaction/const.go | 3 ++ cmd/transaction/generator.go | 81 ++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+) diff --git a/cmd/transaction/cmd.go b/cmd/transaction/cmd.go index 26bfbc0f5..bde2e8800 100644 --- a/cmd/transaction/cmd.go +++ b/cmd/transaction/cmd.go @@ -62,6 +62,18 @@ var ( Long: "transaction sub command used to generate 'multi signature' transaction that require multiple account to submit their signature " + "before it is valid to be executed", } + registerNodeCmdHDwallet = &cobra.Command{ + Use: "register-node", + Short: "send-money command used to generate \"send money\" transaction based on HD Wallet", + } + updateNodeCmdHDwallet = &cobra.Command{ + Use: "update-node", + Short: "update-node command used to generate \"update node\" transaction based on HD Wallet", + } + removeNodeCmdHDwallet = &cobra.Command{ + Use: "remove-node", + Short: "remove-node command used to generate \"remove node\" transaction based on HD Wallet", + } ) func init() { @@ -179,6 +191,12 @@ func Commands(sqliteDB *sql.DB) *cobra.Command { txCmd.AddCommand(escrowApprovalCmd) multiSigCmd.Run = txGeneratorCommandsInstance.MultiSignatureProcess() txCmd.AddCommand(multiSigCmd) + registerNodeCmdHDwallet.Run = txGeneratorCommandsInstance.RegisterNodeProcessHDwallet() + txCmd.AddCommand(registerNodeCmdHDwallet) + updateNodeCmdHDwallet.Run = txGeneratorCommandsInstance.UpdateNodeProcessHDwallet() + txCmd.AddCommand(updateNodeCmdHDwallet) + removeNodeCmdHDwallet.Run = txGeneratorCommandsInstance.RemoveNodeProcessHDwallet() + txCmd.AddCommand(removeNodeCmdHDwallet) return txCmd } @@ -373,3 +391,75 @@ func (*TXGeneratorCommands) MultiSignatureProcess() RunCommand { } } } + +// RegisterNodeProcess for generate TX RegisterNode type +func (txg *TXGeneratorCommands) RegisterNodeProcessHDwallet() RunCommand { + return func(ccmd *cobra.Command, args []string) { + tx := GenerateBasicTransaction( + senderSeed, + senderSignatureType, + version, + timestamp, + fee, + recipientAccountAddress, + ) + tx = GenerateTxRegisterNodeHDwallet( + tx, + recipientAccountAddress, + nodeAddress, + lockedBalance, + poowMessageByte, + signatureByte, + nodePubKey, + ) + if escrow { + tx = GenerateEscrowedTransaction(tx) + } + PrintTx(GenerateSignedTxBytes(tx, senderSeed, senderSignatureType), outputType) + } +} + +// GenerateTxUpdateNodeHDwallet for generate TX UpdateNode type +func (txg *TXGeneratorCommands) UpdateNodeProcessHDwallet() RunCommand { + return func(ccmd *cobra.Command, args []string) { + tx := GenerateBasicTransaction( + senderSeed, + senderSignatureType, + version, + timestamp, + fee, + recipientAccountAddress, + ) + tx = GenerateTxUpdateNodeHDwallet( + tx, + nodeAddress, + lockedBalance, + poowMessageByte, + signatureByte, + nodePubKey, + ) + if escrow { + tx = GenerateEscrowedTransaction(tx) + } + PrintTx(GenerateSignedTxBytes(tx, senderSeed, senderSignatureType), outputType) + } +} + +// GenerateTxRemoveNodeHDwallet for generate TX RemoveNode type +func (*TXGeneratorCommands) RemoveNodeProcessHDwallet() RunCommand { + return func(ccmd *cobra.Command, args []string) { + tx := GenerateBasicTransaction( + senderSeed, + senderSignatureType, + version, + timestamp, + fee, + recipientAccountAddress, + ) + tx = GenerateTxRemoveNodeHDwallet(tx, nodePubKey) + if escrow { + tx = GenerateEscrowedTransaction(tx) + } + PrintTx(GenerateSignedTxBytes(tx, senderSeed, senderSignatureType), outputType) + } +} diff --git a/cmd/transaction/const.go b/cmd/transaction/const.go index dff3003ca..9787f26bb 100644 --- a/cmd/transaction/const.go +++ b/cmd/transaction/const.go @@ -38,6 +38,9 @@ var ( nodeOwnerAccountAddress string nodeAddress string lockedBalance int64 + poowMessageByte []byte + signatureByte []byte + nodePubKey []byte // dataset transaction property string diff --git a/cmd/transaction/generator.go b/cmd/transaction/generator.go index 80d31b42b..7e15c509b 100644 --- a/cmd/transaction/generator.go +++ b/cmd/transaction/generator.go @@ -467,3 +467,84 @@ func GeneratedMultiSignatureTransaction( tx.TransactionBodyLength = uint32(len(tx.TransactionBodyBytes)) return tx } + +func GenerateTxRegisterNodeHDwallet( + tx *model.Transaction, + recipientAccountAddress, nodeAddress string, + lockedBalance int64, + poownMessageBytes, signature, nodePubKey []byte, +) *model.Transaction { + txBody := &model.NodeRegistrationTransactionBody{ + NodePublicKey: nodePubKey, + NodeAddress: &model.NodeAddress{ + Address: nodeAddress, + }, + LockedBalance: lockedBalance, + Poown: &model.ProofOfOwnership{ + MessageBytes: poownMessageBytes, + Signature: signature, + }, + } + txBodyBytes := (&transaction.NodeRegistration{ + Body: txBody, + NodeRegistrationQuery: query.NewNodeRegistrationQuery(), + }).GetBodyBytes() + + tx.TransactionType = util.ConvertBytesToUint32(txTypeMap["registerNode"]) + tx.TransactionBody = &model.Transaction_NodeRegistrationTransactionBody{ + NodeRegistrationTransactionBody: txBody, + } + tx.TransactionBodyBytes = txBodyBytes + tx.TransactionBodyLength = uint32(len(txBodyBytes)) + + return tx +} + +func GenerateTxUpdateNodeHDwallet( + tx *model.Transaction, + nodeAddress string, + lockedBalance int64, + poowMessageBytes, signature, nodePubKey []byte, +) *model.Transaction { + txBody := &model.UpdateNodeRegistrationTransactionBody{ + NodePublicKey: nodePubKey, + NodeAddress: &model.NodeAddress{ + Address: nodeAddress, + }, + LockedBalance: lockedBalance, + Poown: &model.ProofOfOwnership{ + MessageBytes: poowMessageBytes, + Signature: signature, + }, + } + txBodyBytes := (&transaction.UpdateNodeRegistration{ + Body: txBody, + NodeRegistrationQuery: query.NewNodeRegistrationQuery(), + }).GetBodyBytes() + + tx.TransactionBodyLength = uint32(len(txBodyBytes)) + tx.TransactionType = util.ConvertBytesToUint32(txTypeMap["updateNodeRegistration"]) + tx.TransactionBody = &model.Transaction_UpdateNodeRegistrationTransactionBody{ + UpdateNodeRegistrationTransactionBody: txBody, + } + tx.TransactionBodyBytes = txBodyBytes + return tx +} + +func GenerateTxRemoveNodeHDwallet(tx *model.Transaction, nodePubKey []byte) *model.Transaction { + txBody := &model.RemoveNodeRegistrationTransactionBody{ + NodePublicKey: nodePubKey, + } + txBodyBytes := (&transaction.RemoveNodeRegistration{ + Body: txBody, + NodeRegistrationQuery: query.NewNodeRegistrationQuery(), + }).GetBodyBytes() + + tx.TransactionType = util.ConvertBytesToUint32(txTypeMap["removeNodeRegistration"]) + tx.TransactionBody = &model.Transaction_RemoveNodeRegistrationTransactionBody{ + RemoveNodeRegistrationTransactionBody: txBody, + } + tx.TransactionBodyBytes = txBodyBytes + tx.TransactionBodyLength = uint32(len(txBodyBytes)) + return tx +} From 0cf199702f80d2cc41c89c3f77c3eeb77d90ab7d Mon Sep 17 00:00:00 2001 From: kevinh2810 Date: Mon, 30 Mar 2020 08:54:07 +0700 Subject: [PATCH 2/5] pull schema --- cmd/transaction/const.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/cmd/transaction/const.go b/cmd/transaction/const.go index d9ad72dca..31fee2798 100644 --- a/cmd/transaction/const.go +++ b/cmd/transaction/const.go @@ -38,15 +38,12 @@ var ( nodeOwnerAccountAddress string nodeAddress string lockedBalance int64 -<<<<<<< HEAD poowMessageByte []byte signatureByte []byte nodePubKey []byte -======= proofOfOwnershipHex string databasePath string databaseName string ->>>>>>> 4f354ef2df93b708fe5ccd791c50300b6b633bed // dataset transaction property string From 8a2301850feaa65be30b4e38a3991fe7b043b6a8 Mon Sep 17 00:00:00 2001 From: kevinh2810 Date: Mon, 30 Mar 2020 09:34:28 +0700 Subject: [PATCH 3/5] pull newest schema --- common/schema | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/schema b/common/schema index 201d583c8..19e27af04 160000 --- a/common/schema +++ b/common/schema @@ -1 +1 @@ -Subproject commit 201d583c8643a00510336de8480e2977c36575e6 +Subproject commit 19e27af04d19e3796614a13e985c66cdad7cddd9 From c89390baa80f65a76628c494c37b3b3fabc25452 Mon Sep 17 00:00:00 2001 From: kevinh2810 Date: Mon, 30 Mar 2020 12:14:45 +0700 Subject: [PATCH 4/5] removing unused command for hd wallet --- cmd/transaction/cmd.go | 90 ---------------------------------------- cmd/transaction/const.go | 1 + 2 files changed, 1 insertion(+), 90 deletions(-) diff --git a/cmd/transaction/cmd.go b/cmd/transaction/cmd.go index 67e9ab15c..048017d1f 100644 --- a/cmd/transaction/cmd.go +++ b/cmd/transaction/cmd.go @@ -61,18 +61,6 @@ var ( Long: "transaction sub command used to generate 'multi signature' transaction that require multiple account to submit their signature " + "before it is valid to be executed", } - registerNodeCmdHDwallet = &cobra.Command{ - Use: "register-node", - Short: "send-money command used to generate \"send money\" transaction based on HD Wallet", - } - updateNodeCmdHDwallet = &cobra.Command{ - Use: "update-node", - Short: "update-node command used to generate \"update node\" transaction based on HD Wallet", - } - removeNodeCmdHDwallet = &cobra.Command{ - Use: "remove-node", - Short: "remove-node command used to generate \"remove node\" transaction based on HD Wallet", - } ) func init() { @@ -208,12 +196,6 @@ func Commands() *cobra.Command { txCmd.AddCommand(escrowApprovalCmd) multiSigCmd.Run = txGeneratorCommandsInstance.MultiSignatureProcess() txCmd.AddCommand(multiSigCmd) - registerNodeCmdHDwallet.Run = txGeneratorCommandsInstance.RegisterNodeProcessHDwallet() - txCmd.AddCommand(registerNodeCmdHDwallet) - updateNodeCmdHDwallet.Run = txGeneratorCommandsInstance.UpdateNodeProcessHDwallet() - txCmd.AddCommand(updateNodeCmdHDwallet) - removeNodeCmdHDwallet.Run = txGeneratorCommandsInstance.RemoveNodeProcessHDwallet() - txCmd.AddCommand(removeNodeCmdHDwallet) return txCmd } @@ -441,75 +423,3 @@ func (*TXGeneratorCommands) MultiSignatureProcess() RunCommand { } } } - -// RegisterNodeProcess for generate TX RegisterNode type -func (txg *TXGeneratorCommands) RegisterNodeProcessHDwallet() RunCommand { - return func(ccmd *cobra.Command, args []string) { - tx := GenerateBasicTransaction( - senderSeed, - senderSignatureType, - version, - timestamp, - fee, - recipientAccountAddress, - ) - tx = GenerateTxRegisterNodeHDwallet( - tx, - recipientAccountAddress, - nodeAddress, - lockedBalance, - poowMessageByte, - signatureByte, - nodePubKey, - ) - if escrow { - tx = GenerateEscrowedTransaction(tx) - } - PrintTx(GenerateSignedTxBytes(tx, senderSeed, senderSignatureType), outputType) - } -} - -// GenerateTxUpdateNodeHDwallet for generate TX UpdateNode type -func (txg *TXGeneratorCommands) UpdateNodeProcessHDwallet() RunCommand { - return func(ccmd *cobra.Command, args []string) { - tx := GenerateBasicTransaction( - senderSeed, - senderSignatureType, - version, - timestamp, - fee, - recipientAccountAddress, - ) - tx = GenerateTxUpdateNodeHDwallet( - tx, - nodeAddress, - lockedBalance, - poowMessageByte, - signatureByte, - nodePubKey, - ) - if escrow { - tx = GenerateEscrowedTransaction(tx) - } - PrintTx(GenerateSignedTxBytes(tx, senderSeed, senderSignatureType), outputType) - } -} - -// GenerateTxRemoveNodeHDwallet for generate TX RemoveNode type -func (*TXGeneratorCommands) RemoveNodeProcessHDwallet() RunCommand { - return func(ccmd *cobra.Command, args []string) { - tx := GenerateBasicTransaction( - senderSeed, - senderSignatureType, - version, - timestamp, - fee, - recipientAccountAddress, - ) - tx = GenerateTxRemoveNodeHDwallet(tx, nodePubKey) - if escrow { - tx = GenerateEscrowedTransaction(tx) - } - PrintTx(GenerateSignedTxBytes(tx, senderSeed, senderSignatureType), outputType) - } -} diff --git a/cmd/transaction/const.go b/cmd/transaction/const.go index 31fee2798..c92028154 100644 --- a/cmd/transaction/const.go +++ b/cmd/transaction/const.go @@ -44,6 +44,7 @@ var ( proofOfOwnershipHex string databasePath string databaseName string + hdwalletflag string // dataset transaction property string From 854385cded3bcd9b35b8e0fc93f7f3a562b75595 Mon Sep 17 00:00:00 2001 From: kevinh2810 Date: Mon, 30 Mar 2020 12:43:26 +0700 Subject: [PATCH 5/5] cleaning some unused variables --- cmd/transaction/const.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/transaction/const.go b/cmd/transaction/const.go index c92028154..31fee2798 100644 --- a/cmd/transaction/const.go +++ b/cmd/transaction/const.go @@ -44,7 +44,6 @@ var ( proofOfOwnershipHex string databasePath string databaseName string - hdwalletflag string // dataset transaction property string