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

34 lines
820 B
Go

package keeper
import (
"context"
"fmt"
"cosmos-test/x/cosmostest/memdb"
"cosmos-test/x/cosmostest/types"
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)
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 {
return nil, fmt.Errorf("failed to get bids for auction %s: %s", auction.Index, err)
}
return &types.QueryAuctionBidsResponse{Bids: bids}, nil
}