Skip to content

Commit

Permalink
Merge pull request #279 from comdex-official/refactor-code
Browse files Browse the repository at this point in the history
refactor token mint module
  • Loading branch information
dheerajkd30 authored Jun 22, 2022
2 parents 4bae1b3 + 7095075 commit 2f1833d
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 192 deletions.
25 changes: 10 additions & 15 deletions x/tokenmint/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ package cli

import (
"fmt"
// "strings"
"strconv"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
// sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/comdex-official/comdex/x/tokenmint/types"
)

// GetQueryCmd returns the cli query commands for this module
// GetQueryCmd returns the cli query commands for this module.
func GetQueryCmd() *cobra.Command {
// Group tokenmint queries under a subcommand
cmd := &cobra.Command{
Expand All @@ -35,14 +33,13 @@ func GetQueryCmd() *cobra.Command {
return cmd
}

// QueryAllTokenMintedForAllProducts Queries the total token minted for all the apps on comdex
// QueryAllTokenMintedForAllProducts Queries the total token minted for all the apps on comdex.
func QueryAllTokenMintedForAllProducts() *cobra.Command {
cmd := &cobra.Command{
Use: "total-token-minted-all-products",
Short: "Token minted tokens data",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {

pagination, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
Expand Down Expand Up @@ -70,14 +67,13 @@ func QueryAllTokenMintedForAllProducts() *cobra.Command {
return cmd
}

// QueryTokenMintedByProduct queries token minted per application/product
// QueryTokenMintedByProduct queries token minted per application/product.
func QueryTokenMintedByProduct() *cobra.Command {
cmd := &cobra.Command{
Use: "token-minted-by-product [app_id]",
Short: "Token minted by product",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {

pagination, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
Expand All @@ -87,15 +83,15 @@ func QueryTokenMintedByProduct() *cobra.Command {
if err != nil {
return err
}
appId, err := strconv.ParseUint(args[0], 10, 64)
appID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

queryClient := types.NewQueryClient(ctx)

res, err := queryClient.QueryTokenMintedByProduct(cmd.Context(), &types.QueryTokenMintedByProductRequest{
AppId: appId,
AppId: appID,
Pagination: pagination,
})

Expand All @@ -110,14 +106,13 @@ func QueryTokenMintedByProduct() *cobra.Command {
return cmd
}

// QueryTokenMintedByProductAndAsset queries token minted for an application/product and asset
// QueryTokenMintedByProductAndAsset queries token minted for an application/product and asset.
func QueryTokenMintedByProductAndAsset() *cobra.Command {
cmd := &cobra.Command{
Use: "token-minted-by-product-asset [app_id] [asset_id]",
Short: "Token minted by product and asset data",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {

pagination, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
Expand All @@ -127,20 +122,20 @@ func QueryTokenMintedByProductAndAsset() *cobra.Command {
if err != nil {
return err
}
appId, err := strconv.ParseUint(args[0], 10, 64)
appID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}
assetId, err := strconv.ParseUint(args[1], 10, 64)
assetID, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return err
}

queryClient := types.NewQueryClient(ctx)

res, err := queryClient.QueryTokenMintedByProductAndAsset(cmd.Context(), &types.QueryTokenMintedByProductAndAssetRequest{
AppId: appId,
AssetId: assetId,
AppId: appID,
AssetId: assetID,
Pagination: pagination,
})

Expand Down
33 changes: 0 additions & 33 deletions x/tokenmint/client/cli/query_params.go
Original file line number Diff line number Diff line change
@@ -1,34 +1 @@
package cli

// import (
// "context"

// "github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/flags"
// "github.com/spf13/cobra"
// "github.com/comdex-official/comdex/x/tokenmint/types"
// )

// func CmdQueryParams() *cobra.Command {
// cmd := &cobra.Command{
// Use: "params",
// Short: "shows the parameters of the module",
// Args: cobra.NoArgs,
// RunE: func(cmd *cobra.Command, args []string) error {
// clientCtx := client.GetClientContextFromCmd(cmd)

// queryClient := types.NewQueryServiceClient(clientCtx)

// res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{})
// if err != nil {
// return err
// }

// return clientCtx.PrintProto(res)
// },
// }

// flags.AddQueryFlagsToCmd(cmd)

// return cmd
// }
24 changes: 11 additions & 13 deletions x/tokenmint/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ import (
"github.com/comdex-official/comdex/x/tokenmint/types"
)

const (
flagPacketTimeoutTimestamp = "packet-timeout-timestamp"
listSeparator = ","
)

// GetTxCmd returns the transaction commands for this module
// GetTxCmd returns the transaction commands for this module.
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: types.ModuleName,
Expand All @@ -34,7 +29,7 @@ func GetTxCmd() *cobra.Command {
return cmd
}

// Token mint txs cmd
// Token mint txs cmd.
func txMint() *cobra.Command {
cmd := &cobra.Command{
Use: "tokenmint [app_ID] [asset_id]",
Expand All @@ -45,18 +40,21 @@ func txMint() *cobra.Command {
if err != nil {
return err
}
appId, err := sdk.ParseUint(args[0])
appID := appId.Uint64()
appID, err := sdk.ParseUint(args[0])

assetId, err := sdk.ParseUint(args[1])
if err != nil {
return err
}
assetID, err := sdk.ParseUint(args[1])

msg := types.NewMsgMintNewTokensRequest(ctx.GetFromAddress(), appID, assetId.Uint64())
if err != nil {
return err
}
msg := types.NewMsgMintNewTokensRequest(ctx.GetFromAddress(), appID.Uint64(), assetID.Uint64())

return tx.GenerateOrBroadcastTxCLI(ctx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd

}
6 changes: 3 additions & 3 deletions x/tokenmint/expected/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type BankKeeper interface {
}

type AssetKeeper interface {
GetApp(ctx sdk.Context, id uint64) (assettypes.AppMapping, bool)
GetApp(ctx sdk.Context, ID uint64) (assettypes.AppMapping, bool)
GetApps(ctx sdk.Context) ([]assettypes.AppMapping, bool)
GetAsset(ctx sdk.Context, id uint64) (assettypes.Asset, bool)
GetAsset(ctx sdk.Context, ID uint64) (assettypes.Asset, bool)
GetAssetForDenom(ctx sdk.Context, denom string) (assettypes.Asset, bool)
GetMintGenesisTokenData(ctx sdk.Context, appId, assetId uint64) (assettypes.MintGenesisToken, bool)
GetMintGenesisTokenData(ctx sdk.Context, appID, assetID uint64) (assettypes.MintGenesisToken, bool)
}
10 changes: 5 additions & 5 deletions x/tokenmint/keeper/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func (k *Keeper) GetApps(ctx sdk.Context) ([]assettypes.AppMapping, bool) {
return k.asset.GetApps(ctx)
}

func (k *Keeper) GetMintGenesisTokenData(ctx sdk.Context, appId, assetId uint64) (assettypes.MintGenesisToken, bool) {
return k.asset.GetMintGenesisTokenData(ctx, appId, assetId)
func (k *Keeper) GetMintGenesisTokenData(ctx sdk.Context, appID, assetID uint64) (assettypes.MintGenesisToken, bool) {
return k.asset.GetMintGenesisTokenData(ctx, appID, assetID)
}

func (k *Keeper) GetAssetForDenom(ctx sdk.Context, denom string) (assettypes.Asset, bool){
return k.asset.GetAssetForDenom(ctx,denom)
}
func (k *Keeper) GetAssetForDenom(ctx sdk.Context, denom string) (assettypes.Asset, bool) {
return k.asset.GetAssetForDenom(ctx, denom)
}
18 changes: 0 additions & 18 deletions x/tokenmint/keeper/grpc_query_params.go
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
package keeper

// import (
// "context"

// sdk "github.com/cosmos/cosmos-sdk/types"
// "github.com/comdex-official/comdex/x/tokenmint/types"
// "google.golang.org/grpc/codes"
// "google.golang.org/grpc/status"
// )

// func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
// if req == nil {
// return nil, status.Error(codes.InvalidArgument, "invalid request")
// }
// ctx := sdk.UnwrapSDKContext(c)

// return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil
// }
Loading

0 comments on commit 2f1833d

Please sign in to comment.