From 86ccc34059dbb7c418df01da2557727ea8a5d707 Mon Sep 17 00:00:00 2001 From: zemyblue Date: Mon, 22 Aug 2022 16:14:16 +0900 Subject: [PATCH] fix: remove legacy codes of wasm (#640) * remove unused interface and struct in wasm (QueryRouter, Router) Signed-off-by: zemyblue * remove duplicated Event in the wasm proposal handler Signed-off-by: zemyblue * chore: add changelog Signed-off-by: zemyblue * fix: lint error Signed-off-by: zemyblue * chore: remove the message types event of governance process. Signed-off-by: zemyblue Signed-off-by: zemyblue --- CHANGELOG.md | 1 + x/wasm/alias.go | 3 -- x/wasm/keeper/msg_server.go | 4 -- x/wasm/keeper/proposal_handler.go | 52 +--------------------- x/wasm/types/events.go | 2 - x/wasm/types/querier_router.go | 65 ---------------------------- x/wasm/types/querier_router_test.go | 29 ------------- x/wasm/types/router.go | 67 ----------------------------- x/wasm/types/router_test.go | 27 ------------ 9 files changed, 2 insertions(+), 248 deletions(-) delete mode 100644 x/wasm/types/querier_router.go delete mode 100644 x/wasm/types/querier_router_test.go delete mode 100644 x/wasm/types/router.go delete mode 100644 x/wasm/types/router_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ed10e5fd7..cbb8341b38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (client) [\#565](https://github.com/line/lbm-sdk/pull/565) fix the data race problem in `TestQueryABCIHeight` * (x/token) [\#589](https://github.com/line/lbm-sdk/pull/589) fix naming collision in x/token enums * (x/token) [\#599](https://github.com/line/lbm-sdk/pull/599) fix the order of events +* (x/wasm) [\#640](https://github.com/line/lbm-sdk/pull/640) remove legacy codes of wasm * (amino) [\#635](https://github.com/line/lbm-sdk/pull/635) change some minor things that haven't been fixed in #549 ### Breaking Changes diff --git a/x/wasm/alias.go b/x/wasm/alias.go index dbd08d0607..457e07d0bd 100644 --- a/x/wasm/alias.go +++ b/x/wasm/alias.go @@ -126,7 +126,4 @@ type ( CustomQuerier = keeper.CustomQuerier QueryPlugins = keeper.QueryPlugins Option = keeper.Option - - EncodeHandler = types.EncodeHandler - EncodeQuerier = types.EncodeQuerier ) diff --git a/x/wasm/keeper/msg_server.go b/x/wasm/keeper/msg_server.go index d39f098c03..27d5fe454e 100644 --- a/x/wasm/keeper/msg_server.go +++ b/x/wasm/keeper/msg_server.go @@ -210,10 +210,6 @@ func (m msgServer) ClearAdmin(goCtx context.Context, msg *types.MsgClearAdmin) ( sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), )) - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypeUpdateAdmin, - sdk.NewAttribute(types.AttributeKeyContractAddr, msg.Contract), - )) if err := m.keeper.ClearContractAdmin(ctx, contractAddr, senderAddr); err != nil { return nil, err diff --git a/x/wasm/keeper/proposal_handler.go b/x/wasm/keeper/proposal_handler.go index 73c3b1c6b4..6f7ba4f3f3 100644 --- a/x/wasm/keeper/proposal_handler.go +++ b/x/wasm/keeper/proposal_handler.go @@ -2,8 +2,6 @@ package keeper import ( "encoding/hex" - "strconv" - "strings" sdk "github.com/line/lbm-sdk/types" sdkerrors "github.com/line/lbm-sdk/types/errors" @@ -182,17 +180,7 @@ func handleUpdateAdminProposal(ctx sdk.Context, k types.ContractOpsKeeper, p typ return sdkerrors.Wrap(err, "run as address") } - if err := k.UpdateContractAdmin(ctx, contractAddr, nil, newAdminAddr); err != nil { - return err - } - - ourEvent := sdk.NewEvent( - types.EventTypeUpdateAdmin, - sdk.NewAttribute(types.AttributeKeyContractAddr, p.Contract), - sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - ) - ctx.EventManager().EmitEvent(ourEvent) - return nil + return k.UpdateContractAdmin(ctx, contractAddr, nil, newAdminAddr) } func handleClearAdminProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.ClearAdminProposal) error { @@ -207,13 +195,6 @@ func handleClearAdminProposal(ctx sdk.Context, k types.ContractOpsKeeper, p type if err := k.ClearContractAdmin(ctx, contractAddr, nil); err != nil { return err } - - ourEvent := sdk.NewEvent( - types.EventTypeClearAdmin, - sdk.NewAttribute(types.AttributeKeyContractAddr, p.Contract), - sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - ) - ctx.EventManager().EmitEvent(ourEvent) return nil } @@ -226,22 +207,6 @@ func handlePinCodesProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types. return sdkerrors.Wrapf(err, "code id: %d", v) } } - s := make([]string, len(p.CodeIDs)) - for _, v := range p.CodeIDs { - ourEvent := sdk.NewEvent( - types.EventTypePinCode, - sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - sdk.NewAttribute(types.AttributeKeyCodeID, strconv.FormatUint(v, 10)), - ) - ctx.EventManager().EmitEvent(ourEvent) - } - - ourEvent := sdk.NewEvent( - types.EventTypePinCode, - sdk.NewAttribute(types.AttributeKeyCodeIDs, strings.Join(s, ",")), - ) - ctx.EventManager().EmitEvent(ourEvent) - return nil } @@ -254,21 +219,6 @@ func handleUnpinCodesProposal(ctx sdk.Context, k types.ContractOpsKeeper, p type return sdkerrors.Wrapf(err, "code id: %d", v) } } - s := make([]string, len(p.CodeIDs)) - for _, v := range p.CodeIDs { - ourEvent := sdk.NewEvent( - types.EventTypeUnpinCode, - sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - sdk.NewAttribute(types.AttributeKeyCodeID, strconv.FormatUint(v, 10)), - ) - ctx.EventManager().EmitEvent(ourEvent) - } - - ourEvent := sdk.NewEvent( - types.EventTypeUnpinCode, - sdk.NewAttribute(types.AttributeKeyCodeIDs, strings.Join(s, ",")), - ) - ctx.EventManager().EmitEvent(ourEvent) return nil } diff --git a/x/wasm/types/events.go b/x/wasm/types/events.go index 1675860a14..378b3fd089 100644 --- a/x/wasm/types/events.go +++ b/x/wasm/types/events.go @@ -10,8 +10,6 @@ const ( EventTypeInstantiate = "instantiate" EventTypeExecute = "execute" EventTypeMigrate = "migrate" - EventTypeUpdateAdmin = "update_admin" - EventTypeClearAdmin = "clear_admin" EventTypeUpdateContractStatus = "update_contract_status" EventTypePinCode = "pin_code" EventTypeUnpinCode = "unpin_code" diff --git a/x/wasm/types/querier_router.go b/x/wasm/types/querier_router.go deleted file mode 100644 index 165d2227ec..0000000000 --- a/x/wasm/types/querier_router.go +++ /dev/null @@ -1,65 +0,0 @@ -package types - -import ( - "encoding/json" - "fmt" - - sdk "github.com/line/lbm-sdk/types" -) - -var _ QueryRouter = (*querierRouter)(nil) - -type EncodeQuerier func(ctx sdk.Context, jsonQuerier json.RawMessage) ([]byte, error) - -// QueryRouter provides queryables for each query path. -type QueryRouter interface { - AddRoute(r string, q EncodeQuerier) QueryRouter - HasRoute(r string) bool - GetRoute(path string) EncodeQuerier - Seal() -} - -type querierRouter struct { - routes map[string]EncodeQuerier - sealed bool -} - -func NewQuerierRouter() QueryRouter { - return &querierRouter{ - routes: make(map[string]EncodeQuerier), - } -} - -func (rtr *querierRouter) Seal() { - if rtr.sealed { - panic("querier router already sealed") - } - rtr.sealed = true -} - -func (rtr *querierRouter) AddRoute(path string, q EncodeQuerier) QueryRouter { - if rtr.sealed { - panic("router sealed; cannot add route handler") - } - if !sdk.IsAlphaNumeric(path) { - panic("querier route expressions can only contain alphanumeric characters") - } - if rtr.HasRoute(path) { - panic(fmt.Sprintf("querier route %s has already been initialized", path)) - } - - rtr.routes[path] = q - return rtr -} - -func (rtr *querierRouter) HasRoute(path string) bool { - return rtr.routes[path] != nil -} - -func (rtr *querierRouter) GetRoute(path string) EncodeQuerier { - if !rtr.HasRoute(path) { - panic(fmt.Sprintf("querier route \"%s\" does not exist", path)) - } - - return rtr.routes[path] -} diff --git a/x/wasm/types/querier_router_test.go b/x/wasm/types/querier_router_test.go deleted file mode 100644 index b57fe6377c..0000000000 --- a/x/wasm/types/querier_router_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package types - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/require" - - sdk "github.com/line/lbm-sdk/types" -) - -func testQuerierHandler(ctx sdk.Context, jsonQuerier json.RawMessage) ([]byte, error) { - return nil, nil -} - -func TestQuerierRouterSeal(t *testing.T) { - r := NewQuerierRouter() - r.Seal() - require.Panics(t, func() { r.AddRoute("test", nil) }) - require.Panics(t, func() { r.Seal() }) -} - -func TestQuerierRouter(t *testing.T) { - r := NewQuerierRouter() - r.AddRoute("test", testQuerierHandler) - require.True(t, r.HasRoute("test")) - require.Panics(t, func() { r.AddRoute("test", testQuerierHandler) }) - require.Panics(t, func() { r.AddRoute(" ", testQuerierHandler) }) -} diff --git a/x/wasm/types/router.go b/x/wasm/types/router.go deleted file mode 100644 index d9bc9ae4fb..0000000000 --- a/x/wasm/types/router.go +++ /dev/null @@ -1,67 +0,0 @@ -package types - -import ( - "encoding/json" - "fmt" - - sdk "github.com/line/lbm-sdk/types" -) - -var _ Router = (*router)(nil) - -type EncodeHandler func(jsonMsg json.RawMessage) ([]sdk.Msg, error) - -type Router interface { - AddRoute(r string, h EncodeHandler) (rtr Router) - HasRoute(r string) bool - GetRoute(path string) (h EncodeHandler) - Seal() -} - -type router struct { - routes map[string]EncodeHandler - sealed bool -} - -func NewRouter() Router { - return &router{ - routes: make(map[string]EncodeHandler), - } -} - -func (rtr *router) Seal() { - if rtr.sealed { - panic("router already sealed") - } - rtr.sealed = true -} - -func (rtr *router) AddRoute(path string, h EncodeHandler) Router { - if rtr.sealed { - panic("router sealed; cannot add route handler") - } - - if !sdk.IsAlphaNumeric(path) { - panic("route expressions can only contain alphanumeric characters") - } - if rtr.HasRoute(path) { - panic(fmt.Sprintf("route %s has already been initialized", path)) - } - - rtr.routes[path] = h - return rtr -} - -// HasRoute returns true if the router has a path registered or false otherwise. -func (rtr *router) HasRoute(path string) bool { - return rtr.routes[path] != nil -} - -// GetRoute returns a Handler for a given path. -func (rtr *router) GetRoute(path string) EncodeHandler { - if !rtr.HasRoute(path) { - panic(fmt.Sprintf("route \"%s\" does not exist", path)) - } - - return rtr.routes[path] -} diff --git a/x/wasm/types/router_test.go b/x/wasm/types/router_test.go deleted file mode 100644 index 39d3d71bde..0000000000 --- a/x/wasm/types/router_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package types - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/require" - - sdk "github.com/line/lbm-sdk/types" -) - -func testHandler(jsonMsg json.RawMessage) ([]sdk.Msg, error) { return []sdk.Msg{}, nil } - -func TestRouterSeal(t *testing.T) { - r := NewRouter() - r.Seal() - require.Panics(t, func() { r.AddRoute("test", nil) }) - require.Panics(t, func() { r.Seal() }) -} - -func TestRouter(t *testing.T) { - r := NewRouter() - r.AddRoute("test", testHandler) - require.True(t, r.HasRoute("test")) - require.Panics(t, func() { r.AddRoute("test", testHandler) }) - require.Panics(t, func() { r.AddRoute(" ", testHandler) }) -}