Skip to content

Commit

Permalink
Improved usability
Browse files Browse the repository at this point in the history
- Added the features for signtx and verifytx to read transactions from a file.
  • Loading branch information
hayarobi committed Feb 7, 2024
1 parent 316af77 commit cc53115
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions cmd/aergocli/cmd/signtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import (
func init() {
rootCmd.AddCommand(signCmd)
signCmd.Flags().StringVar(&jsonTx, "jsontx", "", "transaction json to sign")
signCmd.Flags().StringVar(&jsonPath, "jsontxpath", "", "transaction json file path to sign")
signCmd.Flags().StringVar(&address, "address", "1", "address of account to use for signing")
signCmd.Flags().StringVar(&pw, "password", "", "local account password")
signCmd.Flags().StringVar(&privKey, "key", "", "base58 encoded key for sign")
rootCmd.AddCommand(verifyCmd)
verifyCmd.Flags().StringVar(&jsonTx, "jsontx", "", "transaction list json to verify")
verifyCmd.Flags().StringVar(&jsonPath, "jsontxpath", "", "transaction json file path to verify")
verifyCmd.Flags().BoolVar(&remote, "remote", false, "verify in the node")
}

Expand All @@ -32,10 +34,18 @@ var signCmd = &cobra.Command{
PreRun: preConnectAergo,
Run: func(cmd *cobra.Command, args []string) {
var err error
if jsonTx == "" {
if jsonTx == "" && jsonPath == "" {
cmd.Printf("need to transaction json input")
return
}
if jsonTx == "" {
b, readerr := os.ReadFile(jsonPath)
if readerr != nil {
cmd.Printf("Failed to read --jsontxpath\n" + readerr.Error())
return
}
jsonTx = string(b)
}
param, err := jsonrpc.ParseBase58TxBody([]byte(jsonTx))
if err != nil {
cmd.Printf("Failed: %s\n", err.Error())
Expand Down Expand Up @@ -102,10 +112,19 @@ var verifyCmd = &cobra.Command{
Short: "Verify transaction",
PreRun: preConnectAergo,
Run: func(cmd *cobra.Command, args []string) {
if jsonTx == "" {
if jsonTx == "" && jsonPath == "" {
cmd.Printf("need to transaction json input")
return
}
if jsonTx == "" {
b, readerr := os.ReadFile(jsonPath)
if readerr != nil {
cmd.Printf("Failed to read --jsontxpath\n" + readerr.Error())
return
}
jsonTx = string(b)
}

param, err := jsonrpc.ParseBase58Tx([]byte(jsonTx))
if err != nil {
cmd.Printf("Failed: %s\n", err.Error())
Expand Down

0 comments on commit cc53115

Please sign in to comment.