Skip to content

Commit

Permalink
Merge 6198691 into fe34493
Browse files Browse the repository at this point in the history
  • Loading branch information
ebruck authored Mar 16, 2020
2 parents fe34493 + 6198691 commit 50febd6
Show file tree
Hide file tree
Showing 19 changed files with 646 additions and 357 deletions.
8 changes: 4 additions & 4 deletions x/crud/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ var (
type (
Keeper = keeper.Keeper
MaxKeeperSizes = keeper.MaxKeeperSizes
MsgBLZCreate = types.MsgBLZCreate
MsgBLZRead = types.MsgBLZRead
MsgBLZUpdate = types.MsgBLZUpdate
MsgBLZDelete = types.MsgBLZDelete
MsgCreate = types.MsgCreate
MsgRead = types.MsgRead
MsgUpdate = types.MsgUpdate
MsgDelete = types.MsgDelete
QueryResultRead = types.QueryResultRead
QueryResultHas = types.QueryResultHas
)
20 changes: 10 additions & 10 deletions x/crud/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ func GetQueryCmd(storeKey string, cdc *codec.Codec) *cobra.Command {
}

crudQueryCmd.AddCommand(flags.GetCommands(
GetCmdBLZQRead(storeKey, cdc),
GetCmdBLZQHas(storeKey, cdc),
GetCmdBLZQKeys(storeKey, cdc),
GetCmdBLZQKeyValues(storeKey, cdc),
GetCmdBLZQCount(storeKey, cdc),
GetCmdQRead(storeKey, cdc),
GetCmdQHas(storeKey, cdc),
GetCmdQKeys(storeKey, cdc),
GetCmdQKeyValues(storeKey, cdc),
GetCmdQCount(storeKey, cdc),
)...)

return crudQueryCmd
}

func GetCmdBLZQRead(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQRead(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "read [UUID] [key]",
Short: "read UUID key",
Expand All @@ -66,7 +66,7 @@ func GetCmdBLZQRead(queryRoute string, cdc *codec.Codec) *cobra.Command {
}
}

func GetCmdBLZQHas(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQHas(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "has [UUID] [key]",
Short: "has UUID key",
Expand All @@ -84,7 +84,7 @@ func GetCmdBLZQHas(queryRoute string, cdc *codec.Codec) *cobra.Command {
}
}

func GetCmdBLZQKeys(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQKeys(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "keys [UUID]",
Short: "keys UUID",
Expand All @@ -107,7 +107,7 @@ func GetCmdBLZQKeys(queryRoute string, cdc *codec.Codec) *cobra.Command {
}
}

func GetCmdBLZQKeyValues(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQKeyValues(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "keyvalues [UUID]",
Short: "keyvalues UUID",
Expand All @@ -130,7 +130,7 @@ func GetCmdBLZQKeyValues(queryRoute string, cdc *codec.Codec) *cobra.Command {
}
}

func GetCmdBLZQCount(queryRoute string, cdc *codec.Codec) *cobra.Command {
func GetCmdQCount(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "count [UUID]",
Short: "count UUID",
Expand Down
87 changes: 61 additions & 26 deletions x/crud/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/spf13/cobra"
Expand All @@ -36,22 +37,23 @@ func GetTxCmd(_ string, cdc *codec.Codec) *cobra.Command {
RunE: client.ValidateCmd,
}
crudTxCmd.AddCommand(flags.PostCommands(
GetCmdBLZCreate(cdc),
GetCmdBLZRead(cdc),
GetCmdBLZUpdate(cdc),
GetCmdBLZDelete(cdc),
GetCmdBLZKeys(cdc),
GetCmdBLZHas(cdc),
GetCmdBLZRename(cdc),
GetCmdBLZKeyValues(cdc),
GetCmdBLZCount(cdc),
GetCmdCreate(cdc),
GetCmdRead(cdc),
GetCmdUpdate(cdc),
GetCmdDelete(cdc),
GetCmdKeys(cdc),
GetCmdHas(cdc),
GetCmdRename(cdc),
GetCmdKeyValues(cdc),
GetCmdCount(cdc),
GetCmdDeleteAll(cdc),
GetCmdMultiUpdate(cdc),
)...)

return crudTxCmd
}

func GetCmdBLZCreate(cdc *codec.Codec) *cobra.Command {
func GetCmdCreate(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "create [UUID] [key] [value]",
Short: "create a new entry in the database",
Expand All @@ -61,7 +63,7 @@ func GetCmdBLZCreate(cdc *codec.Codec) *cobra.Command {
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))

msg := types.NewMsgBLZCreate(args[0], args[1], args[2], cliCtx.GetFromAddress())
msg := types.NewMsgCreate(args[0], args[1], args[2], cliCtx.GetFromAddress())

err := msg.ValidateBasic()
if err != nil {
Expand All @@ -73,7 +75,7 @@ func GetCmdBLZCreate(cdc *codec.Codec) *cobra.Command {
}
}

func GetCmdBLZRead(cdc *codec.Codec) *cobra.Command {
func GetCmdRead(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "read [UUID] [key]",
Short: "read an existing entry in the database",
Expand All @@ -82,7 +84,7 @@ func GetCmdBLZRead(cdc *codec.Codec) *cobra.Command {
cliCtx := context.NewCLIContext().WithCodec(cdc)
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
msg := types.NewMsgBLZRead(args[0], args[1], cliCtx.GetFromAddress())
msg := types.NewMsgRead(args[0], args[1], cliCtx.GetFromAddress())

err := msg.ValidateBasic()
if err != nil {
Expand All @@ -94,7 +96,7 @@ func GetCmdBLZRead(cdc *codec.Codec) *cobra.Command {
}
}

func GetCmdBLZUpdate(cdc *codec.Codec) *cobra.Command {
func GetCmdUpdate(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "update [UUID] [key] [value]",
Short: "update an existing entry in the database",
Expand All @@ -103,7 +105,7 @@ func GetCmdBLZUpdate(cdc *codec.Codec) *cobra.Command {
cliCtx := context.NewCLIContext().WithCodec(cdc)
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
msg := types.NewMsgBLZUpdate(args[0], args[1], args[2], cliCtx.GetFromAddress())
msg := types.NewMsgUpdate(args[0], args[1], args[2], cliCtx.GetFromAddress())

err := msg.ValidateBasic()
if err != nil {
Expand All @@ -115,7 +117,7 @@ func GetCmdBLZUpdate(cdc *codec.Codec) *cobra.Command {
}
}

func GetCmdBLZDelete(cdc *codec.Codec) *cobra.Command {
func GetCmdDelete(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "delete [UUID] [key]",
Short: "delete an existing entry in the database",
Expand All @@ -124,7 +126,7 @@ func GetCmdBLZDelete(cdc *codec.Codec) *cobra.Command {
cliCtx := context.NewCLIContext().WithCodec(cdc)
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
msg := types.NewMsgBLZDelete(args[0], args[1], cliCtx.GetFromAddress())
msg := types.NewMsgDelete(args[0], args[1], cliCtx.GetFromAddress())

err := msg.ValidateBasic()
if err != nil {
Expand All @@ -136,7 +138,7 @@ func GetCmdBLZDelete(cdc *codec.Codec) *cobra.Command {
}
}

func GetCmdBLZKeys(cdc *codec.Codec) *cobra.Command {
func GetCmdKeys(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "keys [UUID]",
Short: "list keys for a UUID in the database",
Expand All @@ -145,7 +147,7 @@ func GetCmdBLZKeys(cdc *codec.Codec) *cobra.Command {
cliCtx := context.NewCLIContext().WithCodec(cdc)
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
msg := types.NewMsgBLZKeys(args[0], cliCtx.GetFromAddress())
msg := types.NewMsgKeys(args[0], cliCtx.GetFromAddress())

err := msg.ValidateBasic()
if err != nil {
Expand All @@ -157,7 +159,7 @@ func GetCmdBLZKeys(cdc *codec.Codec) *cobra.Command {
}
}

func GetCmdBLZKeyValues(cdc *codec.Codec) *cobra.Command {
func GetCmdKeyValues(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "keyvalues [UUID]",
Short: "list keys/values for a UUID in the database",
Expand All @@ -166,7 +168,7 @@ func GetCmdBLZKeyValues(cdc *codec.Codec) *cobra.Command {
cliCtx := context.NewCLIContext().WithCodec(cdc)
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
msg := types.NewMsgBLZKeyValues(args[0], cliCtx.GetFromAddress())
msg := types.NewMsgKeyValues(args[0], cliCtx.GetFromAddress())

err := msg.ValidateBasic()
if err != nil {
Expand All @@ -178,7 +180,7 @@ func GetCmdBLZKeyValues(cdc *codec.Codec) *cobra.Command {
}
}

func GetCmdBLZHas(cdc *codec.Codec) *cobra.Command {
func GetCmdHas(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "has [UUID] [key]",
Short: "returns true if the key value pair exists",
Expand All @@ -187,7 +189,7 @@ func GetCmdBLZHas(cdc *codec.Codec) *cobra.Command {
cliCtx := context.NewCLIContext().WithCodec(cdc)
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
msg := types.NewMsgBLZHas(args[0], args[1], cliCtx.GetFromAddress())
msg := types.NewMsgHas(args[0], args[1], cliCtx.GetFromAddress())

err := msg.ValidateBasic()
if err != nil {
Expand All @@ -199,7 +201,7 @@ func GetCmdBLZHas(cdc *codec.Codec) *cobra.Command {
}
}

func GetCmdBLZRename(cdc *codec.Codec) *cobra.Command {
func GetCmdRename(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "rename [UUID] [key] [new key]",
Short: "rename an existing entry in the database",
Expand All @@ -208,7 +210,7 @@ func GetCmdBLZRename(cdc *codec.Codec) *cobra.Command {
cliCtx := context.NewCLIContext().WithCodec(cdc)
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))
msg := types.NewMsgBLZRename(args[0], args[1], args[2], cliCtx.GetFromAddress())
msg := types.NewMsgRename(args[0], args[1], args[2], cliCtx.GetFromAddress())

err := msg.ValidateBasic()
if err != nil {
Expand All @@ -220,7 +222,7 @@ func GetCmdBLZRename(cdc *codec.Codec) *cobra.Command {
}
}

func GetCmdBLZCount(cdc *codec.Codec) *cobra.Command {
func GetCmdCount(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "count [UUID]",
Short: "count of existing entries in the database",
Expand Down Expand Up @@ -261,3 +263,36 @@ func GetCmdDeleteAll(cdc *codec.Codec) *cobra.Command {
},
}
}

func GetCmdMultiUpdate(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "multiupdate [UUID] [key] [value] <key> <value> ...",
Short: "update existing entries in the database",
Args: cobra.MinimumNArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
inBuf := bufio.NewReader(cmd.InOrStdin())
txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc))

// after uuid there should be an even number of k/v pairs...
argsLen := len(args) - 1

if (argsLen % 2) == 0 {
msg := types.NewMsgMultiUpdate(args[0], cliCtx.GetFromAddress(), nil)

for i := 1; i < argsLen; i += 2 {
msg.KeyValues = append(msg.KeyValues, types.KeyValue{Key: args[i], Value: args[i+1]})
}

err := msg.ValidateBasic()
if err != nil {
return err
}

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
}

return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "incorrect number of k/v arguments")
},
}
}
1 change: 1 addition & 0 deletions x/crud/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, storeName string)
r.HandleFunc(fmt.Sprintf("/%s/count/{UUID}", storeName), BlzQCountHandler(cliCtx, storeName)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/deleteall", storeName), BlzDeleteAllHandler(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/version", storeName), BlzQVersionHandler(cliCtx, storeName)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/multiupdate", storeName), BlzMultiUpdateHandler(cliCtx)).Methods("POST")
}
Loading

0 comments on commit 50febd6

Please sign in to comment.