Skip to content

Commit

Permalink
Added payout related queries in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Aug 13, 2023
1 parent f901725 commit a8815a8
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 22 deletions.
2 changes: 1 addition & 1 deletion x/deposit/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func queryDeposit() *cobra.Command {
cmd := &cobra.Command{
Use: "deposit [address]",
Use: "deposit [account-addr]",
Short: "Query a deposit",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
4 changes: 2 additions & 2 deletions x/node/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func queryNodes() *cobra.Command {
qc = types.NewQueryServiceClient(ctx)
)

if id > 0 {
if id != 0 {
res, err := qc.QueryNodesForPlan(
context.Background(),
types.NewQueryNodesForPlanRequest(
Expand Down Expand Up @@ -115,7 +115,7 @@ func queryNodes() *cobra.Command {
flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "nodes")
cmd.Flags().String(hubtypes.FlagStatus, "", "filter the nodes by status (active|inactive)")
cmd.Flags().Uint64(flagPlan, 0, "query the nodes of a subscription plan")
cmd.Flags().Uint64(flagPlan, 0, "filter the nodes by subscription plan")

return cmd
}
Expand Down
4 changes: 2 additions & 2 deletions x/plan/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ func queryPlans() *cobra.Command {

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "plans")
cmd.Flags().String(flagProvider, "", "filter by provider address")
cmd.Flags().String(flagStatus, "", "filter by status")
cmd.Flags().String(flagProvider, "", "filter the plans by provider address")
cmd.Flags().String(flagStatus, "", "filter the plans by by status (active|inactive)")

return cmd
}
2 changes: 1 addition & 1 deletion x/provider/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func queryProvider() *cobra.Command {
cmd := &cobra.Command{
Use: "provider [address]",
Use: "provider [provider-addr]",
Short: "Query a provider",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
14 changes: 7 additions & 7 deletions x/session/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

func querySession() *cobra.Command {
cmd := &cobra.Command{
Use: "session [id]",
Use: "session [session-id]",
Short: "Query a session",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -86,7 +86,7 @@ func querySessions() *cobra.Command {
qc = types.NewQueryServiceClient(ctx)
)

if !accAddr.Empty() {
if accAddr != nil {
res, err := qc.QuerySessionsForAccount(
context.Background(),
types.NewQuerySessionsForAccountRequest(
Expand All @@ -101,7 +101,7 @@ func querySessions() *cobra.Command {
return ctx.PrintProto(res)
}

if !nodeAddr.Empty() {
if nodeAddr != nil {
res, err := qc.QuerySessionsForNode(
context.Background(),
types.NewQuerySessionsForNodeRequest(
Expand All @@ -116,7 +116,7 @@ func querySessions() *cobra.Command {
return ctx.PrintProto(res)
}

if subscriptionID > 0 {
if subscriptionID != 0 {
res, err := qc.QuerySessionsForSubscription(
context.Background(),
types.NewQuerySessionsForSubscriptionRequest(
Expand Down Expand Up @@ -147,9 +147,9 @@ func querySessions() *cobra.Command {

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "sessions")
cmd.Flags().String(flagAddress, "", "query the sessions of an account address")
cmd.Flags().String(flagNodeAddress, "", "query the sessions of a node address")
cmd.Flags().Uint64(flagSubscriptionID, 0, "query the sessions of a subscription id")
cmd.Flags().String(flagAddress, "", "filter the sessions by an account address")
cmd.Flags().String(flagNodeAddress, "", "filter the sessions by a node address")
cmd.Flags().Uint64(flagSubscriptionID, 0, "filter the sessions by a subscription id")

return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion x/session/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func txUpdateDetails() *cobra.Command {

func txEnd() *cobra.Command {
cmd := &cobra.Command{
Use: "end [id]",
Use: "end [session-id]",
Short: "End a session",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
55 changes: 49 additions & 6 deletions x/subscription/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func querySubscriptions() *cobra.Command {
qc = types.NewQueryServiceClient(ctx)
)

if !accAddr.Empty() {
if accAddr != nil {
res, err := qc.QuerySubscriptionsForAccount(
context.Background(),
types.NewQuerySubscriptionsForAccountRequest(
Expand All @@ -100,7 +100,8 @@ func querySubscriptions() *cobra.Command {
}

return ctx.PrintProto(res)
} else if !nodeAddr.Empty() {
}
if nodeAddr != nil {
res, err := qc.QuerySubscriptionsForNode(
context.Background(),
types.NewQuerySubscriptionsForNodeRequest(
Expand All @@ -113,7 +114,8 @@ func querySubscriptions() *cobra.Command {
}

return ctx.PrintProto(res)
} else if planID > 0 {
}
if planID != 0 {
res, err := qc.QuerySubscriptionsForPlan(
context.Background(),
types.NewQuerySubscriptionsForPlanRequest(
Expand Down Expand Up @@ -144,9 +146,9 @@ func querySubscriptions() *cobra.Command {

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "subscriptions")
cmd.Flags().String(flagAccountAddress, "", "query the subscriptions of an account address")
cmd.Flags().String(flagNodeAddress, "", "query the subscriptions of a node address")
cmd.Flags().Uint64(flagPlanID, 0, "query the subscriptions of a subscription plan")
cmd.Flags().String(flagAccountAddress, "", "filter the subscriptions by an account address")
cmd.Flags().String(flagNodeAddress, "", "filter the subscriptions by a node address")
cmd.Flags().Uint64(flagPlanID, 0, "filter the subscriptions by a subscription plan")

return cmd
}
Expand Down Expand Up @@ -291,6 +293,16 @@ func queryPayouts() *cobra.Command {
return err
}

accAddr, err := GetAccountAddress(cmd.Flags())
if err != nil {
return err
}

nodeAddr, err := GetNodeAddress(cmd.Flags())
if err != nil {
return err
}

pagination, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
Expand All @@ -300,6 +312,35 @@ func queryPayouts() *cobra.Command {
qc = types.NewQueryServiceClient(ctx)
)

if accAddr != nil {
res, err := qc.QueryPayoutsForAccount(
context.Background(),
types.NewQueryPayoutsForAccountRequest(
accAddr,
pagination,
),
)
if err != nil {
return err
}

return ctx.PrintProto(res)
}
if nodeAddr != nil {
res, err := qc.QueryPayoutsForNode(
context.Background(),
types.NewQueryPayoutsForNodeRequest(
nodeAddr,
pagination,
),
)
if err != nil {
return err
}

return ctx.PrintProto(res)
}

res, err := qc.QueryPayouts(
context.Background(),
types.NewQueryPayoutsRequest(
Expand All @@ -316,6 +357,8 @@ func queryPayouts() *cobra.Command {

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "payouts")
cmd.Flags().String(flagAccountAddress, "", "filter the subscriptions by an account address")
cmd.Flags().String(flagNodeAddress, "", "filter the subscriptions by a node address")

return cmd
}
Expand Down
4 changes: 2 additions & 2 deletions x/subscription/types/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func NewQueryPayoutsRequest(pagination *query.PageRequest) *QueryPayoutsRequest
}
}

func NewQueryPayoutsForAccountRequest(addr sdk.AccAddress, pagination *query.PageRequest) *QueryPayoutsForNodeRequest {
return &QueryPayoutsForNodeRequest{
func NewQueryPayoutsForAccountRequest(addr sdk.AccAddress, pagination *query.PageRequest) *QueryPayoutsForAccountRequest {
return &QueryPayoutsForAccountRequest{
Address: addr.String(),
Pagination: pagination,
}
Expand Down

0 comments on commit a8815a8

Please sign in to comment.