docs: Code blocks in SDK docs are broken (#11189)
This commit is contained in:
@@ -28,11 +28,11 @@ It is possible for developers to define the order of execution between the `Begi
|
||||
|
||||
See an example implementation of `BeginBlocker` from the `distr` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/f33749263f4ecc796115ad6e789cb0f7cddf9148/x/distribution/abci.go#L14-L38>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/f33749263f4ecc796115ad6e789cb0f7cddf9148/x/distribution/abci.go#L14-L38
|
||||
|
||||
and an example implementation of `EndBlocker` from the `staking` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/f33749263f4ecc796115ad6e789cb0f7cddf9148/x/staking/abci.go#L22-L27>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/f33749263f4ecc796115ad6e789cb0f7cddf9148/x/staking/abci.go#L22-L27
|
||||
|
||||
## Next {hide}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ of errors is handled via the `types/errors` package.
|
||||
|
||||
Example:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.43.0/x/distribution/types/errors.go#L1-L21>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.43.0/x/distribution/types/errors.go#L1-L21
|
||||
|
||||
Each custom module error must provide the codespace, which is typically the module name
|
||||
(e.g. "distribution") and is unique per module, and a uint32 code. Together, the codespace and code
|
||||
@@ -38,7 +38,7 @@ execution.
|
||||
|
||||
Example:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/b2d48a9e815fe534a7faeec6ca2adb0874252b81/x/bank/keeper/keeper.go#L85-L122>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/b2d48a9e815fe534a7faeec6ca2adb0874252b81/x/bank/keeper/keeper.go#L85-L122
|
||||
|
||||
Regardless if an error is wrapped or not, the Cosmos SDK's `errors` package provides an API to determine if
|
||||
an error is of a particular kind via `Is`.
|
||||
|
||||
@@ -17,7 +17,7 @@ The subset of the genesis state defined from a given module is generally defined
|
||||
|
||||
See an example of `GenesisState` protobuf message definition from the `auth` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/a9547b54ffac9729fe1393651126ddfc0d236cff/proto/cosmos/auth/v1beta1/genesis.proto>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/a9547b54ffac9729fe1393651126ddfc0d236cff/proto/cosmos/auth/v1beta1/genesis.proto
|
||||
|
||||
Next we present the main genesis-related methods that need to be implemented by module developers in order for their module to be used in Cosmos SDK applications.
|
||||
|
||||
@@ -25,13 +25,13 @@ Next we present the main genesis-related methods that need to be implemented by
|
||||
|
||||
The `DefaultGenesis()` method is a simple method that calls the constructor function for `GenesisState` with the default value for each parameter. See an example from the `auth` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/64b6bb5270e1a3b688c2d98a8f481ae04bb713ca/x/auth/module.go#L48-L52>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/64b6bb5270e1a3b688c2d98a8f481ae04bb713ca/x/auth/module.go#L48-L52
|
||||
|
||||
### `ValidateGenesis`
|
||||
|
||||
The `ValidateGenesis(genesisState GenesisState)` method is called to verify that the provided `genesisState` is correct. It should perform validity checks on each of the parameters listed in `GenesisState`. See an example from the `auth` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/64b6bb5270e1a3b688c2d98a8f481ae04bb713ca/x/auth/types/genesis.go#L57-L70>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/64b6bb5270e1a3b688c2d98a8f481ae04bb713ca/x/auth/types/genesis.go#L57-L70
|
||||
|
||||
## Other Genesis Methods
|
||||
|
||||
@@ -45,7 +45,7 @@ The [module manager](./module-manager.md#manager) of the application is responsi
|
||||
|
||||
See an example of `InitGenesis` from the `auth` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/64b6bb5270e1a3b688c2d98a8f481ae04bb713ca/x/auth/genesis.go#L13-L28>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/64b6bb5270e1a3b688c2d98a8f481ae04bb713ca/x/auth/genesis.go#L13-L28
|
||||
|
||||
### `ExportGenesis`
|
||||
|
||||
@@ -53,7 +53,7 @@ The `ExportGenesis` method is executed whenever an export of the state is made.
|
||||
|
||||
See an example of `ExportGenesis` from the `auth` module.
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/64b6bb5270e1a3b688c2d98a8f481ae04bb713ca/x/auth/genesis.go#L31-L42>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/64b6bb5270e1a3b688c2d98a8f481ae04bb713ca/x/auth/genesis.go#L31-L42
|
||||
|
||||
## Next {hide}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ An invariant is a property of the application that should always be true. In the
|
||||
|
||||
An `Invariant` is a function that checks for a particular invariant within a module. Module `Invariant`s must follow the `Invariant` type:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/7d7821b9af132b0f6131640195326aa02b6751db/types/invariant.go#L9>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/7d7821b9af132b0f6131640195326aa02b6751db/types/invariant.go#L9
|
||||
|
||||
The `string` return value is the invariant message, which can be used when printing logs, and the `bool` return value is the actual result of the invariant check.
|
||||
|
||||
@@ -69,17 +69,17 @@ The `InvariantRegistry` is a registry where the `Invariant`s of all the modules
|
||||
|
||||
At its core, the `InvariantRegistry` is defined in the Cosmos SDK as an interface:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/7d7821b9af132b0f6131640195326aa02b6751db/types/invariant.go#L14-L17>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/7d7821b9af132b0f6131640195326aa02b6751db/types/invariant.go#L14-L17
|
||||
|
||||
Typically, this interface is implemented in the `keeper` of a specific module. The most used implementation of an `InvariantRegistry` can be found in the `crisis` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.42.1/x/crisis/keeper/keeper.go#L50-L54>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.42.1/x/crisis/keeper/keeper.go#L50-L54
|
||||
|
||||
The `InvariantRegistry` is therefore typically instantiated by instantiating the `keeper` of the `crisis` module in the [application's constructor function](../basics/app-anatomy.md#constructor-function).
|
||||
|
||||
`Invariant`s can be checked manually via [`message`s](./messages-and-queries.md), but most often they are checked automatically at the end of each block. Here is an example from the `crisis` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/7d7821b9af132b0f6131640195326aa02b6751db/x/crisis/abci.go#L7-L14>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/7d7821b9af132b0f6131640195326aa02b6751db/x/crisis/abci.go#L7-L14
|
||||
|
||||
In both cases, if one of the `Invariant`s returns false, the `InvariantRegistry` can trigger special logic (e.g. have the application panic and print the `Invariant`s message in the log).
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ type Keeper struct {
|
||||
|
||||
For example, here is the type definition of the `keeper` from the `staking` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/staking/keeper/keeper.go#L23-L33>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/staking/keeper/keeper.go#L23-L33
|
||||
|
||||
Let us go through the different parameters:
|
||||
|
||||
@@ -78,7 +78,7 @@ The [module `KVStore`](../core/store.md#kvstore-and-commitkvstore-interfaces) al
|
||||
|
||||
This is an example from the `auth` module to iterate accounts:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/bf8809ef9840b4f5369887a38d8345e2380a567f/x/auth/keeper/account.go#L70-L83>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/bf8809ef9840b4f5369887a38d8345e2380a567f/x/auth/keeper/account.go#L70-L83
|
||||
|
||||
## Next {hide}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ Starting from v0.40, defining Protobuf `Msg` services is the recommended way to
|
||||
|
||||
See an example of a `Msg` service definition from `x/bank` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/proto/cosmos/bank/v1beta1/tx.proto#L10-L17>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/proto/cosmos/bank/v1beta1/tx.proto#L10-L17
|
||||
|
||||
Each `Msg` service method must have exactly one argument, which must implement the `sdk.Msg` interface, and a Protobuf response. The naming convention is to call the RPC argument `Msg<service-rpc-name>` and the RPC response `Msg<service-rpc-name>Response`. For example:
|
||||
|
||||
@@ -49,7 +49,7 @@ Amino `LegacyMsg`s can be defined as protobuf messages. The messages definition
|
||||
|
||||
A `LegacyMsg` is typically accompanied by a standard constructor function, that is called from one of the [module's interface](./module-interfaces.md). `message`s also need to implement the `sdk.Msg` interface:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/4a1b2fba43b1052ca162b3a1e0b6db6db9c26656/types/tx_msg.go#L10-L33>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/4a1b2fba43b1052ca162b3a1e0b6db6db9c26656/types/tx_msg.go#L10-L33
|
||||
|
||||
It extends `proto.Message` and contains the following methods:
|
||||
|
||||
@@ -61,7 +61,7 @@ It extends `proto.Message` and contains the following methods:
|
||||
|
||||
See an example implementation of a `message` from the `gov` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/x/gov/types/msgs.go#L77-L125>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/x/gov/types/msgs.go#L77-L125
|
||||
|
||||
## Queries
|
||||
|
||||
@@ -73,7 +73,7 @@ Starting from v0.40, the prefered way to define queries is by using [Protobuf se
|
||||
|
||||
Here's an example of such a `Query` service definition:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/d55c1a26657a0af937fa2273b38dcfa1bb3cff9f/proto/cosmos/auth/v1beta1/query.proto#L12-L23>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/d55c1a26657a0af937fa2273b38dcfa1bb3cff9f/proto/cosmos/auth/v1beta1/query.proto#L12-L23
|
||||
|
||||
As `proto.Message`s, generated `Response` types implement by default `String()` method of [`fmt.Stringer`](https://golang.org/pkg/fmt/#Stringer).
|
||||
|
||||
@@ -106,9 +106,9 @@ Store queries query directly for store keys. They use `clientCtx.QueryABCI(req a
|
||||
|
||||
See following examples:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/080fcf1df25ccdf97f3029b6b6f83caaf5a235e4/x/ibc/core/client/query.go#L36-L46>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/080fcf1df25ccdf97f3029b6b6f83caaf5a235e4/x/ibc/core/client/query.go#L36-L46
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/080fcf1df25ccdf97f3029b6b6f83caaf5a235e4/baseapp/abci.go#L722-L749>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/080fcf1df25ccdf97f3029b6b6f83caaf5a235e4/baseapp/abci.go#L722-L749
|
||||
|
||||
## Next {hide}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ One of the main interfaces for an application is the [command-line interface](..
|
||||
|
||||
Here is an example from the `x/bank` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/x/bank/client/cli/tx.go#L28-L63>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/x/bank/client/cli/tx.go#L28-L63
|
||||
|
||||
In the example, `NewSendTxCmd()` creates and returns the transaction command for a transaction that wraps and delivers `MsgSend`. `MsgSend` is the message used to send tokens from one account to another.
|
||||
|
||||
@@ -42,17 +42,17 @@ In general, the getter function does the following:
|
||||
|
||||
Each module must implement `NewTxCmd()`, which aggregates all of the transaction commands of the module. Here is an example from the `x/bank` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/x/bank/client/cli/tx.go#L13-L26>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/x/bank/client/cli/tx.go#L13-L26
|
||||
|
||||
Each module must also implement the `GetTxCmd()` method for `AppModuleBasic` that simply returns `NewTxCmd()`. This allows the root command to easily aggregate all of the transaction commands for each module. Here is an example:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/x/bank/module.go#L75-L78>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/x/bank/module.go#L75-L78
|
||||
|
||||
### Query Commands
|
||||
|
||||
[Queries](./messages-and-queries.md#queries) allow users to gather information about the application or network state; they are routed by the application and processed by the module in which they are defined. Query commands typically have their own `query.go` file in the module's `./client/cli` folder. Like transaction commands, they are specified in getter functions. Here is an example of a query command from the `x/auth` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/x/auth/client/cli/query.go#L75-L105>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/x/auth/client/cli/query.go#L75-L105
|
||||
|
||||
In the example, `GetAccountCmd()` creates and returns a query command that returns the state of an account based on the provided account address.
|
||||
|
||||
@@ -72,11 +72,11 @@ In general, the getter function does the following:
|
||||
|
||||
Each module must implement `GetQueryCmd()`, which aggregates all of the query commands of the module. Here is an example from the `x/auth` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/x/auth/client/cli/query.go#L25-L42>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/x/auth/client/cli/query.go#L25-L42
|
||||
|
||||
Each module must also implement the `GetQueryCmd()` method for `AppModuleBasic` that returns the `GetQueryCmd()` function. This allows for the root command to easily aggregate all of the query commands for each module. Here is an example:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/x/auth/module.go#L80-L83>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/x/auth/module.go#L80-L83
|
||||
|
||||
### Flags
|
||||
|
||||
@@ -102,13 +102,13 @@ For more detailed information on creating flags, visit the [Cobra Documentation]
|
||||
|
||||
As mentioned in [transaction commands](#transaction-commands), there is a set of flags that all transaction commands must add. This is done with the `AddTxFlagsToCmd` method defined in the Cosmos SDK's `./client/flags` package.
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/client/flags/flags.go#L94-L120>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/client/flags/flags.go#L94-L120
|
||||
|
||||
Since `AddTxFlagsToCmd(cmd *cobra.Command)` includes all of the basic flags required for a transaction command, module developers may choose not to add any of their own (specifying arguments instead may often be more appropriate).
|
||||
|
||||
Similarly, there is a `AddQueryFlagsToCmd(cmd *cobra.Command)` to add common flags to a module query command.
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/client/flags/flags.go#L85-L92>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/client/flags/flags.go#L85-L92
|
||||
|
||||
## gRPC
|
||||
|
||||
@@ -120,7 +120,7 @@ In order to do that, modules must implement `RegisterGRPCGatewayRoutes(clientCtx
|
||||
|
||||
Here's an example from the `x/auth` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/x/auth/module.go#L68-L73>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/x/auth/module.go#L68-L73
|
||||
|
||||
## gRPC-gateway REST
|
||||
|
||||
@@ -128,7 +128,7 @@ Applications need to support web services that use HTTP requests (e.g. a web wal
|
||||
|
||||
Modules that want to expose REST queries should add `google.api.http` annotations to their `rpc` methods, such as in the example below from the `x/auth` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/proto/cosmos/auth/v1beta1/query.proto#L13-L29>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/proto/cosmos/auth/v1beta1/query.proto#L13-L29
|
||||
|
||||
gRPC gateway is started in-process along with the application and Tendermint. It can be enabled or disabled by setting gRPC Configuration `enable` in [`app.toml`](../run-node/run-node.md#configuring-the-node-using-apptoml).
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ are only used for genesis can take advantage of the `Module` patterns without ha
|
||||
|
||||
The `AppModuleBasic` interface defines the independent methods modules need to implement.
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/325be6ff215db457c6fc7668109640cd7fdac461/types/module/module.go#L49-L63>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/325be6ff215db457c6fc7668109640cd7fdac461/types/module/module.go#L49-L63
|
||||
|
||||
Let us go through the methods:
|
||||
|
||||
@@ -49,7 +49,7 @@ All the `AppModuleBasic` of an application are managed by the [`BasicManager`](#
|
||||
|
||||
The `AppModuleGenesis` interface is a simple embedding of the `AppModuleBasic` interface with two added methods.
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/325be6ff215db457c6fc7668109640cd7fdac461/types/module/module.go#L152-L158>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/325be6ff215db457c6fc7668109640cd7fdac461/types/module/module.go#L152-L158
|
||||
|
||||
Let us go through the two added methods:
|
||||
|
||||
@@ -62,7 +62,7 @@ It does not have its own manager, and exists separately from [`AppModule`](#appm
|
||||
|
||||
The `AppModule` interface defines the inter-dependent methods that modules need to implement.
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/b4cce159bcc6a32ac78245c6866dd87c73f3720d/types/module/module.go#L160-L182>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/b4cce159bcc6a32ac78245c6866dd87c73f3720d/types/module/module.go#L160-L182
|
||||
|
||||
`AppModule`s are managed by the [module manager](#manager). This interface embeds the `AppModuleGenesis` interface so that the manager can access all the independent and genesis inter-dependent methods of the module. This means that a concrete type implementing the `AppModule` interface must either implement all the methods of `AppModuleGenesis` (and by extension `AppModuleBasic`), or include a concrete type that does as parameter.
|
||||
|
||||
@@ -106,7 +106,7 @@ Module managers are used to manage collections of `AppModuleBasic` and `AppModul
|
||||
|
||||
The `BasicManager` is a structure that lists all the `AppModuleBasic` of an application:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/325be6ff215db457c6fc7668109640cd7fdac461/types/module/module.go#L65-L66>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/325be6ff215db457c6fc7668109640cd7fdac461/types/module/module.go#L65-L66
|
||||
|
||||
It implements the following methods:
|
||||
|
||||
@@ -124,7 +124,7 @@ It implements the following methods:
|
||||
|
||||
The `Manager` is a structure that holds all the `AppModule` of an application, and defines the order of execution between several key components of these modules:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/325be6ff215db457c6fc7668109640cd7fdac461/types/module/module.go#L223-L231>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/325be6ff215db457c6fc7668109640cd7fdac461/types/module/module.go#L223-L231
|
||||
|
||||
The module manager is used throughout the application whenever an action on a collection of modules is required. It implements the following methods:
|
||||
|
||||
@@ -143,7 +143,7 @@ The module manager is used throughout the application whenever an action on a co
|
||||
|
||||
Here's an example of a concrete integration within an application:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/2323f1ac0e9a69a0da6b43693061036134193464/simapp/app.go#L315-L362>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/2323f1ac0e9a69a0da6b43693061036134193464/simapp/app.go#L315-L362
|
||||
|
||||
## Next {hide}
|
||||
|
||||
|
||||
@@ -19,15 +19,15 @@ As further described in [ADR 031](../architecture/adr-031-msg-service.md), this
|
||||
|
||||
Protobuf generates a `MsgServer` interface based on a definition of `Msg` service. It is the role of the module developer to implement this interface, by implementing the state transition logic that should happen upon receival of each `sdk.Msg`. As an example, here is the generated `MsgServer` interface for `x/bank`, which exposes two `sdk.Msg`s:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc3/x/bank/types/tx.pb.go#L285-L291>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc3/x/bank/types/tx.pb.go#L285-L291
|
||||
|
||||
When possible, the existing module's [`Keeper`](keeper.md) should implement `MsgServer`, otherwise a `msgServer` struct that embeds the `Keeper` can be created, typically in `./keeper/msg_server.go`:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/x/bank/keeper/msg_server.go#L14-L16>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/x/bank/keeper/msg_server.go#L14-L16
|
||||
|
||||
`msgServer` methods can retrieve the `sdk.Context` from the `context.Context` parameter method using the `sdk.UnwrapSDKContext`:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/x/bank/keeper/msg_server.go#L27-L28>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/x/bank/keeper/msg_server.go#L27-L28
|
||||
|
||||
`sdk.Msg` processing usually follows these 3 steps:
|
||||
|
||||
@@ -77,11 +77,11 @@ These events are relayed back to the underlying consensus engine and can be used
|
||||
|
||||
The invoked `msgServer` method returns a `proto.Message` response and an `error`. These return values are then wrapped into an `*sdk.Result` or an `error` using `sdk.WrapServiceResult(ctx sdk.Context, res proto.Message, err error)`:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc2/baseapp/msg_service_router.go#L104-L104>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc2/baseapp/msg_service_router.go#L104-L104
|
||||
|
||||
This method takes care of marshaling the `res` parameter to protobuf and attaching any events on the `ctx.EventManager()` to the `sdk.Result`.
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/d55c1a26657a0af937fa2273b38dcfa1bb3cff9f/proto/cosmos/base/abci/v1beta1/abci.proto#L81-L95>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/d55c1a26657a0af937fa2273b38dcfa1bb3cff9f/proto/cosmos/base/abci/v1beta1/abci.proto#L81-L95
|
||||
|
||||
This diagram shows a typical structure of a Protobuf `Msg` service, and how the message propagates through the module.
|
||||
|
||||
@@ -95,7 +95,7 @@ The `handler` type defined in the Cosmos SDK will be deprecated in favor of [`Ms
|
||||
|
||||
Here is the typical structure of a `handler` function:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc2/types/handler.go#L4-L4>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc2/types/handler.go#L4-L4
|
||||
|
||||
Let us break it down:
|
||||
|
||||
@@ -107,13 +107,13 @@ Module `handler`s are typically implemented in a `./handler.go` file inside the
|
||||
[application's `router`](../core/baseapp.md#message-routing) via the `Route()` method. Typically,
|
||||
the manager's `Route()` method simply constructs a Route that calls a `NewHandler()` method defined in `handler.go`.
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/228728cce2af8d494c8b4e996d011492139b04ab/x/gov/module.go#L143-L146>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/228728cce2af8d494c8b4e996d011492139b04ab/x/gov/module.go#L143-L146
|
||||
|
||||
### Implementation
|
||||
|
||||
`NewHandler` function dispatches a `LegacyMsg` to appropriate handler function, usually by using a switch statement:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/d55c1a26657a0af937fa2273b38dcfa1bb3cff9f/x/bank/handler.go#L13-L29>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/d55c1a26657a0af937fa2273b38dcfa1bb3cff9f/x/bank/handler.go#L13-L29
|
||||
|
||||
First, `NewHandler` function sets a new `EventManager` to the context to isolate events per `msg`.
|
||||
Then, a simple switch calls the appropriate `handler` based on the `LegacyMsg` type.
|
||||
@@ -127,7 +127,7 @@ New [telemetry metrics](../core/telemetry.md) can be created from `msgServer` me
|
||||
|
||||
This is an example from the `x/auth/vesting` module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/x/auth/vesting/msg_server.go#L73-L85>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0-rc1/x/auth/vesting/msg_server.go#L73-L85
|
||||
|
||||
## Next {hide}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ A Protobuf Query service processes [`queries`](./messages-and-queries.md#queries
|
||||
|
||||
The `querier` type defined in the Cosmos SDK will be deprecated in favor of [gRPC Services](#grpc-service). It specifies the typical structure of a `querier` function:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/9a183ffbcc0163c8deb71c7fd5f8089a83e58f05/types/queryable.go#L9>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/9a183ffbcc0163c8deb71c7fd5f8089a83e58f05/types/queryable.go#L9
|
||||
|
||||
Let us break it down:
|
||||
|
||||
@@ -43,7 +43,7 @@ from the store. Therefore, the Cosmos SDK provides a function `sdk.UnwrapSDKCont
|
||||
|
||||
Here's an example implementation for the bank module:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/d55c1a26657a0af937fa2273b38dcfa1bb3cff9f/x/bank/keeper/grpc_query.go>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/d55c1a26657a0af937fa2273b38dcfa1bb3cff9f/x/bank/keeper/grpc_query.go
|
||||
|
||||
### Legacy Queriers
|
||||
|
||||
|
||||
@@ -62,13 +62,13 @@ Operations on the simulation are simulated using the full [transaction cycle](..
|
||||
|
||||
Shown below is how weights are set:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.42.1/x/staking/simulation/operations.go#L18-L68>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.42.1/x/staking/simulation/operations.go#L18-L68
|
||||
|
||||
As you can see, the weights are predefined in this case. Options exist to override this behavior with different weights. One option is to use `*rand.Rand` to define a random weight for the operation, or you can inject your own predefined weights.
|
||||
|
||||
Here is how one can override the above package `simappparams`.
|
||||
|
||||
+++ <https://github.com/cosmos/gaia/blob/master/sims.mk#L9-L22>
|
||||
+++ https://github.com/cosmos/gaia/blob/master/sims.mk#L9-L22
|
||||
|
||||
For the last test a tool called runsim <!-- # TODO: add link to runsim readme when its created --> is used, this is used to parallelize go test instances, provide info to Github and slack integrations to provide information to your team on how the simulations are running.
|
||||
|
||||
@@ -82,7 +82,7 @@ them to be used on the parameters.
|
||||
|
||||
Now that all the required functions are defined, we need to integrate them into the module pattern within the `module.go`:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/v0.42.0/x/distribution/module.go>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/v0.42.0/x/distribution/module.go
|
||||
|
||||
## App Simulator manager
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
|
||||
Since these migrations are functions that need access to a Keeper's store, use a wrapper around the keepers called `Migrator` as shown in this example:
|
||||
|
||||
+++ <https://github.com/cosmos/cosmos-sdk/blob/6ac8898fec9bd7ea2c1e5c79e0ed0c3f827beb55/x/bank/keeper/migrations.go#L8-L21>
|
||||
+++ https://github.com/cosmos/cosmos-sdk/blob/6ac8898fec9bd7ea2c1e5c79e0ed0c3f827beb55/x/bank/keeper/migrations.go#L8-L21
|
||||
|
||||
## Writing Migration Scripts
|
||||
|
||||
|
||||
Reference in New Issue
Block a user