From ecf095e10e81dd8f10880277559a1322af22ee17 Mon Sep 17 00:00:00 2001 From: Zygimantas <5236121+Zygimantass@users.noreply.github.com> Date: Wed, 27 Dec 2023 14:31:29 +0200 Subject: [PATCH] feat(cosmosutil): add querying methods for the Auth module --- cosmosutil/auth.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 cosmosutil/auth.go diff --git a/cosmosutil/auth.go b/cosmosutil/auth.go new file mode 100644 index 0000000..f6a83bb --- /dev/null +++ b/cosmosutil/auth.go @@ -0,0 +1,33 @@ +package cosmosutil + +import ( + "context" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +func (c *ChainClient) Account(ctx context.Context, address string) (sdk.AccountI, error) { + authClient, err := c.getAuthClient() + + if err != nil { + return nil, err + } + + res, err := authClient.Account(ctx, &authtypes.QueryAccountRequest{ + Address: address, + }) + + if err != nil { + return nil, err + } + + var acc authtypes.BaseAccount + + err = c.EncodingConfig.InterfaceRegistry.UnpackAny(res.Account, &acc) + + if err != nil { + return nil, err + } + + return &acc, nil +}