Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Playground

gnomod.toml

module = "gno.land/r/moul/x/upgrade/selfreg/impl/v0"
gno = "0.9"

[addpkg]
  creator = "g1manfred47kzduec920z88wfr64ylksmdcedlf5"
  height = 410018
  max_deposit = "5000000ugnot"

impl.gno

// Package impl is version 0 of the implementation realm of the
// "self-registering implementation" upgrade pattern (pattern E; see
// ../../README.md).
//
// Deploying this realm is the whole upgrade: init registers it with the facade.
package impl

import (
	facade "gno.land/r/moul/x/upgrade/selfreg/facade/v0"
)

type greeter struct{}

func (greeter) Greet(name string) string { return "hello, " + name }
func (greeter) Version() string          { return "impl/v0" }

// Instance exposes the singleton so a test (or a rollback) can re-register it
// without redeploying.
func Instance() facade.Impl { return greeter{} }

func init(cur realm) {
	facade.Register(cross(cur), Instance())
}

// Register re-registers this implementation with the facade. init does it once
// at deploy; exposing it as a transaction is what makes a rollback to an
// already-deployed version a single call.
func Register(cur realm) {
	facade.Register(cross(cur), Instance())
}

// Seal asks the facade to end its upgradeability, forever. It only succeeds
// while this implementation is the live one: the facade reads the caller off
// the crossing frame, so this cannot be used to seal somebody else's tenure.
func Seal(cur realm) {
	facade.Seal(cross(cur))
}