From e3718e06c9dd58f34fe55c9bebff16eda2abb274 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 12 Feb 2025 01:06:24 +0100 Subject: [PATCH] docs: correct explanation on how to set custom signer via depinject (#23654) Co-authored-by: John Letey --- .../02-messages-and-queries.md | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/build/building-modules/02-messages-and-queries.md b/docs/build/building-modules/02-messages-and-queries.md index 2b519c26c0..3c9d9c4493 100644 --- a/docs/build/building-modules/02-messages-and-queries.md +++ b/docs/build/building-modules/02-messages-and-queries.md @@ -54,22 +54,32 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.2/x/bank/proto/cosmos/ban 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 { +func ProvideCustomMsgTransactionGetSigners() signing.CustomGetSigner { // Extract the signer from the signature. signer, err := coretypes.LatestSigner(Tx).Sender(ethTx) - if err != nil { + if err != nil { return nil, err } // Return the signer in the required format. - return [][]byte{signer.Bytes()}, nil + return signing.CustomGetSigner{ + MsgType: protoreflect.FullName(gogoproto.MessageName(&types.CustomMsg{})), + Fn: func(msg proto.Message) ([][]byte, error) { + return [][]byte{signer}, nil + } + } } ``` -This can be provided to the application using depinject's `Provide` method in the application's `app.go`: +This can be provided to the application using depinject's `Provide` method in the module that defines the type: -```go -depinject.Provide(banktypes.ProvideBankSendTransactionGetSigners) +```diff +func init() { + appconfig.RegisterModule(&modulev1.Module{}, +- appconfig.Provide(ProvideModule), ++ appconfig.Provide(ProvideModule, ProvideCustomMsgTransactionGetSigners), + ) +} ``` The Cosmos SDK uses Protobuf definitions to generate client and server code: