Documentation ¶
Index ¶
- Variables
- func Equal(a, b transaction.Msg) bool
- func ExecModule(ctx context.Context, msg transaction.Msg) (transaction.Msg, error)
- func FindMessageByName(name string) (transaction.Msg, error)
- func Funds(ctx context.Context) sdk.Coins
- func IsRoutingError(err error) bool
- func MakeAccountContext(ctx context.Context, storeSvc store.KVStoreService, accNumber uint64, ...) context.Context
- func MakeAccountsMap(cdc codec.Codec, addressCodec address.Codec, env appmodule.Environment, ...) (map[string]Implementation, error)
- func Merge(a, b transaction.Msg)
- func MessageName(msg transaction.Msg) string
- func QueryModule(ctx context.Context, req transaction.Msg) (transaction.Msg, error)
- func RegisterExecuteHandler[Req any, ProtoReq ProtoMsgG[Req], Resp any, ProtoResp ProtoMsgG[Resp]](router *ExecuteBuilder, ...)
- func RegisterInitHandler[Req any, ProtoReq ProtoMsgG[Req], Resp any, ProtoResp ProtoMsgG[Resp]](router *InitBuilder, ...)
- func RegisterQueryHandler[Req any, ProtoReq ProtoMsgG[Req], Resp any, ProtoResp ProtoMsgG[Resp]](router *QueryBuilder, ...)
- func Sender(ctx context.Context) []byte
- func SetSender(ctx context.Context, sender []byte) context.Context
- func UnpackAny[T any, PT ProtoMsgG[T]](anyPB *Any) (PT, error)
- func UnpackAnyRaw(anyPB *Any) (proto.Message, error)
- func UnpackAnyTo(anyPB *Any, to transaction.Msg) error
- func Whoami(ctx context.Context) []byte
- type Account
- type AccountCreatorFunc
- type Any
- type Dependencies
- type ExecuteBuilder
- type HandlerSchema
- type Implementation
- type InitBuilder
- type MessageSchema
- type ModuleExecFunc
- type ModuleQueryFunc
- type ProtoMsgG
- type QueryBuilder
Constants ¶
This section is empty.
Variables ¶
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 IsRoutingError ¶
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 UnpackAnyTo ¶
func UnpackAnyTo(anyPB *Any, to transaction.Msg) error
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
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.