2019-05-16 08:25:32 -07:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// combine multiple staking hooks, all hook functions are run in array sequence
|
2021-06-30 03:13:07 -07:00
|
|
|
var _ StakingHooks = &MultiStakingHooks{}
|
|
|
|
|
2019-06-04 15:06:58 -07:00
|
|
|
type MultiStakingHooks []StakingHooks
|
2019-05-16 08:25:32 -07:00
|
|
|
|
2019-06-04 15:06:58 -07:00
|
|
|
func NewMultiStakingHooks(hooks ...StakingHooks) MultiStakingHooks {
|
2019-05-16 08:25:32 -07:00
|
|
|
return hooks
|
|
|
|
}
|
|
|
|
|
2021-06-30 03:13:07 -07:00
|
|
|
func (h MultiStakingHooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) error {
|
2019-05-16 08:25:32 -07:00
|
|
|
for i := range h {
|
2021-06-30 03:13:07 -07:00
|
|
|
if err := h[i].AfterValidatorCreated(ctx, valAddr); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
|
|
|
|
return nil
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
func (h MultiStakingHooks) BeforeValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress) error {
|
2019-05-16 08:25:32 -07:00
|
|
|
for i := range h {
|
2021-06-30 03:13:07 -07:00
|
|
|
if err := h[i].BeforeValidatorModified(ctx, valAddr); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
return nil
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
func (h MultiStakingHooks) AfterValidatorRemoved(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
|
2019-05-16 08:25:32 -07:00
|
|
|
for i := range h {
|
2021-06-30 03:13:07 -07:00
|
|
|
if err := h[i].AfterValidatorRemoved(ctx, consAddr, valAddr); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
return nil
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
func (h MultiStakingHooks) AfterValidatorBonded(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
|
2019-05-16 08:25:32 -07:00
|
|
|
for i := range h {
|
2021-06-30 03:13:07 -07:00
|
|
|
if err := h[i].AfterValidatorBonded(ctx, consAddr, valAddr); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
return nil
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
func (h MultiStakingHooks) AfterValidatorBeginUnbonding(ctx sdk.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error {
|
2019-05-16 08:25:32 -07:00
|
|
|
for i := range h {
|
2021-06-30 03:13:07 -07:00
|
|
|
if err := h[i].AfterValidatorBeginUnbonding(ctx, consAddr, valAddr); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
return nil
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
func (h MultiStakingHooks) BeforeDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
|
2019-05-16 08:25:32 -07:00
|
|
|
for i := range h {
|
2021-06-30 03:13:07 -07:00
|
|
|
if err := h[i].BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
return nil
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
func (h MultiStakingHooks) BeforeDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
|
2019-05-16 08:25:32 -07:00
|
|
|
for i := range h {
|
2021-06-30 03:13:07 -07:00
|
|
|
if err := h[i].BeforeDelegationSharesModified(ctx, delAddr, valAddr); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
return nil
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
func (h MultiStakingHooks) BeforeDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
|
2019-05-16 08:25:32 -07:00
|
|
|
for i := range h {
|
2021-06-30 03:13:07 -07:00
|
|
|
if err := h[i].BeforeDelegationRemoved(ctx, delAddr, valAddr); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
return nil
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
func (h MultiStakingHooks) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
|
2019-05-16 08:25:32 -07:00
|
|
|
for i := range h {
|
2021-06-30 03:13:07 -07:00
|
|
|
if err := h[i].AfterDelegationModified(ctx, delAddr, valAddr); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
return nil
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
func (h MultiStakingHooks) BeforeValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress, fraction sdk.Dec) error {
|
2019-05-16 08:25:32 -07:00
|
|
|
for i := range h {
|
2021-06-30 03:13:07 -07:00
|
|
|
if err := h[i].BeforeValidatorSlashed(ctx, valAddr, fraction); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|
2021-06-30 03:13:07 -07:00
|
|
|
return nil
|
2019-05-16 08:25:32 -07:00
|
|
|
}
|