Add a command to get registry module account balances

This commit is contained in:
Prathamesh Musale 2024-02-19 09:32:01 +05:30
parent 764fb1f04a
commit 0b8904d7de
3 changed files with 28 additions and 1 deletions

View File

@ -326,5 +326,24 @@ func (k Keeper) processAttributeMap(ctx sdk.Context, n ipld.Node, id string, pre
// GetModuleBalances gets the registry module account(s) balances.
func (k Keeper) GetModuleBalances(ctx sdk.Context) []*registrytypes.AccountBalance {
panic("unimplemented")
var balances []*registrytypes.AccountBalance
accountNames := []string{
registrytypes.RecordRentModuleAccountName,
registrytypes.AuthorityRentModuleAccountName,
}
for _, accountName := range accountNames {
moduleAddress := k.accountKeeper.GetModuleAddress(accountName)
moduleAccount := k.accountKeeper.GetAccount(ctx, moduleAddress)
if moduleAccount != nil {
accountBalance := k.bankKeeper.GetAllBalances(ctx, moduleAddress)
balances = append(balances, &registrytypes.AccountBalance{
AccountName: accountName,
Balance: accountBalance,
})
}
}
return balances
}

View File

@ -90,7 +90,9 @@ func (qs queryServer) GetRegistryModuleBalance(c context.Context,
_ *registrytypes.QueryGetRegistryModuleBalanceRequest,
) (*registrytypes.QueryGetRegistryModuleBalanceResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
balances := qs.k.GetModuleBalances(ctx)
return &registrytypes.QueryGetRegistryModuleBalanceResponse{
Balances: balances,
}, nil

View File

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