Search Apps Documentation Source Content File Folder Download Copy Actions Download

gnosdk.gno

0.95 Kb · 37 lines
 1package validators
 2
 3import (
 4	"math"
 5
 6	"gno.land/p/sys/validators"
 7)
 8
 9// GetChanges returns the validator changes stored on the realm,
10// for blocks in the [from, to] range (inclusive on both ends).
11// If to >= math.MaxInt64, it is clamped to math.MaxInt64-1 to avoid overflow.
12// Panics if from > to (after clamping).
13// This function is intended to be called by gno.land through the GnoSDK.
14func GetChanges(from, to int64) []validators.Validator {
15	if to > math.MaxInt64-1 {
16		to = math.MaxInt64 - 1
17	}
18	if to < from {
19		panic("invalid range: from must be <= to")
20	}
21
22	valsetChanges := make([]validators.Validator, 0)
23
24	// Gather the changes in the [from, to] block range.
25	// AVL Iterate uses an exclusive end, so we pass to+1.
26	changes.Iterate(getBlockID(from), getBlockID(to+1), func(_ string, value any) bool {
27		chs := value.([]change)
28
29		for _, ch := range chs {
30			valsetChanges = append(valsetChanges, ch.validator)
31		}
32
33		return false
34	})
35
36	return valsetChanges
37}