From 6e5476797fb2111f48ddc8cd4380ae1eaf6e70b1 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Sun, 16 Jul 2023 21:18:30 +0200 Subject: [PATCH 1/4] docs on getsigner --- docs/docs/building-modules/02-messages-and-queries.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/docs/building-modules/02-messages-and-queries.md b/docs/docs/building-modules/02-messages-and-queries.md index a7d7fba0e5e6..9e56c3d06a55 100644 --- a/docs/docs/building-modules/02-messages-and-queries.md +++ b/docs/docs/building-modules/02-messages-and-queries.md @@ -40,6 +40,15 @@ Each `Msg` service method must have exactly one argument, which must implement t `sdk.Msg` interface is a simplified version of the Amino `LegacyMsg` interface described [below](#legacy-amino-msgs) with the `GetSigners()` method. For backwards compatibility with [Amino `LegacyMsg`s](#legacy-amino-msgs), existing `LegacyMsg` types should be used as the request parameter for `service` RPC definitions. Newer `sdk.Msg` types, which only support `service` definitions, should use canonical `Msg...` name. +`sdk.Msg` is a alias of `proto.Message`. To attach a `ValidateBasic()` and/or `GetSigners()` method to a message then you must add methods to the type adhereing to the `HasValidateBasic` and/or + + + +```go reference +https://github.com/cosmos/cosmos-sdk/blob/9c1e8b247cd47b5d3decda6e86fbc3bc996ee5d7/types/tx_msg.go#L84-L89 +``` + + The Cosmos SDK uses Protobuf definitions to generate client and server code: * `MsgServer` interface defines the server API for the `Msg` service and its implementation is described as part of the [`Msg` services](./03-msg-services.md) documentation. From 1c8765fd6d6ceabd810d986981d91f95e9c52634 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 30 Aug 2023 15:42:21 +0200 Subject: [PATCH 2/4] add docs on how to use custom signers --- .../02-messages-and-queries.md | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/docs/docs/building-modules/02-messages-and-queries.md b/docs/docs/building-modules/02-messages-and-queries.md index 9363120f91dc..3dbe1a957d0c 100644 --- a/docs/docs/building-modules/02-messages-and-queries.md +++ b/docs/docs/building-modules/02-messages-and-queries.md @@ -38,14 +38,39 @@ Each `Msg` service method must have exactly one argument, which must implement t `sdk.Msg` interface is a simplified version of the Amino `LegacyMsg` interface described [below](#legacy-amino-msgs) with the `GetSigners()` method. For backwards compatibility with [Amino `LegacyMsg`s](#legacy-amino-msgs), existing `LegacyMsg` types should be used as the request parameter for `service` RPC definitions. Newer `sdk.Msg` types, which only support `service` definitions, should use canonical `Msg...` name. -`sdk.Msg` is a alias of `proto.Message`. To attach a `ValidateBasic()` and/or `GetSigners()` method to a message then you must add methods to the type adhereing to the `HasValidateBasic` and/or - - +`sdk.Msg` is a alias of `proto.Message`. To attach a `ValidateBasic()` method to a message then you must add methods to the type adhereing to the `HasValidateBasic`. ```go reference https://github.com/cosmos/cosmos-sdk/blob/9c1e8b247cd47b5d3decda6e86fbc3bc996ee5d7/types/tx_msg.go#L84-L89 ``` +In 0.50+ signers from the `GetSigners()` call is automated via a protobuf annotation. + +```protobuf reference +https://github.com/cosmos/cosmos-sdk/blob/e6848d99b55a65d014375b295bdd7f9641aac95e/proto/cosmos/bank/v1beta1/tx.proto#L41 +``` + +If there is a need for custom signers then there is an alternative path which can be taken. A function which returns `signing.CustomGetSigner` for a specific message can be defined. + +```go +func ProvideBankSendTransactionGetSigners() signing.CustomGetSigner { + + // Extract the signer from the signature. + signer, err := coretypes.LatestSigner(Tx).Sender(ethTx) + if err != nil { + return nil, err + } + + // Return the signer in the required format. + return [][]byte{signer.Bytes()}, nil +} +``` + +When using dependency injection (depinject) this can be provided to the application via the provide method. + +```go +depinject.Provide(banktypes.ProvideBankSendTransactionGetSigners) +``` The Cosmos SDK uses Protobuf definitions to generate client and server code: From 84d18537d81dc09fa2e6552b670733eda02fda19 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Thu, 31 Aug 2023 22:00:16 +0200 Subject: [PATCH 3/4] change wording --- .../02-messages-and-queries.md | 46 ++++++------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/docs/docs/building-modules/02-messages-and-queries.md b/docs/docs/building-modules/02-messages-and-queries.md index 3dbe1a957d0c..77dc8d5c871f 100644 --- a/docs/docs/building-modules/02-messages-and-queries.md +++ b/docs/docs/building-modules/02-messages-and-queries.md @@ -24,11 +24,6 @@ When a transaction is relayed from the underlying consensus engine to the Cosmos Defining Protobuf `Msg` services is the recommended way to handle messages. A Protobuf `Msg` service should be created for each module, typically in `tx.proto` (see more info about [conventions and naming](../core/05-encoding.md#faq)). It must have an RPC service method defined for each message in the module. -See an example of a `Msg` service definition from `x/bank` module: - -```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/proto/cosmos/bank/v1beta1/tx.proto#L13-L36 -``` 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` and the RPC response `MsgResponse`. For example: @@ -36,16 +31,26 @@ Each `Msg` service method must have exactly one argument, which must implement t rpc Send(MsgSend) returns (MsgSendResponse); ``` -`sdk.Msg` interface is a simplified version of the Amino `LegacyMsg` interface described [below](#legacy-amino-msgs) with the `GetSigners()` method. For backwards compatibility with [Amino `LegacyMsg`s](#legacy-amino-msgs), existing `LegacyMsg` types should be used as the request parameter for `service` RPC definitions. Newer `sdk.Msg` types, which only support `service` definitions, should use canonical `Msg...` name. +See an example of a `Msg` service definition from `x/bank` module: + +```protobuf reference +https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/proto/cosmos/bank/v1beta1/tx.proto#L13-L36 +``` + +#### `sdk.Msg` Interface -`sdk.Msg` is a alias of `proto.Message`. To attach a `ValidateBasic()` method to a message then you must add methods to the type adhereing to the `HasValidateBasic`. +`sdk.Msg` is a alias of `proto.Message`. + +To attach a `ValidateBasic()` method to a message then you must add methods to the type adhereing to the `HasValidateBasic`. ```go reference -https://github.com/cosmos/cosmos-sdk/blob/9c1e8b247cd47b5d3decda6e86fbc3bc996ee5d7/types/tx_msg.go#L84-L89 +https://github.com/cosmos/cosmos-sdk/blob/9c1e8b247cd47b5d3decda6e86fbc3bc996ee5d7/types/tx_msg.go#L84-L88 ``` In 0.50+ signers from the `GetSigners()` call is automated via a protobuf annotation. + + ```protobuf reference https://github.com/cosmos/cosmos-sdk/blob/e6848d99b55a65d014375b295bdd7f9641aac95e/proto/cosmos/bank/v1beta1/tx.proto#L41 ``` @@ -81,31 +86,6 @@ A `RegisterMsgServer` method is also generated and should be used to register th In order for clients (CLI and grpc-gateway) to have these URLs registered, the Cosmos SDK provides the function `RegisterMsgServiceDesc(registry codectypes.InterfaceRegistry, sd *grpc.ServiceDesc)` that should be called inside module's [`RegisterInterfaces`](01-module-manager.md#appmodulebasic) method, using the proto-generated `&_Msg_serviceDesc` as `*grpc.ServiceDesc` argument. -### Legacy Amino `LegacyMsg`s - -The following way of defining messages is deprecated and using [`Msg` services](#msg-services) is preferred. - -Amino `LegacyMsg`s can be defined as protobuf messages. The messages definition usually includes a list of parameters needed to process the message that will be provided by end-users when they want to create a new transaction containing said message. - -A `LegacyMsg` is typically accompanied by a standard constructor function, that is called from one of the [module's interface](./09-module-interfaces.md). `message`s also need to implement the `sdk.Msg` interface: - -```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/tx_msg.go#L21-L28 -``` - -It extends `proto.Message` and contains the following methods: - -* `GetSignBytes() []byte`: Return the canonical byte representation of the message. Used to generate a signature. - -```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/auth/migrations/legacytx/stdsign.go#L21-L29 -``` - -See an example implementation of a `message` from the `gov` module: - -```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/gov/types/v1/msgs.go#L103-L150 -``` ## Queries From 79095372f86bac401f6a704bdda7fba849243c70 Mon Sep 17 00:00:00 2001 From: Marko Date: Tue, 5 Sep 2023 09:18:37 +0200 Subject: [PATCH 4/4] Update docs/docs/building-modules/02-messages-and-queries.md Co-authored-by: samricotta <37125168+samricotta@users.noreply.github.com> --- docs/docs/building-modules/02-messages-and-queries.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/building-modules/02-messages-and-queries.md b/docs/docs/building-modules/02-messages-and-queries.md index 77dc8d5c871f..a175216c3488 100644 --- a/docs/docs/building-modules/02-messages-and-queries.md +++ b/docs/docs/building-modules/02-messages-and-queries.md @@ -37,7 +37,7 @@ See an example of a `Msg` service definition from `x/bank` module: https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/proto/cosmos/bank/v1beta1/tx.proto#L13-L36 ``` -#### `sdk.Msg` Interface +### `sdk.Msg` Interface `sdk.Msg` is a alias of `proto.Message`.