Skip to content

Commit

Permalink
fix(#237): Updated commands
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Dec 13, 2024
1 parent 380ce8a commit 29d5ceb
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
11 changes: 9 additions & 2 deletions x/cardchain/client/cli/tx_encounter_close.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ var _ = strconv.Itoa(0)

func CmdEncounterClose() *cobra.Command {
cmd := &cobra.Command{
Use: "encounter-close [encounter-id]",
Use: "encounter-close [encounter-id] [user] [won]",
Short: "Broadcast message EncounterClose",
Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argEncounterId, err := cast.ToUint64E(args[0])
if err != nil {
return err
}

argWon, err := cast.ToBoolE(args[2])
if err != nil {
return err
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
Expand All @@ -32,6 +37,8 @@ func CmdEncounterClose() *cobra.Command {
msg := types.NewMsgEncounterClose(
clientCtx.GetFromAddress().String(),
argEncounterId,
args[1],
argWon,
)
if err := msg.ValidateBasic(); err != nil {
return err
Expand Down
19 changes: 17 additions & 2 deletions x/cardchain/client/cli/tx_encounter_create.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"encoding/json"
"strconv"

"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
Expand All @@ -14,10 +15,21 @@ var _ = strconv.Itoa(0)

func CmdEncounterCreate() *cobra.Command {
cmd := &cobra.Command{
Use: "encounter-create",
Use: "encounter-create [drawlist] [parameters] [image]",
Short: "Broadcast message EncounterCreate",
Args: cobra.ExactArgs(0),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
var reqDrawlist []uint64
err = json.Unmarshal([]byte(args[0]), &reqDrawlist)
if err != nil {
return err
}

var reqParameters map[string]string
err = json.Unmarshal([]byte(args[1]), &reqParameters)
if err != nil {
return err
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -26,6 +38,9 @@ func CmdEncounterCreate() *cobra.Command {

msg := types.NewMsgEncounterCreate(
clientCtx.GetFromAddress().String(),
reqDrawlist,
reqParameters,
[]byte(args[1]),
)
if err := msg.ValidateBasic(); err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions x/cardchain/client/cli/tx_encounter_do.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ var _ = strconv.Itoa(0)

func CmdEncounterDo() *cobra.Command {
cmd := &cobra.Command{
Use: "encounter-do [encounter-id]",
Use: "encounter-do [encounter-id] [user]",
Short: "Broadcast message EncounterDo",
Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argEncounterId, err := cast.ToUint64E(args[0])
if err != nil {
Expand All @@ -32,6 +32,7 @@ func CmdEncounterDo() *cobra.Command {
msg := types.NewMsgEncounterDo(
clientCtx.GetFromAddress().String(),
argEncounterId,
args[1],
)
if err := msg.ValidateBasic(); err != nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion x/cardchain/types/message_encounter_close.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ const TypeMsgEncounterClose = "encounter_close"

var _ sdk.Msg = &MsgEncounterClose{}

func NewMsgEncounterClose(creator string, encounterId uint64) *MsgEncounterClose {
func NewMsgEncounterClose(creator string, encounterId uint64, user string, won bool) *MsgEncounterClose {
return &MsgEncounterClose{
Creator: creator,
EncounterId: encounterId,
User: user,
Won: won,
}
}

Expand Down
7 changes: 5 additions & 2 deletions x/cardchain/types/message_encounter_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ const TypeMsgEncounterCreate = "encounter_create"

var _ sdk.Msg = &MsgEncounterCreate{}

func NewMsgEncounterCreate(creator string) *MsgEncounterCreate {
func NewMsgEncounterCreate(creator string, drawlist []uint64, parameters map[string]string, image []byte) *MsgEncounterCreate {
return &MsgEncounterCreate{
Creator: creator,
Creator: creator,
Drawlist: drawlist,
Parameters: parameters,
Image: image,
}
}

Expand Down
3 changes: 2 additions & 1 deletion x/cardchain/types/message_encounter_do.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ const TypeMsgEncounterDo = "encounter_do"

var _ sdk.Msg = &MsgEncounterDo{}

func NewMsgEncounterDo(creator string, encounterId uint64) *MsgEncounterDo {
func NewMsgEncounterDo(creator string, encounterId uint64, user string) *MsgEncounterDo {
return &MsgEncounterDo{
Creator: creator,
EncounterId: encounterId,
User: user,
}
}

Expand Down

0 comments on commit 29d5ceb

Please sign in to comment.