github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/r/x/manfred_upgrade_patterns/upgrade_b/v1/v1.gno (about) 1 package upgradea 2 3 import "std" 4 5 const admin = "blahblah" 6 7 var ( 8 counter int 9 nextVersion string 10 ) 11 12 func Inc(nb int) { 13 if nextVersion != "" { 14 panic("contract is locked, please use the new version at r/" + nextVersion) 15 } 16 counter += nb 17 } 18 19 func Get() int { 20 return counter 21 } 22 23 func SetNextVersion(addr string) { 24 // assert CallTx call. 25 std.AssertOriginCall() 26 // assert admin. 27 caller := std.GetCallerAt(2) 28 if caller != std.GetOrigCaller() { 29 panic("should not happen") // because std.AssertOrigCall(). 30 } 31 if caller != admin { 32 panic("unauthorized") 33 } 34 nextVersion = addr 35 }