Skip to content

Commit

Permalink
Defensive checks callbacks (#875)
Browse files Browse the repository at this point in the history
* fix: super defensive checks. fixes #842

* use Keys() helper func

---------

Co-authored-by: Jacob Gadikian <[email protected]>
  • Loading branch information
Joe Bowman and faddat authored Dec 12, 2023
1 parent 570709f commit fb10791
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
9 changes: 1 addition & 8 deletions x/interchainquery/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"sort"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -63,15 +62,9 @@ func (k msgServer) SubmitQueryResponse(goCtx context.Context, msg *types.MsgSubm
noDelete := false
// execute registered callbacks.

keys := make([]string, 0)
for k := range k.callbacks {
keys = append(keys, k)
}

sort.Strings(keys)
callbackExecuted := false

for _, key := range keys {
for _, key := range utils.Keys[types.QueryCallbacks](k.callbacks) {
module := k.callbacks[key]
if module.Has(q.CallbackId) {
err := module.Call(ctx, q.CallbackId, msg.Result, q)
Expand Down
3 changes: 3 additions & 0 deletions x/interchainstaking/keeper/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func (k *Keeper) CallbackHandler() Callbacks {

// Call calls callback handler.
func (c Callbacks) Call(ctx sdk.Context, id string, args []byte, query icqtypes.Query) error {
if !c.Has(id) {
return fmt.Errorf("callback %s not found", id)
}
return c.callbacks[id](c.k, ctx, args, query)
}

Expand Down
3 changes: 3 additions & 0 deletions x/participationrewards/keeper/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func (k *Keeper) CallbackHandler() Callbacks {

// Call calls callback handler.
func (c Callbacks) Call(ctx sdk.Context, id string, args []byte, query icqtypes.Query) error {
if c.Has(id) {
return fmt.Errorf("callback %s not found", id)
}
return c.callbacks[id](ctx, c.k, args, query)
}

Expand Down

0 comments on commit fb10791

Please sign in to comment.