0g-chain/x/shutdown/ante/ante.go

36 lines
999 B
Go
Raw Normal View History

2020-03-04 16:41:13 +00:00
package ante
2020-03-04 14:35:16 +00:00
2020-03-04 16:41:13 +00:00
import (
"fmt"
2020-03-04 19:16:27 +00:00
"github.com/kava-labs/kava/x/shutdown/keeper"
2020-03-04 16:41:13 +00:00
sdk "github.com/cosmos/cosmos-sdk/types"
)
2020-03-04 19:50:30 +00:00
// DisableMsgDecorator errors if a tx contains a disallowed msg type and calls the next AnteHandler if all msgs are allowed
type DisableMsgDecorator struct {
shutdownKeeper keeper.Keeper
2020-03-04 14:35:16 +00:00
}
2020-03-04 19:50:30 +00:00
func NewDisableMsgDecorator(shutdownKeeper keeper.Keeper) DisableMsgDecorator {
return DisableMsgDecorator{
shutdownKeeper: shutdownKeeper,
2020-03-04 14:35:16 +00:00
}
}
2020-03-04 19:50:30 +00:00
func (dmd DisableMsgDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
2020-03-04 14:35:16 +00:00
// get msg route, error if not allowed
2020-03-04 19:50:30 +00:00
disallowedRoutes := dmd.shutdownKeeper.GetMsgRoutes(ctx)
2020-03-04 16:41:13 +00:00
for _, m := range tx.GetMsgs() {
for _, r := range disallowedRoutes {
if r.Route == m.Route() && r.Msg == m.Type() {
2020-03-04 19:50:30 +00:00
return ctx, fmt.Errorf("route %s has been disabled, tx rejected", r)
2020-03-04 14:35:16 +00:00
}
}
}
2020-03-04 19:50:30 +00:00
// otherwise continue to next antehandler decorator
2020-03-04 14:35:16 +00:00
return next(ctx, tx, simulate)
}