Additional auction module commands #3

Merged
ashwin merged 8 commits from pm-bid-commands into main 2024-02-15 06:56:20 +00:00
3 changed files with 47 additions and 2 deletions
Showing only changes of commit 513ad9975b - Show all commits

View File

@ -204,12 +204,38 @@ func (k Keeper) GetAuctionById(ctx sdk.Context, id string) (auctiontypes.Auction
func (k Keeper) GetAuctionsByOwner(ctx sdk.Context, owner string) ([]auctiontypes.Auction, error) {
iter, err := k.Auctions.Indexes.Owner.MatchExact(ctx, owner)
if err != nil {
return []auctiontypes.Auction{}, err
return nil, err
}
return indexes.CollectValues(ctx, k.Auctions, iter)
}
// QueryAuctionsByBidder - query auctions by bidder
func (k Keeper) QueryAuctionsByBidder(ctx sdk.Context, bidderAddress string) ([]auctiontypes.Auction, error) {
auctions := []auctiontypes.Auction{}
iter, err := k.Bids.Indexes.Bidder.MatchExact(ctx, bidderAddress)
if err != nil {
return nil, err
}
for ; iter.Valid(); iter.Next() {
keyPair, err := iter.PrimaryKey()
if err != nil {
return nil, err
}
auction, err := k.GetAuctionById(ctx, keyPair.K1())
if err != nil {
return nil, err
}
auctions = append(auctions, auction)
}
return auctions, nil
}
// CreateAuction creates a new auction.
func (k Keeper) CreateAuction(ctx sdk.Context, msg auctiontypes.MsgCreateAuction) (*auctiontypes.Auction, error) {
// TODO: Setup checks

View File

@ -101,7 +101,18 @@ func (qs queryServer) GetBids(c context.Context, req *auctiontypes.QueryBidsRequ
// AuctionsByBidder queries auctions by bidder
func (qs queryServer) AuctionsByBidder(c context.Context, req *auctiontypes.QueryAuctionsByBidderRequest) (*auctiontypes.QueryAuctionsByBidderResponse, error) {
panic("unimplemented")
ctx := sdk.UnwrapSDKContext(c)
if req.BidderAddress == "" {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "bidder address is required")
}
auctions, err := qs.k.QueryAuctionsByBidder(ctx, req.BidderAddress)
if err != nil {
return nil, err
}
return &auctiontypes.QueryAuctionsByBidderResponse{Auctions: &auctiontypes.Auctions{Auctions: auctions}}, nil
}
// AuctionsByOwner queries auctions by owner

View File

@ -60,6 +60,14 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
{ProtoField: "auction_id"},
},
},
{
RpcMethod: "AuctionsByBidder",
Use: "by-bidder [bidder]",
Short: "Get auctions list by bidder",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "bidder_address"},
},
},
},
},
Tx: &autocliv1.ServiceCommandDescriptor{