Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Query demand orders by status cmd #637

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions proto/dymension/eibc/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ service Query {
rpc DemandOrderById(QueryGetDemandOrderRequest) returns (QueryGetDemandOrderResponse) {
option (google.api.http).get = "/dymensionxyz/dymension/eibc/demand_order/{id}";
}
// Queries a list of demand orders by status.
rpc DemandOrdersByStatus(QueryDemandOrdersByStatusRequest) returns (QueryDemandOrdersByStatusResponse) {
option (google.api.http).get = "/dymensionxyz/dymension/eibc/demand_orders/{status}";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand All @@ -36,8 +40,20 @@ message QueryGetDemandOrderRequest {
string id = 1;
}

// QueryDemandOrdersByStatusRequest is the request type for the Query/GetDemandOrdersByStatus RPC method.
message QueryDemandOrdersByStatusRequest {
// id of the demand order to get
string status = 1;
}

// QueryGetDemandOrderResponse is the response type for the Query/GetDemandOrder RPC method.
message QueryGetDemandOrderResponse {
// demand order with the given id
DemandOrder demand_order = 1;
}

// QueryDemandOrdersByStatusResponse is the response type for the Query/GetDemandOrdersByStatus RPC method.
message QueryDemandOrdersByStatusResponse {
// A list of demand orders with the given status
repeated DemandOrder demand_orders = 1;
}
1 change: 1 addition & 0 deletions x/eibc/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
}

cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdListDemandOrdersByStatus())

Check warning on line 28 in x/eibc/client/cli/query.go

View check run for this annotation

Codecov / codecov/patch

x/eibc/client/cli/query.go#L28

Added line #L28 was not covered by tests
// this line is used by starport scaffolding # 1

return cmd
Expand Down
38 changes: 38 additions & 0 deletions x/eibc/client/cli/query_command_orders.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cli

import (
"context"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/dymensionxyz/dymension/v3/x/eibc/types"
"github.com/spf13/cobra"
)

func CmdListDemandOrdersByStatus() *cobra.Command {
cmd := &cobra.Command{
Use: "list-demand-orders [status]",
Short: "List all demand orders with a specific status",
Long: `Query demand orders filtered by status. Examples of status include "pending", "finalized", and "reverted".`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
status := args[0]

queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.DemandOrdersByStatus(context.Background(), &types.QueryDemandOrdersByStatusRequest{
Status: status,
})

if err != nil {
return err
}

Check warning on line 29 in x/eibc/client/cli/query_command_orders.go

View check run for this annotation

Codecov / codecov/patch

x/eibc/client/cli/query_command_orders.go#L12-L29

Added lines #L12 - L29 were not covered by tests

return clientCtx.PrintProto(res)

Check warning on line 31 in x/eibc/client/cli/query_command_orders.go

View check run for this annotation

Codecov / codecov/patch

x/eibc/client/cli/query_command_orders.go#L31

Added line #L31 was not covered by tests
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd

Check warning on line 37 in x/eibc/client/cli/query_command_orders.go

View check run for this annotation

Codecov / codecov/patch

x/eibc/client/cli/query_command_orders.go#L35-L37

Added lines #L35 - L37 were not covered by tests
}
34 changes: 34 additions & 0 deletions x/eibc/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import (
"context"
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
Expand Down Expand Up @@ -49,3 +51,35 @@
}
return nil, status.Error(codes.Internal, err.Error())
}

func (q Querier) DemandOrdersByStatus(goCtx context.Context, req *types.QueryDemandOrdersByStatusRequest) (*types.QueryDemandOrdersByStatusResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
if req.Status == "" {
return nil, status.Error(codes.InvalidArgument, "status must be provided")
}

Check warning on line 61 in x/eibc/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/eibc/keeper/grpc_query.go#L55-L61

Added lines #L55 - L61 were not covered by tests

// Convert string status to commontypes.Status
var statusValue commontypes.Status
switch strings.ToUpper(req.Status) {
case "PENDING":
statusValue = commontypes.Status_PENDING
case "FINALIZED":
statusValue = commontypes.Status_FINALIZED
case "REVERTED":
statusValue = commontypes.Status_REVERTED
default:
return nil, fmt.Errorf("invalid demand order status: %s", req.Status)

Check warning on line 73 in x/eibc/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/eibc/keeper/grpc_query.go#L64-L73

Added lines #L64 - L73 were not covered by tests
}
ctx := sdk.UnwrapSDKContext(goCtx)

// Get the demand orders by status
demandOrders, err := q.ListDemandOrdersByStatus(ctx, statusValue)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

Check warning on line 81 in x/eibc/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/eibc/keeper/grpc_query.go#L75-L81

Added lines #L75 - L81 were not covered by tests

// Construct the response
return &types.QueryDemandOrdersByStatusResponse{DemandOrders: demandOrders}, nil

Check warning on line 84 in x/eibc/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/eibc/keeper/grpc_query.go#L84

Added line #L84 was not covered by tests
}
Loading
Loading