diff --git a/genesis.go b/genesis.go index 175c279..c61435f 100644 --- a/genesis.go +++ b/genesis.go @@ -40,11 +40,7 @@ func ExportGenesis(ctx context.Context, k *keeper.Keeper) *types.GenesisState { panic(err) } - var bypassMessages []string - err = k.BypassMessages.Walk(ctx, nil, func(bypassMessage string) (stop bool, err error) { - bypassMessages = append(bypassMessages, bypassMessage) - return false, nil - }) + bypassMessages, err := k.GetBypassMessages(ctx) if err != nil { panic(err) } diff --git a/keeper/msg_server_test.go b/keeper/msg_server_test.go index 7c9f416..e17c133 100644 --- a/keeper/msg_server_test.go +++ b/keeper/msg_server_test.go @@ -228,11 +228,7 @@ func TestUpdateBypassMessages(t *testing.T) { }) // ASSERT: The action should've succeeded. require.NoError(t, err) - var bypassMessages []string - err = k.BypassMessages.Walk(ctx, nil, func(bypassMessage string) (stop bool, err error) { - bypassMessages = append(bypassMessages, bypassMessage) - return false, nil - }) + bypassMessages, err := k.GetBypassMessages(ctx) require.NoError(t, err) require.Len(t, bypassMessages, 1) require.Contains(t, bypassMessages, "/noble.globalfee.v1.MsgUpdateBypassMessages") diff --git a/keeper/query_server.go b/keeper/query_server.go index 81986a5..4a7fbc3 100644 --- a/keeper/query_server.go +++ b/keeper/query_server.go @@ -50,11 +50,7 @@ func (k queryServer) BypassMessages(ctx context.Context, req *types.QueryBypassM return nil, errors.ErrInvalidRequest } - var bypassMessages []string - err := k.Keeper.BypassMessages.Walk(ctx, nil, func(bypassMessage string) (stop bool, err error) { - bypassMessages = append(bypassMessages, bypassMessage) - return false, nil - }) + bypassMessages, err := k.GetBypassMessages(ctx) return &types.QueryBypassMessagesResponse{BypassMessages: bypassMessages}, err } diff --git a/keeper/state.go b/keeper/state.go new file mode 100644 index 0000000..378f04b --- /dev/null +++ b/keeper/state.go @@ -0,0 +1,27 @@ +// Copyright 2024 NASD Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package keeper + +import "context" + +// GetBypassMessages is a utility that returns all bypass messages from state. +func (k *Keeper) GetBypassMessages(ctx context.Context) (bypassMessages []string, err error) { + err = k.BypassMessages.Walk(ctx, nil, func(bypassMessage string) (stop bool, err error) { + bypassMessages = append(bypassMessages, bypassMessage) + return false, nil + }) + + return +}