Add a command to get auction module balance

This commit is contained in:
Prathamesh Musale 2024-02-14 09:25:10 +05:30
parent de742a5a84
commit 842dfc6185
3 changed files with 22 additions and 7 deletions

View File

@ -367,3 +367,11 @@ func (k Keeper) GetParams(ctx sdk.Context) (*auctiontypes.Params, error) {
return &params, nil
}
// GetAuctionModuleBalances gets the auction module account(s) balances.
func (k Keeper) GetAuctionModuleBalances(ctx sdk.Context) sdk.Coins {
moduleAddress := k.accountKeeper.GetModuleAddress(auctiontypes.ModuleName)
balances := k.bankKeeper.GetAllBalances(ctx, moduleAddress)
return balances
}

View File

@ -10,8 +10,6 @@ import (
auctiontypes "git.vdb.to/cerc-io/laconic2d/x/auction"
)
// TODO: Add required read methods
var _ auctiontypes.QueryServer = queryServer{}
type queryServer struct {
@ -39,12 +37,12 @@ func (qs queryServer) Params(c context.Context, req *auctiontypes.QueryParamsReq
func (qs queryServer) Auctions(c context.Context, req *auctiontypes.QueryAuctionsRequest) (*auctiontypes.QueryAuctionsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
resp, err := qs.k.ListAuctions(ctx)
auctions, err := qs.k.ListAuctions(ctx)
if err != nil {
return nil, err
}
return &auctiontypes.QueryAuctionsResponse{Auctions: &auctiontypes.Auctions{Auctions: resp}}, nil
return &auctiontypes.QueryAuctionsResponse{Auctions: &auctiontypes.Auctions{Auctions: auctions}}, nil
}
// GetAuction queries an auction by id
@ -91,12 +89,12 @@ func (qs queryServer) GetBids(c context.Context, req *auctiontypes.QueryBidsRequ
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "auction id is required")
}
resp, err := qs.k.GetBids(ctx, req.AuctionId)
bids, err := qs.k.GetBids(ctx, req.AuctionId)
if err != nil {
return nil, err
}
return &auctiontypes.QueryBidsResponse{Bids: resp}, nil
return &auctiontypes.QueryBidsResponse{Bids: bids}, nil
}
// AuctionsByBidder queries auctions by bidder
@ -133,5 +131,8 @@ func (qs queryServer) AuctionsByOwner(c context.Context, req *auctiontypes.Query
// GetAuctionModuleBalance queries the auction module account balance
func (qs queryServer) GetAuctionModuleBalance(c context.Context, req *auctiontypes.QueryGetAuctionModuleBalanceRequest) (*auctiontypes.QueryGetAuctionModuleBalanceResponse, error) {
panic("unimplemented")
ctx := sdk.UnwrapSDKContext(c)
balances := qs.k.GetAuctionModuleBalances(ctx)
return &auctiontypes.QueryGetAuctionModuleBalanceResponse{Balance: balances}, nil
}

View File

@ -68,6 +68,12 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
{ProtoField: "bidder_address"},
},
},
{
RpcMethod: "GetAuctionModuleBalance",
Use: "balance",
Short: "Get auction module account balances",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{},
},
},
},
Tx: &autocliv1.ServiceCommandDescriptor{