Skip to content

Commit

Permalink
chore: add utility for fetching bypass messages
Browse files Browse the repository at this point in the history
  • Loading branch information
johnletey committed Oct 24, 2024
1 parent dac14ba commit 6a67d80
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
6 changes: 1 addition & 5 deletions genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 1 addition & 5 deletions keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 1 addition & 5 deletions keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
27 changes: 27 additions & 0 deletions keeper/state.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 6a67d80

Please sign in to comment.