diff --git a/examples/gno.land/r/demo/teritori/dao_realm/dao_realm.gno b/examples/gno.land/r/demo/teritori/dao_realm/dao_realm.gno index 9d92e15ceac..3106c325618 100644 --- a/examples/gno.land/r/demo/teritori/dao_realm/dao_realm.gno +++ b/examples/gno.land/r/demo/teritori/dao_realm/dao_realm.gno @@ -63,6 +63,9 @@ func init() { func(core dao_interfaces.IDAOCore) dao_interfaces.MessageHandler { return tori.NewBurnToriHandler() }, + func(core dao_interfaces.IDAOCore) dao_interfaces.MessageHandler { + return tori.NewChangeAdminHandler() + }, } daoCore = dao_core.NewDAOCore(votingModuleFactory, proposalModulesFactories, messageHandlersFactories) diff --git a/examples/gno.land/r/demo/teritori/tori/messages.gno b/examples/gno.land/r/demo/teritori/tori/messages.gno index 2787e1e18a7..c6812ba6966 100644 --- a/examples/gno.land/r/demo/teritori/tori/messages.gno +++ b/examples/gno.land/r/demo/teritori/tori/messages.gno @@ -125,3 +125,57 @@ func (h BurnToriHandler) Type() string { func (h *BurnToriHandler) Instantiate() dao_interfaces.ExecutableMessage { return &ExecutableMessageBurnTori{} } + +type ExecutableMessageChangeAdmin struct { + dao_interfaces.ExecutableMessage + + NewAdmin users.AddressOrName +} + +var _ dao_interfaces.ExecutableMessage = &ExecutableMessageChangeAdmin{} + +func (msg ExecutableMessageChangeAdmin) Type() string { + return "gno.land/r/demo/teritori/tori.ChangeAdmin" +} + +func (msg *ExecutableMessageChangeAdmin) String() string { + var ss []string + ss = append(ss, msg.Type()) + s := "New admin: " + string(msg.NewAdmin) + ss = append(ss, s) + return strings.Join(ss, "\n---\n") +} + +func (msg *ExecutableMessageChangeAdmin) FromJSON(ast *json.Node) { + obj := ast.MustObject() + msg.NewAdmin = jsonutil.MustAddressOrName(obj["newAdmin"]) +} + +func (msg *ExecutableMessageChangeAdmin) ToJSON() *json.Node { + return json.ObjectNode("", map[string]*json.Node{ + "newAdmin": jsonutil.AddressOrNameNode(msg.NewAdmin), + }) +} + +type ChangeAdminHandler struct { + dao_interfaces.MessageHandler +} + +var _ dao_interfaces.MessageHandler = &ChangeAdminHandler{} + +func NewChangeAdminHandler() *ChangeAdminHandler { + return &ChangeAdminHandler{} +} + +func (h *ChangeAdminHandler) Execute(imsg dao_interfaces.ExecutableMessage) { + msg := imsg.(*ExecutableMessageChangeAdmin) + ChangeAdmin(msg.NewAdmin) +} + +func (h ChangeAdminHandler) Type() string { + return ExecutableMessageChangeAdmin{}.Type() +} + +func (h *ChangeAdminHandler) Instantiate() dao_interfaces.ExecutableMessage { + return &ExecutableMessageChangeAdmin{} +} diff --git a/examples/gno.land/r/demo/teritori/tori/tori.gno b/examples/gno.land/r/demo/teritori/tori/tori.gno index 8079151cf9c..70c0d0f3835 100644 --- a/examples/gno.land/r/demo/teritori/tori/tori.gno +++ b/examples/gno.land/r/demo/teritori/tori/tori.gno @@ -13,7 +13,7 @@ import ( var ( tori *grc20.AdminToken userTori grc20.IGRC20 - admin std.Address = std.DerivePkgAddr("gno.land/r/demo/teritori/dao_realm") // TODO: public func and message to change admin + admin std.Address = std.DerivePkgAddr("gno.land/r/demo/teritori/dao_realm") ) func init() { @@ -65,6 +65,12 @@ func TransferFrom(from, to users.AddressOrName, amount uint64) { // administration. +func ChangeAdmin(newAdmin users.AddressOrName) { + caller := std.PrevRealm().Addr() + assertIsAdmin(caller) + admin = rusers.Resolve(newAdmin) +} + func Mint(address users.AddressOrName, amount uint64) { caller := std.PrevRealm().Addr() assertIsAdmin(caller)