From 9f508b90584ace4f7cdf3ccd10f9bb45e2b66361 Mon Sep 17 00:00:00 2001 From: loloicci Date: Mon, 24 Apr 2023 14:35:35 +0900 Subject: [PATCH] fix: simplify how to handle the message in wasmplus --- x/wasmplus/handler.go | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/x/wasmplus/handler.go b/x/wasmplus/handler.go index c16d175bc5..27ba050470 100644 --- a/x/wasmplus/handler.go +++ b/x/wasmplus/handler.go @@ -1,8 +1,6 @@ package wasmplus import ( - "strings" - "github.com/gogo/protobuf/proto" sdk "github.com/Finschia/finschia-sdk/types" @@ -18,19 +16,16 @@ func NewHandler(k wasmtypes.ContractOpsKeeper) sdk.Handler { wasmHandler := wasm.NewHandler(k) return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - res, err := wasmHandler(ctx, msg) - if err != nil && strings.Contains(err.Error(), "MsgStoreCodeAndInstantiateContract") { - // handle wasmplus service - msg2, ok := msg.(*types.MsgStoreCodeAndInstantiateContract) - if ok { - var ( - res proto.Message - err error - ) - res, err = msgServer.StoreCodeAndInstantiateContract(sdk.WrapSDKContext(ctx), msg2) - return sdk.WrapServiceResult(ctx, res, err) - } + var ( + res proto.Message + err error + ) + switch msg := msg.(type) { + case *types.MsgStoreCodeAndInstantiateContract: + res, err = msgServer.StoreCodeAndInstantiateContract(sdk.WrapSDKContext(ctx), msg) + default: + return wasmHandler(ctx, msg) } - return res, err + return sdk.WrapServiceResult(ctx, res, err) } }