Skip to content

Commit

Permalink
refactor: module structure & tx message types
Browse files Browse the repository at this point in the history
- update module structure 
- msg types
  • Loading branch information
harish551 authored Oct 6, 2021
2 parents df7a32f + 46d0a17 commit ccb68a4
Show file tree
Hide file tree
Showing 22 changed files with 1,638 additions and 615 deletions.
69 changes: 33 additions & 36 deletions client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package cli
import (
"context"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"
"github.com/spf13/cobra"

"github.com/OmniFlix/onft/types"
)
Expand All @@ -35,11 +34,11 @@ func GetQueryCmd() *cobra.Command {

func GetCmdQuerySupply() *cobra.Command {
cmd := &cobra.Command{
Use: "supply [denomID]",
Use: "supply [denom-id]",
Long: strings.TrimSpace(
fmt.Sprintf(`total supply of a collection of oNFTs.
Example:
$ %s query onft supply [denom]`, version.AppName)),
$ %s query onft supply [denom-id]`, version.AppName)),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
Expand All @@ -48,17 +47,25 @@ $ %s query onft supply [denom]`, version.AppName)),
return err
}

ownerStr := strings.TrimSpace(viper.GetString(FlagOwner))

denom := strings.TrimSpace(args[0])
if err := types.ValidateDenomID(denom); err != nil {
var owner sdk.AccAddress
ownerStr, err := cmd.Flags().GetString(FlagOwner)
if err != nil {
return err
}

if len(ownerStr) > 0 {
owner, err = sdk.AccAddressFromBech32(ownerStr)
if err != nil {
return err
}
}

denomId := strings.ToLower(strings.TrimSpace(args[0]))

queryClient := types.NewQueryClient(clientCtx)
resp, err := queryClient.Supply(context.Background(), &types.QuerySupplyRequest{
Denom: denom,
Owner: ownerStr,
Denom: denomId,
Owner: owner.String(),
})
if err != nil {
return err
Expand All @@ -74,11 +81,11 @@ $ %s query onft supply [denom]`, version.AppName)),

func GetCmdQueryCollection() *cobra.Command {
cmd := &cobra.Command{
Use: "collection [denomID]",
Use: "collection [denom-id]",
Long: strings.TrimSpace(
fmt.Sprintf(`Get all the oNFTs from a given collection
Example:
$ %s query onft collection <denom>`, version.AppName)),
$ %s query onft collection <denom-id>`, version.AppName)),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
Expand All @@ -87,14 +94,11 @@ $ %s query onft collection <denom>`, version.AppName)),
return err
}

denom := strings.TrimSpace(args[0])
if err := types.ValidateDenomID(denom); err != nil {
return err
}
denomId := strings.ToLower(strings.TrimSpace(args[0]))

queryClient := types.NewQueryClient(clientCtx)
resp, err := queryClient.Collection(context.Background(), &types.QueryCollectionRequest{
Denom: denom,
Denom: denomId,
})
if err != nil {
return err
Expand Down Expand Up @@ -136,11 +140,11 @@ $ %s query onft denoms`, version.AppName)),

func GetCmdQueryDenom() *cobra.Command {
cmd := &cobra.Command{
Use: "denom [denomID]",
Use: "denom [denom-id]",
Long: strings.TrimSpace(
fmt.Sprintf(`Query the denominations by the specified denom name
Example:
$ %s query onft denom <denom>`, version.AppName)),
$ %s query onft denom <denom-id>`, version.AppName)),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
Expand All @@ -149,14 +153,14 @@ $ %s query onft denom <denom>`, version.AppName)),
return err
}

denom := strings.TrimSpace(args[0])
if err := types.ValidateDenomID(denom); err != nil {
denomId := strings.ToLower(strings.TrimSpace(args[0]))
if err := types.ValidateDenomID(denomId); err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
resp, err := queryClient.Denom(context.Background(), &types.QueryDenomRequest{
Denom: denom,
Denom: denomId,
})
if err != nil {
return err
Expand All @@ -171,11 +175,11 @@ $ %s query onft denom <denom>`, version.AppName)),

func GetCmdQueryONFT() *cobra.Command {
cmd := &cobra.Command{
Use: "asset [denomID] [onftID]",
Use: "asset [denom-id] [onft-id]",
Long: strings.TrimSpace(
fmt.Sprintf(`Query a single oNFT from a collection
Example:
$ %s query onft asset <denom> <onftID>`, version.AppName)),
$ %s query onft asset <denom> <onft-id>`, version.AppName)),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
Expand All @@ -184,20 +188,13 @@ $ %s query onft asset <denom> <onftID>`, version.AppName)),
return err
}

denom := strings.TrimSpace(args[0])
if err := types.ValidateDenomID(denom); err != nil {
return err
}

onftID := strings.TrimSpace(args[1])
if err := types.ValidateONFTID(onftID); err != nil {
return err
}
denomId := strings.ToLower(strings.TrimSpace(args[0]))
onftId := strings.ToLower(strings.TrimSpace(args[1]))

queryClient := types.NewQueryClient(clientCtx)
resp, err := queryClient.ONFT(context.Background(), &types.QueryONFTRequest{
Denom: denom,
Id: onftID,
Denom: denomId,
Id: onftId,
})
if err != nil {
return err
Expand Down
Loading

0 comments on commit ccb68a4

Please sign in to comment.