Skip to content

Commit

Permalink
add nil-delegation record when delegation is removed. fixes cosmos#45
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Bowman committed Mar 2, 2020
1 parent 8970cff commit 02b4f11
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions x/staking/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func (k Keeper) RemoveDelegation(ctx sdk.Context, delegation types.Delegation) {
k.BeforeDelegationRemoved(ctx, delegation.DelegatorAddress, delegation.ValidatorAddress)
store := ctx.KVStore(k.storeKey)
store.Delete(types.GetDelegationKey(delegation.DelegatorAddress, delegation.ValidatorAddress))
k.ExportZeroDelegationForAccount(ctx, delegation.DelegatorAddress, delegation.ValidatorAddress)
k.ExportDelegationsForAccount(ctx, delegation.DelegatorAddress)
}

Expand All @@ -120,6 +121,16 @@ func (k Keeper) ExportDelegationsForAccount(ctx sdk.Context, account sdk.AccAddr
}
}

func (k Keeper) ExportZeroDelegationForAccount(ctx sdk.Context, account sdk.AccAddress, validator sdk.ValAddress) {
noGasCtx, _ := ctx.CacheContext()
noGasCtx = noGasCtx.WithGasMeter(sdk.NewInfiniteGasMeter()).WithBlockGasMeter(sdk.NewInfiniteGasMeter())
if ctx.Value("ExtractDataMode") != nil {
f, _ := os.OpenFile(fmt.Sprintf("./extract/unchecked/delegations.%d.%s", ctx.BlockHeight(), ctx.ChainID()), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
f.WriteString(fmt.Sprintf("%s,%s,%d,%d,%s,%s\n", account.String(), validator.String(), 0, uint64(ctx.BlockHeight()), ctx.BlockHeader().Time.Format("2006-01-02 15:04:05"), ctx.ChainID()))
f.Close()
}
}

// return a given amount of all the delegator unbonding-delegations
func (k Keeper) GetUnbondingDelegations(ctx sdk.Context, delegator sdk.AccAddress,
maxRetrieve uint16) (unbondingDelegations []types.UnbondingDelegation) {
Expand Down

0 comments on commit 02b4f11

Please sign in to comment.