implementation

package
v0.0.0-...-f74a9f6 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AccountStatePrefix = collections.NewPrefix(255)

Functions

func Equal

func Equal(a, b transaction.Msg) bool

func ExecModule

func ExecModule(ctx context.Context, msg transaction.Msg) (transaction.Msg, error)

ExecModule can be used to execute a message towards a module, when the response type is unknown.

func FindMessageByName

func FindMessageByName(name string) (transaction.Msg, error)

func Funds

func Funds(ctx context.Context) sdk.Coins

Funds returns the funds associated with the execution context.

func IsRoutingError

func IsRoutingError(err error) bool

IsRoutingError returns true if the error is a routing error, which typically occurs when a message cannot be matched to a handler.

func MakeAccountContext

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

MakeAccountContext creates a new account execution context given: storeSvc: which fetches the x/accounts module store. accountAddr: the address of the account being invoked, which is used to give the account a prefixed storage. sender: the address of entity invoking the account action. moduleExec: a function that executes a module message. moduleQuery: a function that queries a module.

func MakeAccountsMap

func MakeAccountsMap(
	cdc codec.Codec,
	addressCodec address.Codec,
	env appmodule.Environment,
	accounts []AccountCreatorFunc,
) (map[string]Implementation, error)

MakeAccountsMap creates a map of account names to account implementations from a list of account creator functions.

func Merge

func Merge(a, b transaction.Msg)

func MessageName

func MessageName(msg transaction.Msg) string

func QueryModule

func QueryModule(ctx context.Context, req transaction.Msg) (transaction.Msg, error)

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

func RegisterExecuteHandler

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

RegisterExecuteHandler registers an execution handler for a smart account that uses protobuf.

func RegisterInitHandler

func RegisterInitHandler[
	Req any, ProtoReq ProtoMsgG[Req], Resp any, ProtoResp 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 ProtoMsgG[Req], Resp any, ProtoResp 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 address of the entity invoking the account action.

func SetSender

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

func UnpackAny

func UnpackAny[T any, PT ProtoMsgG[T]](anyPB *Any) (PT, error)

UnpackAny unpacks an anypb.Any into a proto message.

func UnpackAnyRaw

func UnpackAnyRaw(anyPB *Any) (proto.Message, error)

func UnpackAnyTo

func UnpackAnyTo(anyPB *Any, to transaction.Msg) error

func Whoami

func Whoami(ctx context.Context) []byte

Whoami returns the address of the account being invoked.

Types

type Account

type Account interface {
	// RegisterInitHandler allows the smart account to register an initialisation handler, using
	// the provided InitBuilder. The handler will be called when the smart account is initialized
	// (deployed).
	RegisterInitHandler(builder *InitBuilder)

	// RegisterExecuteHandlers allows the smart account to register execution handlers.
	// The smart account might also decide to not register any execution handler.
	RegisterExecuteHandlers(builder *ExecuteBuilder)

	// RegisterQueryHandlers allows the smart account to register query handlers. The smart account
	// might also decide to not register any query handler.
	RegisterQueryHandlers(builder *QueryBuilder)
}

Account defines a smart account interface.

type AccountCreatorFunc

type AccountCreatorFunc = func(deps Dependencies) (string, Account, error)

AccountCreatorFunc is a function that creates an account.

type Any

type Any = codectypes.Any

func PackAny

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

PackAny packs a proto message into an anypb.Any.

type Dependencies

type Dependencies struct {
	SchemaBuilder    *collections.SchemaBuilder
	AddressCodec     address.Codec
	Environment      appmodule.Environment
	LegacyStateCodec interface {
		Marshal(gogoproto.Message) ([]byte, error)
		Unmarshal([]byte, gogoproto.Message) error
	}
}

Dependencies are passed to the constructor of a smart account.

type ExecuteBuilder

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

ExecuteBuilder defines a smart account's execution router, it will be used to map an execution message to a handler function for a specific account.

func NewExecuteBuilder

func NewExecuteBuilder() *ExecuteBuilder

NewExecuteBuilder creates a new ExecuteBuilder instance.

type HandlerSchema

type HandlerSchema struct {
	// RequestSchema defines the schema of the request.
	RequestSchema MessageSchema
	// ResponseSchema defines the schema of the response.
	ResponseSchema MessageSchema
}

HandlerSchema defines the schema of a handler.

type Implementation

type Implementation struct {
	// Init defines the initialisation handler for the smart account.
	Init func(ctx context.Context, msg transaction.Msg) (resp transaction.Msg, err error)
	// Execute defines the execution handler for the smart account.
	Execute func(ctx context.Context, msg transaction.Msg) (resp transaction.Msg, err error)
	// Query defines the query handler for the smart account.
	Query func(ctx context.Context, msg transaction.Msg) (resp transaction.Msg, err error)
	// CollectionsSchema represents the state schema.
	CollectionsSchema collections.Schema
	// InitHandlerSchema represents the init handler schema.
	InitHandlerSchema HandlerSchema
	// QueryHandlersSchema is the schema of the query handlers.
	QueryHandlersSchema map[string]HandlerSchema
	// ExecuteHandlersSchema is the schema of the execute handlers.
	ExecuteHandlersSchema map[string]HandlerSchema
}

Implementation wraps an Account implementer in order to provide a concrete and non-generic implementation usable by the x/accounts module.

func (Implementation) HasExec

func (i Implementation) HasExec(m transaction.Msg) bool

HasExec returns true if the account can execute the given msg.

func (Implementation) HasInit

func (i Implementation) HasInit(m transaction.Msg) bool

HasInit returns true if the account uses the provided init message.

func (Implementation) HasQuery

func (i Implementation) HasQuery(m transaction.Msg) bool

HasQuery returns true if the account can execute the given request.

type InitBuilder

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

InitBuilder defines a smart account's initialisation handler builder.

func NewInitBuilder

func NewInitBuilder() *InitBuilder

NewInitBuilder creates a new InitBuilder instance.

type MessageSchema

type MessageSchema struct {
	// Name identifies the message name, this must be queryable from some reflection service.
	Name string
	// New is used to create a new message instance for the schema.
	New func() transaction.Msg
}

MessageSchema defines the schema of a message. A message can also define a state schema.

func NewProtoMessageSchema

func NewProtoMessageSchema[T any, PT ProtoMsgG[T]]() *MessageSchema

type ModuleExecFunc

type ModuleExecFunc = func(ctx context.Context, sender []byte, msg transaction.Msg) (transaction.Msg, error)

type ModuleQueryFunc

type ModuleQueryFunc = func(ctx context.Context, queryReq transaction.Msg) (transaction.Msg, error)

type ProtoMsgG

type ProtoMsgG[T any] interface {
	*T
	transaction.Msg
}

ProtoMsgG is a generic interface for protobuf messages.

type QueryBuilder

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

QueryBuilder defines a smart account's query router, it will be used to map a query message to a handler function for a specific account.

func NewQueryBuilder

func NewQueryBuilder() *QueryBuilder

NewQueryBuilder creates a new QueryBuilder instance.

Jump to

Keyboard shortcuts

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