-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move dyncomm state changes to post handler
- Loading branch information
1 parent
43c6797
commit 17541c7
Showing
5 changed files
with
119 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package post | ||
|
||
import ( | ||
dyncommkeeper "github.com/classic-terra/core/v2/x/dyncomm/keeper" | ||
dyncommpost "github.com/classic-terra/core/v2/x/dyncomm/post" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// HandlerOptions are the options required for constructing a default SDK AnteHandler. | ||
type HandlerOptions struct { | ||
DyncommKeeper dyncommkeeper.Keeper | ||
} | ||
|
||
// NewAnteHandler returns an AnteHandler that checks and increments sequence | ||
// numbers, checks signatures & account numbers, and deducts fees from the first | ||
// signer. | ||
func NewPostHandler(options HandlerOptions) (sdk.AnteHandler, error) { | ||
|
||
return sdk.ChainAnteDecorators( | ||
dyncommpost.NewDyncommPostDecorator(options.DyncommKeeper), | ||
), nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package post | ||
|
||
import ( | ||
dyncommkeeper "github.com/classic-terra/core/v2/x/dyncomm/keeper" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
// DyncommDecorator does post runMsg store | ||
// modifications for dyncomm module | ||
type DyncommDecorator struct { | ||
dyncommKeeper dyncommkeeper.Keeper | ||
} | ||
|
||
func NewDyncommPostDecorator(dk dyncommkeeper.Keeper) DyncommDecorator { | ||
return DyncommDecorator{ | ||
dyncommKeeper: dk, | ||
} | ||
} | ||
|
||
func (dd DyncommDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { | ||
|
||
if simulate { | ||
return next(ctx, tx, simulate) | ||
} | ||
|
||
if ctx.IsCheckTx() { | ||
return next(ctx, tx, simulate) | ||
} | ||
|
||
msgs := tx.GetMsgs() | ||
dd.FilterMsgsAndProcessMsgs(ctx, msgs...) | ||
|
||
return next(ctx, tx, simulate) | ||
|
||
} | ||
|
||
func (dd DyncommDecorator) FilterMsgsAndProcessMsgs(ctx sdk.Context, msgs ...sdk.Msg) { | ||
|
||
for _, msg := range msgs { | ||
|
||
switch msg.(type) { | ||
case *stakingtypes.MsgEditValidator: | ||
dd.ProcessEditValidator(ctx, msg) | ||
case *stakingtypes.MsgCreateValidator: | ||
dd.ProcessCreateValidator(ctx, msg) | ||
default: | ||
continue | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
func (dd DyncommDecorator) ProcessEditValidator(ctx sdk.Context, msg sdk.Msg) { | ||
|
||
msgEditValidator := msg.(*stakingtypes.MsgEditValidator) | ||
|
||
// no update of CommissionRate provided | ||
if msgEditValidator.CommissionRate == nil { | ||
return | ||
} | ||
|
||
// post handler runs after successfully | ||
// calling runMsgs -> we can set state changes here! | ||
newIntendedRate := msgEditValidator.CommissionRate | ||
dd.dyncommKeeper.SetTargetCommissionRate(ctx, msgEditValidator.ValidatorAddress, *newIntendedRate) | ||
|
||
} | ||
|
||
func (dd DyncommDecorator) ProcessCreateValidator(ctx sdk.Context, msg sdk.Msg) { | ||
|
||
// post handler runs after successfully | ||
// calling runMsgs -> we can set state changes here! | ||
msgEditValidator := msg.(*stakingtypes.MsgCreateValidator) | ||
newIntendedRate := msgEditValidator.Commission.Rate | ||
dd.dyncommKeeper.SetTargetCommissionRate(ctx, msgEditValidator.ValidatorAddress, newIntendedRate) | ||
|
||
} |