-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdisable_withdraw_delegator_rewards.go
53 lines (43 loc) · 1.29 KB
/
disable_withdraw_delegator_rewards.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
package poaante
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/strangelove-ventures/poa"
)
type MsgDisableWithdrawDelegatorRewards struct {
}
func NewPOADisableWithdrawDelegatorRewards() MsgDisableWithdrawDelegatorRewards {
return MsgDisableWithdrawDelegatorRewards{}
}
func (mdwr MsgDisableWithdrawDelegatorRewards) 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 := mdwr.hasWithdrawDelegatorRewardsMsg(tx.GetMsgs())
if err != nil {
return ctx, err
}
return next(ctx, tx, simulate)
}
func (mdwr MsgDisableWithdrawDelegatorRewards) hasWithdrawDelegatorRewardsMsg(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 = mdwr.hasWithdrawDelegatorRewardsMsg(msgs)
if err != nil {
return err
}
}
if _, ok := msg.(*distrtypes.MsgWithdrawDelegatorReward); ok {
return poa.ErrWithdrawDelegatorRewardsNotAllowed
}
}
return nil
}