Skip to content

Commit

Permalink
Allow whitelist execute MsgExec (#176)
Browse files Browse the repository at this point in the history
* Whitelist accept MsgExec

* Refactor return func of NewWhiteListAnteHandler

* Fix logic so that it allow non-whitelist to send MsgReportData

* Rename variable
  • Loading branch information
p-rial authored and RogerKSI committed Sep 14, 2023
1 parent 30dfb4d commit bfd8f0b
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions x/oracle/ante/ante.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ante

import (
"errors"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -155,17 +154,32 @@ func NewWhiteListAnteHandler(ante sdk.AnteHandler, oracleKeeper keeper.Keeper, r

for _, msg := range tx.GetMsgs() {

if req, ok := msg.(*types.MsgRequestData); ok {
// is a whitelisted request
if _, found := whiteList[req.Sender]; !found {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Request is in valid")
switch m := msg.(type) {
case *types.MsgRequestData:

if _, found := whiteList[m.Sender]; !found {
return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, fmt.Sprintf("%s not in the whitelist", m.Sender))
}
} else if _, ok = msg.(*types.MsgReportData); ok {
case *types.MsgReportData:
// TODO: check if this is our report
} else {
continue
case *authz.MsgExec:
execMsgs, err := m.GetMessages()
if err != nil {
return ctx, err
}

for _, execMsg := range execMsgs {

if sdk.MsgTypeURL(&types.MsgReportData{}) != sdk.MsgTypeURL(execMsg) {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Msg type is not allowed")
}
}
default:
// reject all other msg type
return ctx, errors.New("Msg type is not allowed")
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Msg type is not allowed")
}

}
}
return ante(ctx, tx, simulate)
Expand Down

0 comments on commit bfd8f0b

Please sign in to comment.