Skip to content

Commit fb71ee0

Browse files
author
nashqueue
committed
update cli for commit solution and submit scavenge
1 parent a978009 commit fb71ee0

File tree

2 files changed

+50
-29
lines changed

2 files changed

+50
-29
lines changed

x/scavenge/client/cli/tx_commit_solution.go

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,56 @@
1+
// x/scavenge/client/cli/tx_commit_solution.go
2+
13
package cli
24

35
import (
4-
"strconv"
6+
"crypto/sha256"
7+
"encoding/hex"
58

69
"github.com/cosmos/cosmos-sdk/client"
710
"github.com/cosmos/cosmos-sdk/client/flags"
811
"github.com/cosmos/cosmos-sdk/client/tx"
912
"github.com/spf13/cobra"
13+
1014
"scavenge/x/scavenge/types"
1115
)
1216

13-
var _ = strconv.Itoa(0)
14-
1517
func CmdCommitSolution() *cobra.Command {
1618
cmd := &cobra.Command{
17-
Use: "commit-solution [solution-hash] [solution-scavenger-hash]",
19+
// pass a solution as the only argument
20+
Use: "commit-solution [solution]",
1821
Short: "Broadcast message commit-solution",
19-
Args: cobra.ExactArgs(2),
20-
RunE: func(cmd *cobra.Command, args []string) (err error) {
21-
argSolutionHash := args[0]
22-
argSolutionScavengerHash := args[1]
23-
22+
// set the number of arguments to 1
23+
Args: cobra.ExactArgs(1),
24+
RunE: func(cmd *cobra.Command, args []string) error {
2425
clientCtx, err := client.GetClientTxContext(cmd)
2526
if err != nil {
2627
return err
2728
}
2829

29-
msg := types.NewMsgCommitSolution(
30-
clientCtx.GetFromAddress().String(),
31-
argSolutionHash,
32-
argSolutionScavengerHash,
33-
)
30+
solution := args[0]
31+
32+
// find a hash of the solution
33+
solutionHash := sha256.Sum256([]byte(solution))
34+
35+
// convert the solution hash to string
36+
solutionHashString := hex.EncodeToString(solutionHash[:])
37+
38+
// convert a scavenger address to string
39+
var scavenger = clientCtx.GetFromAddress().String()
40+
41+
// find the hash of solution and scavenger address
42+
var solutionScavengerHash = sha256.Sum256([]byte(solution + scavenger))
43+
44+
// convert the hash to string
45+
var solutionScavengerHashString = hex.EncodeToString(solutionScavengerHash[:])
46+
47+
// create a new message
48+
msg := types.NewMsgCommitSolution(clientCtx.GetFromAddress().String(), string(solutionHashString), string(solutionScavengerHashString))
3449
if err := msg.ValidateBasic(); err != nil {
3550
return err
3651
}
52+
53+
// broadcast the transaction with the message to the blockchain
3754
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
3855
},
3956
}

x/scavenge/client/cli/tx_submit_scavenge.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
1+
// x/scavenge/client/cli/tx_submit_scavenge.go
2+
13
package cli
24

35
import (
4-
"strconv"
6+
"crypto/sha256"
7+
"encoding/hex"
58

69
"github.com/cosmos/cosmos-sdk/client"
710
"github.com/cosmos/cosmos-sdk/client/flags"
811
"github.com/cosmos/cosmos-sdk/client/tx"
912
"github.com/spf13/cobra"
13+
1014
"scavenge/x/scavenge/types"
1115
)
1216

13-
var _ = strconv.Itoa(0)
14-
1517
func CmdSubmitScavenge() *cobra.Command {
1618
cmd := &cobra.Command{
17-
Use: "submit-scavenge [solution-hash] [description] [reward]",
19+
Use: "submit-scavenge [solution] [description] [reward]",
1820
Short: "Broadcast message submit-scavenge",
1921
Args: cobra.ExactArgs(3),
20-
RunE: func(cmd *cobra.Command, args []string) (err error) {
21-
argSolutionHash := args[0]
22-
argDescription := args[1]
23-
argReward := args[2]
24-
22+
RunE: func(cmd *cobra.Command, args []string) error {
2523
clientCtx, err := client.GetClientTxContext(cmd)
2624
if err != nil {
2725
return err
2826
}
2927

30-
msg := types.NewMsgSubmitScavenge(
31-
clientCtx.GetFromAddress().String(),
32-
argSolutionHash,
33-
argDescription,
34-
argReward,
35-
)
28+
// find a hash of the solution
29+
solutionHash := sha256.Sum256([]byte(args[0]))
30+
31+
// convert the hash to string
32+
solutionHashString := hex.EncodeToString(solutionHash[:])
33+
argsDescription := string(args[1])
34+
argsReward := string(args[2])
35+
36+
// create a new message
37+
msg := types.NewMsgSubmitScavenge(clientCtx.GetFromAddress().String(), string(solutionHashString), string(argsDescription), string(argsReward))
3638
if err := msg.ValidateBasic(); err != nil {
3739
return err
3840
}
41+
42+
// broadcast the transaction with the message to the blockchain
3943
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
4044
},
4145
}

0 commit comments

Comments
 (0)