Skip to content

Commit

Permalink
added method to get votes on state for a specific block number
Browse files Browse the repository at this point in the history
  • Loading branch information
0xsuryansh committed Jul 2, 2023
1 parent 74dba15 commit cdfde59
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions x/evmstorechain/keeper/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ func GetVoteIDFromBytes(bz []byte) uint64 {
return binary.BigEndian.Uint64(bz)
}

// GetVotes returns all votes for a specific block number
func (k Keeper) GetVotes(ctx sdk.Context, blockNum uint64) (list []types.Vote) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.VoteKey))
iterator := sdk.KVStorePrefixIterator(store, []byte{})

defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
var val types.Vote
k.cdc.MustUnmarshal(iterator.Value(), &val)
if val.Blocknumber == blockNum {
list = append(list, val)
}
}

return
}

// HasMaxVotes checks if a proposed state has received the maximum number of votes.
func (k Keeper) HasMaxVotes(ctx sdk.Context, blockNum uint64) (uint64, bool) {
voteCounts := make(map[uint64]int)
Expand Down

0 comments on commit cdfde59

Please sign in to comment.