Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

counter.gno

0.59 Kb · 33 lines
 1package staker
 2
 3type Counter struct {
 4	id int64
 5}
 6
 7// NewCounter creates a counter initialized at zero.
 8//
 9// Returns:
10//   - counter: Counter whose next generated identifier is 1.
11func NewCounter() *Counter {
12	return &Counter{
13		id: 0,
14	}
15}
16
17// Next increments the counter and returns the new identifier.
18//
19// Returns:
20//   - id: Counter value after incrementing by one.
21func (c *Counter) Next() int64 {
22	c.id++
23
24	return c.id
25}
26
27// Get returns the counter's current identifier without incrementing it.
28//
29// Returns:
30//   - id: Current counter value.
31func (c *Counter) Get() int64 {
32	return c.id
33}