gpu-compute-chain/x/cosmostest/keeper/grpc_query_auction_bids.go

34 lines
820 B
Go
Raw Normal View History

2022-08-30 14:27:12 -07:00
package keeper
import (
"context"
2022-08-30 14:47:39 -07:00
"fmt"
2022-08-30 14:27:12 -07:00
2022-08-30 14:47:39 -07:00
"cosmos-test/x/cosmostest/memdb"
2022-08-30 14:27:12 -07:00
"cosmos-test/x/cosmostest/types"
2022-08-30 14:47:39 -07:00
2022-08-30 14:27:12 -07:00
sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (k Keeper) AuctionBids(goCtx context.Context, req *types.QueryAuctionBidsRequest) (*types.QueryAuctionBidsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
2022-08-30 14:47:39 -07:00
auction, found := k.GetAuction(ctx, req.Index)
if !found {
return nil, fmt.Errorf("auction %s not found", req.Index)
}
bids, err := memdb.BidDB.GetBids(auction.Index)
if err != nil {
2022-08-30 14:53:47 -07:00
return nil, fmt.Errorf("failed to get bids for auction %s: %s", auction.Index, err)
2022-08-30 14:47:39 -07:00
}
2022-08-30 14:27:12 -07:00
2022-08-30 14:47:39 -07:00
return &types.QueryAuctionBidsResponse{Bids: bids}, nil
2022-08-30 14:27:12 -07:00
}