-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from DecentralCardGame/134-add-route-for-chan…
…ging-collection-name Added MsgSetCollectionName and improved error handling
- Loading branch information
Showing
19 changed files
with
830 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cli | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/DecentralCardGame/Cardchain/x/cardchain/types" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/spf13/cast" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var _ = strconv.Itoa(0) | ||
|
||
func CmdSetCollectionName() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "set-collection-name [collection-id] [name]", | ||
Short: "Broadcast message SetCollectionName", | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
argCollectionId, err := cast.ToUint64E(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
argName := args[1] | ||
|
||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgSetCollectionName( | ||
clientCtx.GetFromAddress().String(), | ||
argCollectionId, | ||
argName, | ||
) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/DecentralCardGame/Cardchain/x/cardchain/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func (k msgServer) SetCollectionName(goCtx context.Context, msg *types.MsgSetCollectionName) (*types.MsgSetCollectionNameResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
collection := k.Collections.Get(ctx, msg.CollectionId) | ||
err := checkCollectionEditable(collection, msg.Creator) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
collection.Name = msg.Name | ||
|
||
k.Collections.Set(ctx, msg.CollectionId, collection) | ||
|
||
return &types.MsgSetCollectionNameResponse{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package simulation | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/DecentralCardGame/Cardchain/x/cardchain/keeper" | ||
"github.com/DecentralCardGame/Cardchain/x/cardchain/types" | ||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
) | ||
|
||
func SimulateMsgSetCollectionName( | ||
ak types.AccountKeeper, | ||
bk types.BankKeeper, | ||
k keeper.Keeper, | ||
) simtypes.Operation { | ||
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, | ||
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { | ||
simAccount, _ := simtypes.RandomAcc(r, accs) | ||
msg := &types.MsgSetCollectionName{ | ||
Creator: simAccount.Address.String(), | ||
} | ||
|
||
// TODO: Handling the SetCollectionName simulation | ||
|
||
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "SetCollectionName simulation not implemented"), nil, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.