From 8e6c32de503ac907fe4c06fd83b8494934e3464f Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Fri, 24 Nov 2023 12:41:54 +0900 Subject: [PATCH] change decoder to decode block-sdk first tx to empty tx --- app/app.go | 12 ++++++------ app/params/config.go | 39 +++++++++++++++++++++++++++++++++++++++ app/params/proto.go | 2 +- 3 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 app/params/config.go diff --git a/app/app.go b/app/app.go index 8b2f9c1..a0375db 100644 --- a/app/app.go +++ b/app/app.go @@ -98,7 +98,7 @@ import ( ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" // initia imports - initiaservice "github.com/initia-labs/initia/service" + ibctestingtypes "github.com/initia-labs/initia/x/ibc/testing/types" icaauth "github.com/initia-labs/initia/x/intertx" icaauthkeeper "github.com/initia-labs/initia/x/intertx/keeper" @@ -993,17 +993,17 @@ func (app *MinitiaApp) Simulate(txBytes []byte) (sdk.GasInfo, *sdk.Result, error // RegisterTxService implements the Application.RegisterTxService method. func (app *MinitiaApp) RegisterTxService(clientCtx client.Context) { - initiaservice.RegisterTxService( + authtx.RegisterTxService( app.BaseApp.GRPCQueryRouter(), clientCtx, - authtx.NewTxServer(clientCtx, app.Simulate, app.interfaceRegistry), + app.Simulate, app.interfaceRegistry, ) } // RegisterTendermintService implements the Application.RegisterTendermintService method. func (app *MinitiaApp) RegisterTendermintService(clientCtx client.Context) { - initiaservice.RegisterTendermintService( - app.BaseApp.GRPCQueryRouter(), - tmservice.NewQueryServer(clientCtx, app.interfaceRegistry, app.Query), + tmservice.RegisterTendermintService( + clientCtx, app.BaseApp.GRPCQueryRouter(), + app.interfaceRegistry, app.Query, ) } diff --git a/app/params/config.go b/app/params/config.go new file mode 100644 index 0000000..8c8860b --- /dev/null +++ b/app/params/config.go @@ -0,0 +1,39 @@ +package params + +import ( + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" + authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" + + blockproposalstypes "github.com/skip-mev/block-sdk/block/proposals/types" +) + +type config struct { + client.TxConfig +} + +func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode) client.TxConfig { + return config{authtx.NewTxConfig(protoCodec, enabledSignModes)} +} + +func (g config) TxDecoder() sdk.TxDecoder { + return func(txBytes []byte) (sdk.Tx, error) { + if tx, err := g.TxConfig.TxDecoder()(txBytes); err != nil { + + // convert skip's custom message to empty tx + var metaData blockproposalstypes.ProposalInfo + if err := metaData.Unmarshal(txBytes); err == nil { + txbuilder := g.NewTxBuilder() + txbuilder.SetMemo("Tx is for BlockSDK") + + return txbuilder.GetTx(), err + } + + return tx, err + } else { + return tx, err + } + } +} diff --git a/app/params/proto.go b/app/params/proto.go index 84ff35a..2342dc2 100644 --- a/app/params/proto.go +++ b/app/params/proto.go @@ -11,7 +11,7 @@ func MakeEncodingConfig() EncodingConfig { amino := codec.NewLegacyAmino() interfaceRegistry := types.NewInterfaceRegistry() marshaler := codec.NewProtoCodec(interfaceRegistry) - txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes) + txCfg := NewTxConfig(marshaler, tx.DefaultSignModes) return EncodingConfig{ InterfaceRegistry: interfaceRegistry,