-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdisable_staking.go
64 lines (52 loc) · 1.64 KB
/
disable_staking.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package poaante
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/strangelove-ventures/poa"
)
type MsgStakingFilterDecorator struct {
}
func NewPOADisableStakingDecorator() MsgStakingFilterDecorator {
return MsgStakingFilterDecorator{}
}
// AnteHandle performs an AnteHandler check that returns an error if the tx contains a message that is blocked.
func (msfd MsgStakingFilterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
currHeight := ctx.BlockHeight()
if currHeight <= 1 {
// allow GenTx to pass
return next(ctx, tx, simulate)
}
err := msfd.hasInvalidStakingMsg(tx.GetMsgs())
if err != nil {
return ctx, err
}
return next(ctx, tx, simulate)
}
func (msfd MsgStakingFilterDecorator) hasInvalidStakingMsg(msgs []sdk.Msg) error {
for _, msg := range msgs {
// authz nested message check (recursive)
if execMsg, ok := msg.(*authz.MsgExec); ok {
msgs, err := execMsg.GetMessages()
if err != nil {
return err
}
err = msfd.hasInvalidStakingMsg(msgs)
if err != nil {
return err
}
}
switch msg.(type) {
// POA wrapped messages
case *stakingtypes.MsgCreateValidator, *stakingtypes.MsgUpdateParams,
// Blocked entirely when POA is enabled
*stakingtypes.MsgBeginRedelegate,
*stakingtypes.MsgCancelUnbondingDelegation,
*stakingtypes.MsgDelegate,
*stakingtypes.MsgUndelegate:
return poa.ErrStakingActionNotAllowed
}
// stakingtypes.MsgEditValidator is the only allowed message. We do not need to check for it.
}
return nil
}