Additional auction module commands #3
@ -1,7 +1,3 @@
|
|||||||
//
|
|
||||||
// Copyright 2020 Wireline, Inc.
|
|
||||||
//
|
|
||||||
|
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -162,25 +162,30 @@ func (k Keeper) GetBid(ctx sdk.Context, id string, bidder string) (auctiontypes.
|
|||||||
return bid, nil
|
return bid, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBids gets the auction bids.
|
||||||
|
func (k Keeper) GetBids(ctx sdk.Context, id string) ([]*auctiontypes.Bid, error) {
|
||||||
|
var bids []*auctiontypes.Bid
|
||||||
|
|
||||||
|
// TODO: Optimize using return by value?
|
||||||
|
err := k.Bids.Walk(ctx, collections.NewPrefixedPairRange[string, string](id), func(key collections.Pair[string, string], value auctiontypes.Bid) (stop bool, err error) {
|
||||||
|
bids = append(bids, &value)
|
||||||
|
return false, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return bids, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ListAuctions - get all auctions.
|
// ListAuctions - get all auctions.
|
||||||
func (k Keeper) ListAuctions(ctx sdk.Context) ([]auctiontypes.Auction, error) {
|
func (k Keeper) ListAuctions(ctx sdk.Context) ([]auctiontypes.Auction, error) {
|
||||||
var auctions []auctiontypes.Auction
|
|
||||||
|
|
||||||
iter, err := k.Auctions.Iterate(ctx, nil)
|
iter, err := k.Auctions.Iterate(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for ; iter.Valid(); iter.Next() {
|
return iter.Values()
|
||||||
auction, err := iter.Value()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
auctions = append(auctions, auction)
|
|
||||||
}
|
|
||||||
|
|
||||||
return auctions, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAuction - gets a record from the store.
|
// GetAuction - gets a record from the store.
|
||||||
|
@ -63,14 +63,40 @@ func (qs queryServer) GetAuction(c context.Context, req *auctiontypes.QueryAucti
|
|||||||
return &auctiontypes.QueryAuctionResponse{Auction: &auction}, nil
|
return &auctiontypes.QueryAuctionResponse{Auction: &auction}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBid queries and auction bid
|
// GetBid queries an auction bid by auction-id and bidder
|
||||||
func (qs queryServer) GetBid(c context.Context, req *auctiontypes.QueryBidRequest) (*auctiontypes.QueryBidResponse, error) {
|
func (qs queryServer) GetBid(c context.Context, req *auctiontypes.QueryBidRequest) (*auctiontypes.QueryBidResponse, error) {
|
||||||
panic("unimplemented")
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
|
|
||||||
|
if req.AuctionId == "" {
|
||||||
|
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "auction id is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Bidder == "" {
|
||||||
|
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "bidder address is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
bid, err := qs.k.GetBid(ctx, req.AuctionId, req.Bidder)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &auctiontypes.QueryBidResponse{Bid: &bid}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBids queries all auction bids
|
// GetBids queries all auction bids
|
||||||
func (qs queryServer) GetBids(c context.Context, req *auctiontypes.QueryBidsRequest) (*auctiontypes.QueryBidsResponse, error) {
|
func (qs queryServer) GetBids(c context.Context, req *auctiontypes.QueryBidsRequest) (*auctiontypes.QueryBidsResponse, error) {
|
||||||
panic("unimplemented")
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
|
|
||||||
|
if req.AuctionId == "" {
|
||||||
|
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "auction id is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := qs.k.GetBids(ctx, req.AuctionId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &auctiontypes.QueryBidsResponse{Bids: resp}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuctionsByBidder queries auctions by bidder
|
// AuctionsByBidder queries auctions by bidder
|
||||||
|
@ -43,6 +43,23 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
|
|||||||
{ProtoField: "owner_address"},
|
{ProtoField: "owner_address"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
RpcMethod: "GetBid",
|
||||||
|
Use: "get-bid [auction-id] [bidder]",
|
||||||
|
Short: "Get auction bid by auction id and bidder",
|
||||||
|
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||||
|
{ProtoField: "auction_id"},
|
||||||
|
{ProtoField: "bidder"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
RpcMethod: "GetBids",
|
||||||
|
Use: "get-bids [auction-id]",
|
||||||
|
Short: "Get all auction bids",
|
||||||
|
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||||
|
{ProtoField: "auction_id"},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Tx: &autocliv1.ServiceCommandDescriptor{
|
Tx: &autocliv1.ServiceCommandDescriptor{
|
||||||
|
Loading…
Reference in New Issue
Block a user