cosmos-sdk/x/accounts
dependabot[bot] 71f18076d6
build(deps): Bump cosmossdk.io/api from 0.7.5 to 0.7.6 (#21895)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
2024-09-25 07:03:18 +00:00
..
accountstd feat(auth): support accounts from auth (#21688) 2024-09-17 18:12:45 +00:00
cli chore: bump golangci-lint and fix all linting issues (#21761) 2024-09-16 19:11:19 +00:00
defaults build(deps): Bump cosmossdk.io/api from 0.7.5 to 0.7.6 (#21895) 2024-09-25 07:03:18 +00:00
interfaces/account_abstraction/v1 perf!: Make slashing not write sign info every block (#19458) 2024-02-20 16:51:02 +00:00
internal refactor(core,stf,x)!: remove InvokeTyped from router (#21224) 2024-08-23 21:38:06 +00:00
proto feat(auth): allow BaseAccounts to be migrated to x/accounts (#21820) 2024-09-23 21:22:01 +00:00
testing chore: fix some comments (#21085) 2024-07-26 11:00:15 +00:00
v1 build(deps): bump proto-builder and regen protos (#21215) 2024-08-08 08:45:15 +00:00
account_test.go refactor(core,stf,x)!: remove InvokeTyped from router (#21224) 2024-08-23 21:38:06 +00:00
CHANGELOG.md feat(x/accounts): On-chain multisig (#19988) 2024-05-06 11:26:49 +00:00
coin_transfer.go refactor(core,stf,x)!: remove InvokeTyped from router (#21224) 2024-08-23 21:38:06 +00:00
depinject.go feat(accounts/base): give chains the possibility to pick their chosen pubkey types for the base accounts (#21466) 2024-09-03 17:09:04 +00:00
genesis_test.go fix (x/accounts): Fix genesis condition check (#20645) 2024-06-12 16:25:02 +00:00
genesis.go fix (x/accounts): Fix genesis condition check (#20645) 2024-06-12 16:25:02 +00:00
go.mod build(deps): Bump cosmossdk.io/api from 0.7.5 to 0.7.6 (#21895) 2024-09-25 07:03:18 +00:00
go.sum build(deps): Bump google.golang.org/grpc from 1.66.2 to 1.67.0 (#21893) 2024-09-25 06:59:42 +00:00
keeper_account_abstraction.go refactor(auth): decouple auth from x/accounts account abstraction types (#20875) 2024-07-08 14:15:17 +00:00
keeper_test.go feat(x/accounts): use router service from env (#20003) 2024-04-15 15:41:11 +00:00
keeper.go feat(auth): support accounts from auth (#21688) 2024-09-17 18:12:45 +00:00
module.go refactor(core,stf): complete gas service + simplify deps (#21166) 2024-08-08 07:30:09 +00:00
msg_server_test.go feat(x/accounts): use router service from env (#20003) 2024-04-15 15:41:11 +00:00
msg_server.go feat(accounts): add genesis account initialization (#20642) 2024-06-12 14:19:13 +00:00
query_server_test.go feat(x/accounts): Add schema caching feature and corresponding test case (#20055) 2024-05-17 05:11:45 +00:00
query_server.go feat(x/accounts): Add schema caching feature and corresponding test case (#20055) 2024-05-17 05:11:45 +00:00
README.md refactor(x/mint): remove staking as a required module (#21858) 2024-09-24 19:52:31 +00:00
sonar-project.properties chore: force reload sonar cloud (#20480) 2024-05-29 11:12:09 +00:00
utils_test.go refactor(core,types,runtime,x): make HasName not mandatory (#20984) 2024-07-19 08:58:47 +00:00

x/accounts

The x/accounts module provides module and facilities for writing smart cosmos-sdk accounts.

Supporting Custom Accounts in the x/auth gRPC Server

Overview

The x/auth module provides a mechanism for custom account types to be exposed via its Account and AccountInfo gRPC queries. This feature is particularly useful for ensuring compatibility with existing wallets that have not yet integrated with x/accounts but still need to parse account information post-migration.

Implementation

To support this feature, your custom account type needs to implement the auth.QueryLegacyAccount handler. Here are some important points to consider:

  1. Selective Implementation: This implementation is not required for every account type. It's only necessary for accounts you want to expose through the x/auth gRPC Account and AccountInfo methods.
  2. Flexible Response: The info field in the QueryLegacyAccountResponse is optional. If your custom account cannot be represented as a BaseAccount, you can leave this field empty.

Example Implementation

A concrete example of implementation can be found in defaults/base/account.go. Here's a simplified version:

func (a Account) AuthRetroCompatibility(ctx context.Context, _ *authtypes.QueryLegacyAccount) (*authtypes.QueryLegacyAccountResponse, error) {
    seq := a.GetSequence()
    num := a.GetNumber()
    address := a.GetAddress()
    pubKey := a.GetPubKey()

    baseAccount := &authtypes.BaseAccount{
        AccountNumber: num,
        Sequence:      seq,
        Address:       address,
    }

    // Convert pubKey to Any type
    pubKeyAny, err := gogotypes.NewAnyWithValue(pubKey)
    if err != nil {
        return nil, err
    }
    baseAccount.PubKey = pubKeyAny

    // Convert the entire baseAccount to Any type
    accountAny, err := gogotypes.NewAnyWithValue(baseAccount)
    if err != nil {
        return nil, err
    }

    return &authtypes.QueryLegacyAccountResponse{
        Account: accountAny,
        Info:    baseAccount,
    }, nil
}

Usage Notes

  • Implement this handler only for account types you want to expose via x/auth gRPC methods.
  • The info field in the response can be nil if your account doesn't fit the BaseAccount structure.

Genesis

Creating accounts on genesis

In order to create accounts at genesis, the x/accounts module allows developers to provide a list of genesis MsgInit messages that will be executed in the x/accounts genesis flow.

The init messages are generated offline. You can also use the following CLI command to generate the json messages: simd accounts tx init [account type] [msg] --from me --genesis. This will generate a jsonified init message wrapped in an x/accounts MsgInit.

This follows the same initialization flow and rules that would happen if the chain is running. The only concrete difference is that this is happening at the genesis block.

For example, given the following genesis.json file:

{
  "app_state": {
    "accounts": {
      "init_account_msgs": [
        {
          "sender": "account_creator_address",
          "account_type": "lockup",
          "message": {
            "@type": "cosmos.accounts.defaults.lockup.MsgInitLockupAccount",
            "owner": "some_owner",
            "end_time": "..",
            "start_time": ".."
          },
          "funds": [
            {
              "denom": "stake",
              "amount": "1000"
            }
          ]
        }
      ]
    }
  }
}

The accounts module will run the lockup account initialization message.