accountstd

package
v0.0.0-...-efc05e8 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 6

Documentation

Overview

Package accountstd exports the types and functions that are used by developers to implement smart accounts.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidType = errors.New("invalid type")
)

Functions

func ExecModule

func ExecModule[MsgResp, Msg transaction.Msg](ctx context.Context, msg Msg) (resp MsgResp, err error)

func ExecModuleAnys

func ExecModuleAnys(ctx context.Context, msgs []*implementation.Any) ([]*implementation.Any, error)

ExecModuleAnys can be used to execute a list of messages towards a module when those messages are packed in Any messages. The function returns a list of responses packed in Any messages.

func Funds

func Funds(ctx context.Context) sdk.Coins

Funds returns if any funds were sent during the execute or init request. In queries this returns nil.

func HasSender

func HasSender(ctx context.Context, wantSender []byte) bool

HasSender checks if the execution context was sent from the provided sender

func NewMockContext

func NewMockContext(
	accNumber uint64,
	accountAddr []byte,
	sender []byte,
	funds sdk.Coins,
	moduleExec implementation.ModuleExecFunc,
	moduleQuery implementation.ModuleQueryFunc,
) (context.Context, store.KVStoreService)

func PackAny

func PackAny(msg transaction.Msg) (*implementation.Any, error)

PackAny packs a protobuf Any message generically.

func QueryModule

func QueryModule[Resp, Req transaction.Msg](ctx context.Context, req Req) (resp Resp, err error)

QueryModule can be used by an account to execute a module query.

func RegisterExecuteHandler

func RegisterExecuteHandler[
	Req any, ProtoReq implementation.ProtoMsgG[Req], Resp any, ProtoResp implementation.ProtoMsgG[Resp],
](router *ExecuteBuilder, handler func(ctx context.Context, req ProtoReq) (ProtoResp, error),
)

func RegisterInitHandler

func RegisterInitHandler[
	Req any, ProtoReq implementation.ProtoMsgG[Req], Resp any, ProtoResp implementation.ProtoMsgG[Resp],
](router *InitBuilder, handler func(ctx context.Context, req ProtoReq) (ProtoResp, error),
)

RegisterInitHandler registers an initialisation handler for a smart account that uses protobuf.

func RegisterQueryHandler

func RegisterQueryHandler[
	Req any, ProtoReq implementation.ProtoMsgG[Req], Resp any, ProtoResp implementation.ProtoMsgG[Resp],
](router *QueryBuilder, handler func(ctx context.Context, req ProtoReq) (ProtoResp, error),
)

RegisterQueryHandler registers a query handler for a smart account that uses protobuf.

func Sender

func Sender(ctx context.Context) []byte

Sender returns the sender of the execution request.

func SenderIsAccountsModule

func SenderIsAccountsModule(ctx context.Context) bool

SenderIsAccountsModule returns true if the sender of the execution request is the accounts module.

func SenderIsSelf

func SenderIsSelf(ctx context.Context) bool

SenderIsSelf checks if the sender of the request is the account itself.

func SetSender

func SetSender(ctx context.Context, sender []byte) context.Context

func UnpackAny

func UnpackAny[Msg any, ProtoMsg implementation.ProtoMsgG[Msg]](any *implementation.Any) (*Msg, error)

UnpackAny unpacks a protobuf Any message generically.

func Whoami

func Whoami(ctx context.Context) []byte

Whoami returns the address of the account being invoked.

Types

type AccountCreatorFunc

type AccountCreatorFunc = implementation.AccountCreatorFunc

AccountCreatorFunc is the exported type of AccountCreatorFunc.

func AddAccount

func AddAccount[A Interface](name string, constructor func(deps Dependencies) (A, error)) AccountCreatorFunc

AddAccount is a helper function to add a smart account to the list of smart accounts.

type Dependencies

type Dependencies = implementation.Dependencies

Dependencies is the exported type of Dependencies.

type DepinjectAccount

type DepinjectAccount struct {
	MakeAccount AccountCreatorFunc
}

func DIAccount

func DIAccount[A Interface](name string, constructor func(deps Dependencies) (A, error)) DepinjectAccount

func (DepinjectAccount) IsManyPerContainerType

func (DepinjectAccount) IsManyPerContainerType()

type ExecuteBuilder

type ExecuteBuilder = implementation.ExecuteBuilder

ExecuteBuilder is the exported type of ExecuteBuilder.

type InitBuilder

type InitBuilder = implementation.InitBuilder

InitBuilder is the exported type of InitBuilder.

type Interface

type Interface = implementation.Account

Interface is the exported interface of an Account.

type QueryBuilder

type QueryBuilder = implementation.QueryBuilder

QueryBuilder is the exported type of QueryBuilder.

Jump to

Keyboard shortcuts

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