WIP intermediate...
This commit is contained in:
parent
c3008d585b
commit
ea565baa60
|
@ -23,8 +23,10 @@ func (k Keeper) onValidatorCreated(ctx sdk.Context, addr sdk.ValAddress) {
|
|||
|
||||
// Withdrawal all validator rewards
|
||||
func (k Keeper) onValidatorModified(ctx sdk.Context, addr sdk.ValAddress) {
|
||||
if err := k.WithdrawValidatorRewardsAll(ctx, addr); err != nil {
|
||||
panic(err)
|
||||
if ctx.BlockHeight() > 0 {
|
||||
if err := k.WithdrawValidatorRewardsAll(ctx, addr); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,6 +54,8 @@ func (k Keeper) onDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress,
|
|||
func (k Keeper) onDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress,
|
||||
valAddr sdk.ValAddress) {
|
||||
|
||||
fmt.Printf("DELEGATION SHARES MODIFIED %v\n", valAddr)
|
||||
|
||||
if err := k.WithdrawDelegationReward(ctx, delAddr, valAddr); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -87,9 +91,11 @@ func (h Hooks) OnValidatorRemoved(ctx sdk.Context, addr sdk.ValAddress) {
|
|||
h.k.onValidatorRemoved(ctx, addr)
|
||||
}
|
||||
func (h Hooks) OnDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) {
|
||||
h.k.onValidatorModified(ctx, valAddr)
|
||||
h.k.onDelegationCreated(ctx, delAddr, valAddr)
|
||||
}
|
||||
func (h Hooks) OnDelegationSharesModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) {
|
||||
h.k.onValidatorModified(ctx, valAddr)
|
||||
h.k.onDelegationSharesModified(ctx, delAddr, valAddr)
|
||||
}
|
||||
func (h Hooks) OnDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) {
|
||||
|
|
|
@ -41,12 +41,13 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) (res [
|
|||
// Manually set indices for the first time
|
||||
keeper.SetValidatorByConsAddr(ctx, validator)
|
||||
keeper.SetValidatorByPowerIndex(ctx, validator, data.Pool)
|
||||
|
||||
fmt.Println("stake.INITGENESIS", ctx.BlockHeight())
|
||||
keeper.OnValidatorCreated(ctx, validator.OperatorAddr)
|
||||
}
|
||||
|
||||
for _, delegation := range data.Bonds {
|
||||
keeper.SetDelegation(ctx, delegation)
|
||||
fmt.Println("stake.INITGENESISd", ctx.BlockHeight())
|
||||
keeper.OnDelegationCreated(ctx, delegation.DelegatorAddr, delegation.ValidatorAddr)
|
||||
}
|
||||
|
||||
|
|
|
@ -106,6 +106,8 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k
|
|||
k.SetValidatorByConsAddr(ctx, validator)
|
||||
k.SetNewValidatorByPowerIndex(ctx, validator)
|
||||
|
||||
k.OnValidatorCreated(ctx, validator.OperatorAddr)
|
||||
|
||||
// move coins from the msg.Address account to a (self-delegation) delegator account
|
||||
// the validator account and global shares are updated within here
|
||||
_, err = k.Delegate(ctx, msg.DelegatorAddr, msg.Delegation, validator, true)
|
||||
|
@ -113,8 +115,6 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k
|
|||
return err.Result()
|
||||
}
|
||||
|
||||
k.OnValidatorCreated(ctx, validator.OperatorAddr)
|
||||
|
||||
tags := sdk.NewTags(
|
||||
tags.Action, tags.ActionCreateValidator,
|
||||
tags.DstValidator, []byte(msg.ValidatorAddr.String()),
|
||||
|
|
|
@ -360,6 +360,7 @@ func (k Keeper) Delegate(ctx sdk.Context, delAddr sdk.AccAddress, bondAmt sdk.Co
|
|||
}
|
||||
|
||||
// call the appropriate hook if present
|
||||
//fmt.Printf("DELEGATION SHARES MODIFIED (2) FOUND OR NOT %v found: %v\n", validator.OperatorAddr, found)
|
||||
if found {
|
||||
k.OnDelegationSharesModified(ctx, delAddr, validator.OperatorAddr)
|
||||
} else {
|
||||
|
|
|
@ -78,7 +78,7 @@ func (k Keeper) GetLastTotalPower(ctx sdk.Context) (power sdk.Dec) {
|
|||
store := ctx.KVStore(k.storeKey)
|
||||
b := store.Get(LastTotalPowerKey)
|
||||
if b == nil {
|
||||
panic("stored last total power should not have been nil")
|
||||
return sdk.ZeroDec()
|
||||
}
|
||||
k.cdc.MustUnmarshalBinary(b, &power)
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue