accounts

package module
v0.0.0-...-a6871c7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 36 Imported by: 12

README

x/accounts

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

Documentation

Index

Constants

View Source
const (
	ModuleName = "accounts"
	StoreKey   = "_" + ModuleName // unfortunately accounts collides with auth store key

	ConsensusVersion = 1
)
View Source
const (
	// TODO(tip): evaluate if the following numbers should be parametrised over state, or over the node.
	SimulateAuthenticateGasLimit   = 1_000_000
	SimulateBundlerPaymentGasLimit = SimulateAuthenticateGasLimit
	ExecuteGasLimit                = SimulateAuthenticateGasLimit
)

Variables

View Source
var (
	// AccountTypeKeyPrefix is the prefix for the account type key.
	AccountTypeKeyPrefix = collections.NewPrefix(0)
	// AccountNumberKey is the key for the account number.
	AccountNumberKey = collections.NewPrefix(1)
	// AccountByNumber is the key for the accounts by number.
	AccountByNumber = collections.NewPrefix(2)
)
View Source
var (
	// ErrAuthentication is returned when the authentication fails.
	ErrAuthentication = errors.New("authentication failed")
	// ErrBundlerPayment is returned when the bundler payment fails.
	ErrBundlerPayment = errors.New("bundler payment failed")
	// ErrExecution is returned when the execution fails.
	ErrExecution = errors.New("execution failed")
)
View Source
var (

	// ErrUnauthorized is returned when a message sender is not allowed to perform the operation.
	ErrUnauthorized = errors.New("unauthorized")
)
View Source
var ModuleAccountAddress = address.Module(ModuleName)

ModuleAccountAddress defines the x/accounts module address.

Functions

func NewMsgServer

func NewMsgServer(k Keeper) v1.MsgServer

func NewQueryServer

func NewQueryServer(k Keeper) v1.QueryServer

Types

type AppModule

type AppModule struct {
	// contains filtered or unexported fields
}

func NewAppModule

func NewAppModule(cdc codec.Codec, k Keeper) AppModule

func (AppModule) ConsensusVersion

func (AppModule) ConsensusVersion() uint64

func (AppModule) DefaultGenesis

func (am AppModule) DefaultGenesis() json.RawMessage

func (AppModule) ExportGenesis

func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error)

func (AppModule) GetQueryCmd

func (AppModule) GetQueryCmd() *cobra.Command

func (AppModule) GetTxCmd

func (AppModule) GetTxCmd() *cobra.Command

func (AppModule) InitGenesis

func (am AppModule) InitGenesis(ctx context.Context, message json.RawMessage) error

func (AppModule) IsAppModule

func (m AppModule) IsAppModule()

func (AppModule) IsOnePerModuleType

func (am AppModule) IsOnePerModuleType()

IsOnePerModuleType implements the depinject.OnePerModuleType interface.

func (AppModule) Name

func (AppModule) Name() string

func (AppModule) RegisterInterfaces

func (m AppModule) RegisterInterfaces(registrar registry.InterfaceRegistrar)

func (AppModule) RegisterServices

func (m AppModule) RegisterServices(registar grpc.ServiceRegistrar) error

func (AppModule) ValidateGenesis

func (am AppModule) ValidateGenesis(message json.RawMessage) error

type InterfaceRegistry

type InterfaceRegistry interface {
	RegisterInterface(name string, iface any, impls ...protoiface.MessageV1)
	RegisterImplementations(iface any, impls ...protoiface.MessageV1)
}

type Keeper

type Keeper struct {
	appmodule.Environment

	// Schema is the schema for the module.
	Schema collections.Schema
	// AccountNumber is the last global account number.
	AccountNumber collections.Sequence
	// AccountsByType maps account address to their implementation.
	AccountsByType collections.Map[[]byte, string]
	// AccountByNumber maps account number to their address.
	AccountByNumber collections.Map[[]byte, uint64]

	// AccountsState keeps track of the state of each account.
	// NOTE: this is only used for genesis import and export.
	// Account set and get their own state but this helps providing a nice mapping
	// between: (account number, account state key) => account state value.
	AccountsState collections.Map[collections.Pair[uint64, []byte], []byte]
	// contains filtered or unexported fields
}

func NewKeeper

func NewKeeper(
	cdc codec.Codec,
	env appmodule.Environment,
	addressCodec address.Codec,
	ir InterfaceRegistry,
	accounts ...accountstd.AccountCreatorFunc,
) (Keeper, error)

func (Keeper) AuthenticateAccount

func (k Keeper) AuthenticateAccount(ctx context.Context, addr []byte, msg *aa_interface_v1.MsgAuthenticate) error

func (Keeper) Execute

func (k Keeper) Execute(
	ctx context.Context,
	accountAddr []byte,
	sender []byte,
	execRequest implementation.ProtoMsg,
	funds sdk.Coins,
) (implementation.ProtoMsg, error)

Execute executes a state transition on the given account.

func (Keeper) ExportState

func (k Keeper) ExportState(ctx context.Context) (*v1.GenesisState, error)

func (Keeper) ImportState

func (k Keeper) ImportState(ctx context.Context, genState *v1.GenesisState) error

func (Keeper) Init

func (k Keeper) Init(
	ctx context.Context,
	accountType string,
	creator []byte,
	initRequest implementation.ProtoMsg,
	funds sdk.Coins,
) (implementation.ProtoMsg, []byte, error)

Init creates a new account of the given type.

func (Keeper) IsAbstractedAccount

func (k Keeper) IsAbstractedAccount(ctx context.Context, addr []byte) (bool, error)

IsAbstractedAccount returns if the provided address is an abstracted account or not.

func (Keeper) IsAccountsModuleAccount

func (k Keeper) IsAccountsModuleAccount(
	ctx context.Context,
	accountAddr []byte,
) bool

IsAccountsModuleAccount check if an address belong to a smart account.

func (Keeper) MigrateLegacyAccount

func (k Keeper) MigrateLegacyAccount(
	ctx context.Context,
	addr []byte,
	accNum uint64,
	accType string,
	msg implementation.ProtoMsg,
) (implementation.ProtoMsg, error)

MigrateLegacyAccount is used to migrate a legacy account to x/accounts. Concretely speaking this works like Init, but with a custom account number provided, Where the creator is the account itself. This can be used by the x/auth module to gradually migrate base accounts to x/accounts. NOTE: this assumes the calling module checks for account overrides.

func (Keeper) Query

func (k Keeper) Query(
	ctx context.Context,
	accountAddr []byte,
	queryRequest implementation.ProtoMsg,
) (implementation.ProtoMsg, error)

Query queries the given account.

func (Keeper) SendModuleMessageUntyped

func (k Keeper) SendModuleMessageUntyped(ctx context.Context, sender []byte, msg implementation.ProtoMsg) (implementation.ProtoMsg, error)

SendModuleMessageUntyped can be used to send a message towards a module. It should be used when the response type is not known by the caller.

type ModuleInputs

type ModuleInputs struct {
	depinject.In

	Cdc          codec.Codec
	Environment  appmodule.Environment
	AddressCodec address.Codec
	Registry     cdctypes.InterfaceRegistry
}

type ModuleOutputs

type ModuleOutputs struct {
	depinject.Out

	AccountsKeeper Keeper
	Module         appmodule.AppModule
}

func ProvideModule

func ProvideModule(in ModuleInputs) ModuleOutputs

Directories

Path Synopsis
Package accountstd exports the types and functions that are used by developers to implement smart accounts.
Package accountstd exports the types and functions that are used by developers to implement smart accounts.
defaults
lockup Module
interfaces
internal
prefixstore
Package prefixstore provides a store that prefixes all keys with a given prefix.
Package prefixstore provides a store that prefixes all keys with a given prefix.
testing

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL