Skip to content

Missing governance iterators  #4439

Closed
@fedekunze

Description

Summary

Create iterator functions for gov keepers

Problem Definition

Currently gov iterators are duplicated and defined within each function in the governance keeper. For eg:

// Deletes all the deposits on a specific proposal without refunding them
func (keeper Keeper) DeleteDeposits(ctx sdk.Context, proposalID uint64) {
    store := ctx.KVStore(keeper.storeKey)
    depositsIterator := keeper.GetDeposits(ctx, proposalID)
    defer depositsIterator.Close()
    for ; depositsIterator.Valid(); depositsIterator.Next() {
        deposit := &Deposit{}
        keeper.cdc.MustUnmarshalBinaryLengthPrefixed(depositsIterator.Value(), deposit)

        err := keeper.sk.BurnCoins(ctx, ModuleName, deposit.Amount)
        if err != nil {
            panic(err)
        }

        store.Delete(depositsIterator.Key())
    }
}

Proposal

Define the following iterators:

func (k Keeper) IterateProposals(ctx sdk.Context, fn func(proposalID uint64) (stop bool)) 

func (k Keeper) IterateRedelegations(ctx sdk.Context, fn func(proposalID uint64, depositorAddr sdk.AccAddress) (stop bool)) 

func (k Keeper) IterateRedelegations(ctx sdk.Context, fn func(proposalID uint64, voterAddr sdk.AccAddress) (stop bool)) 

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

C:x/govType: Code HygieneGeneral cleanup and restructuring of code to provide clarity, flexibility, and modularity.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions