From 842dfc618540bd753f9bf24505af86d50d32eab7 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 14 Feb 2024 09:25:10 +0530 Subject: [PATCH] Add a command to get auction module balance --- x/auction/keeper/keeper.go | 8 ++++++++ x/auction/keeper/query_server.go | 15 ++++++++------- x/auction/module/autocli.go | 6 ++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/x/auction/keeper/keeper.go b/x/auction/keeper/keeper.go index f11e3259..33eae0ea 100644 --- a/x/auction/keeper/keeper.go +++ b/x/auction/keeper/keeper.go @@ -367,3 +367,11 @@ func (k Keeper) GetParams(ctx sdk.Context) (*auctiontypes.Params, error) { return ¶ms, 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 +} diff --git a/x/auction/keeper/query_server.go b/x/auction/keeper/query_server.go index 77cb32a6..4bcfc824 100644 --- a/x/auction/keeper/query_server.go +++ b/x/auction/keeper/query_server.go @@ -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 } diff --git a/x/auction/module/autocli.go b/x/auction/module/autocli.go index 2861e133..b6327a07 100644 --- a/x/auction/module/autocli.go +++ b/x/auction/module/autocli.go @@ -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{