Skip to content

Commit

Permalink
Created delegation keepers
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Kunze committed Aug 17, 2018
1 parent 3afe7db commit c9e1b27
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions x/stake/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ func (k Keeper) RemoveDelegation(ctx sdk.Context, delegation types.Delegation) {

//_____________________________________________________________________________________

// load all unbonding-delegations for a delegator
func (k Keeper) GetUnbondingDelegations(ctx sdk.Context, delegator sdk.AccAddress,
maxRetrieve int16) (unbondingDelegations []types.UnbondingDelegation) {

store := ctx.KVStore(k.storeKey)
delegatorPrefixKey := GetUBDsKey(delegator)
iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) //smallest to largest

unbondingDelegations = make([]types.UnbondingDelegation, maxRetrieve)
i := 0
for ; ; i++ {
if !iterator.Valid() || i > int(maxRetrieve-1) {
break
}
unbondingDelegation := types.MustUnmarshalUBD(k.cdc, iterator.Key(), iterator.Value())
unbondingDelegations[i] = unbondingDelegation
iterator.Next()
}
iterator.Close()
return unbondingDelegations[:i] // trim
}

// load a unbonding delegation
func (k Keeper) GetUnbondingDelegation(ctx sdk.Context,
DelegatorAddr, ValidatorAddr sdk.AccAddress) (ubd types.UnbondingDelegation, found bool) {
Expand Down Expand Up @@ -145,6 +167,28 @@ func (k Keeper) RemoveUnbondingDelegation(ctx sdk.Context, ubd types.UnbondingDe

//_____________________________________________________________________________________

// load all redelegations for a delegator
func (k Keeper) GetRedelegations(ctx sdk.Context, delegator sdk.AccAddress,
maxRetrieve int16) (redelegations []types.Redelegation) {

store := ctx.KVStore(k.storeKey)
delegatorPrefixKey := GetREDsKey(delegator)
iterator := sdk.KVStorePrefixIterator(store, delegatorPrefixKey) //smallest to largest

redelegations = make([]types.Redelegation, maxRetrieve)
i := 0
for ; ; i++ {
if !iterator.Valid() || i > int(maxRetrieve-1) {
break
}
redelegation := types.MustUnmarshalRED(k.cdc, iterator.Key(), iterator.Value())
redelegations[i] = redelegation
iterator.Next()
}
iterator.Close()
return redelegations[:i] // trim
}

// load a redelegation
func (k Keeper) GetRedelegation(ctx sdk.Context,
DelegatorAddr, ValidatorSrcAddr, ValidatorDstAddr sdk.AccAddress) (red types.Redelegation, found bool) {
Expand Down

0 comments on commit c9e1b27

Please sign in to comment.