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

wrap.gno

1.00 Kb · 32 lines
 1// Package wrap is version 1 of the "wrapping versions" upgrade pattern
 2// (pattern A of the exploration; see ../README.md).
 3//
 4// v1 owns a counter of its own and ADDS v0's on read. Both versions stay live
 5// and independently writable, so the two paths report different totals and
 6// neither is authoritative. That is the pattern's defining trade-off: no
 7// migration, no downtime, no coordination, and no single answer either.
 8package wrap
 9
10import (
11	v0 "gno.land/r/moul/x/upgrade/wrap/v0"
12
13	"gno.land/p/nt/ufmt/v0"
14)
15
16var counter int
17
18// Inc adds n to this version's own counter. It does NOT touch v0.
19func Inc(cur realm, n int) {
20	counter += n
21}
22
23// Get returns v0's counter plus this version's own. Reading across the version
24// boundary is a plain non-crossing call: no realm is entered as a writer, so
25// this stays queryable from vm/qeval and from Render.
26func Get() int {
27	return v0.Get() + counter
28}
29
30func Render(_ string) string {
31	return ufmt.Sprintf("wrap/v1: %d (own %d + v0 %d)\n", Get(), counter, v0.Get())
32}