From 3b4c63a06a0927a4f6bdb1b45b31ef6b0d1825ee Mon Sep 17 00:00:00 2001 From: DIGIX666 Date: Fri, 1 Nov 2024 17:11:14 +0100 Subject: [PATCH] change event and modify the doc --- .../p/demo/accesscontrol/accesscontrol.gno | 45 ++++++++++--------- .../gno.land/p/demo/accesscontrol/doc.gno | 29 ++++++++++++ examples/gno.land/p/demo/timelock/doc.gno | 32 +++++++++++++ .../gno.land/p/demo/timelock/timelock.gno | 32 ------------- 4 files changed, 84 insertions(+), 54 deletions(-) create mode 100644 examples/gno.land/p/demo/timelock/doc.gno diff --git a/examples/gno.land/p/demo/accesscontrol/accesscontrol.gno b/examples/gno.land/p/demo/accesscontrol/accesscontrol.gno index 3b7dfdd37a5..e0cd3b6ec7f 100644 --- a/examples/gno.land/p/demo/accesscontrol/accesscontrol.gno +++ b/examples/gno.land/p/demo/accesscontrol/accesscontrol.gno @@ -8,10 +8,11 @@ import ( ) const ( - RoleName = "roleName" - Sender = "sender" - Account = "account" - NewAdminRole = "newAdminRole" + RoleCreatedEvent = "RoleCreated" + RoleGrantedEvent = "RoleGranted" + RoleRevokedEvent = "RoleRevoked" + RoleRenouncedEvent = "RoleRenounced" + RoleSetEvent = "RoleSet" ) // Role struct to store role information @@ -72,9 +73,9 @@ func (rs *Roles) CreateRole(name string) (*Role, error) { rs.AllRoles = append(rs.AllRoles, role) std.Emit( - "RoleCreated", - RoleName, name, - Sender, rs.Ownable.Owner().String(), + RoleCreatedEvent, + "roleName", name, + "sender", rs.Ownable.Owner().String(), ) return role, nil @@ -111,10 +112,10 @@ func (rs *Roles) GrantRole(name string, account std.Address) error { r.Holders.Set(account.String(), struct{}{}) std.Emit( - "RoleGranted", - RoleName, r.Name, - Account, account.String(), - Sender, std.PrevRealm().Addr().String(), + RoleGrantedEvent, + "roleName", r.Name, + "account", account.String(), + "sender", std.PrevRealm().Addr().String(), ) return nil @@ -135,10 +136,10 @@ func (rs *Roles) RevokeRole(name string, account std.Address) error { r.Holders.Remove(account.String()) std.Emit( - "RoleRevoked", - RoleName, r.Name, - Account, account.String(), - Sender, std.PrevRealm().Addr().String(), + RoleRevokedEvent, + "roleName", r.Name, + "account", account.String(), + "sender", std.PrevRealm().Addr().String(), ) return nil @@ -160,10 +161,10 @@ func (rs *Roles) RenounceRole(name string) error { r.Holders.Remove(caller.String()) std.Emit( - "RoleRenounced", - RoleName, r.Name, - Account, caller.String(), - Sender, caller.String(), + RoleRenouncedEvent, + "roleName", r.Name, + "account", caller.String(), + "sender", caller.String(), ) return nil @@ -176,9 +177,9 @@ func (r *Role) SetRoleAdmin(admin std.Address) error { } std.Emit( - "RoleSet", - RoleName, r.Name, - NewAdminRole, r.Ownable.Owner().String(), + RoleSetEvent, + "roleName", r.Name, + "newAdminRole", r.Ownable.Owner().String(), ) return nil diff --git a/examples/gno.land/p/demo/accesscontrol/doc.gno b/examples/gno.land/p/demo/accesscontrol/doc.gno index 31c9dd7794f..c6ba2f79f88 100644 --- a/examples/gno.land/p/demo/accesscontrol/doc.gno +++ b/examples/gno.land/p/demo/accesscontrol/doc.gno @@ -27,4 +27,33 @@ // Role ownership can be transferred using `SetRoleAdmin`. // // SetRoleAdmin(newAdminAddress) +// +// Key events +// - `RoleCreatedEvent`: Triggered when a new role is created +// Key includes: +// `roleName` (name of the role) +// `sender` (address of the sender) +// +// - `RoleGrantedEvent`: Triggered when a role is granted to an account +// Key includes: +// `roleName` (name of the role) +// `account` (address of the account) +// `sender` (address of the sender) +// +// - `RoleRevokedEvent`: Triggered when a role is revoked from an account +// Key includes: +// `roleName` (name of the role) +// `account` (address of the account) +// `sender` (address of the sender) +// +// - `RoleRenouncedEvent`: Triggered when a role is renounced by an account +// Key includes: +// `roleName` (name of the role) +// `account` (address of the account) +// +// - `RoleSetEvent`: Triggered when a role's administrator is set or changed +// Key includes: +// `roleName` (name of the role) +// `newAdmin` (address of the new administrator) +// `sender` (address of the sender) package accesscontrol diff --git a/examples/gno.land/p/demo/timelock/doc.gno b/examples/gno.land/p/demo/timelock/doc.gno new file mode 100644 index 00000000000..025d93ecc17 --- /dev/null +++ b/examples/gno.land/p/demo/timelock/doc.gno @@ -0,0 +1,32 @@ +// Package timelock provides a library for scheduling, cancelling, and +// executing time-locked operations in Gno. It ensures that +// operations are only carried out after a specified delay and offers +// mechanisms for managing and verifying the status of these operations. +// This package leverages an AVL tree for efficient management of timestamps +// and integrates role-based access control for administrative tasks. +// +// # Usage: +// +// import "gno.land/p/demo/timelock" +// import "gno.land/p/demo/accesscontrol" +// +// Initialize timelock utility with an AVL tree and access control. +// timestamps := avl.NewTree() +// adminRole := accesscontrol.NewRole("admin", std.Address("admin-address")) +// timeLockUtil := timelock.NewTimeLockUtil(timestamps, adminRole, 30) +// +// Schedule an operation with a delay of 60 seconds. +// id := seqid.ID() +// timeLockUtil.Schedule(id, 60) +// +// Check if an operation is pending. +// isPending := timeLockUtil.IsPending(id) +// +// Execute the operation when it is pending. +// if timeLockUtil.IsPending(id) { +// timeLockUtil.Execute(id) +// } +// +// Update the minimum delay for future operations. +// timeLockUtil.UpdateDelay(45) +package timelock diff --git a/examples/gno.land/p/demo/timelock/timelock.gno b/examples/gno.land/p/demo/timelock/timelock.gno index 1a90ab3e661..dc280a5cb61 100644 --- a/examples/gno.land/p/demo/timelock/timelock.gno +++ b/examples/gno.land/p/demo/timelock/timelock.gno @@ -1,35 +1,3 @@ -// Package timelock provides a library for scheduling, cancelling, and -// executing time-locked operations in Gno. It ensures that -// operations are only carried out after a specified delay and offers -// mechanisms for managing and verifying the status of these operations. -// This package leverages an AVL tree for efficient management of timestamps -// and integrates role-based access control for administrative tasks. -// -// Example Usage: -// -// import "gno.land/p/demo/timelock" -// import "gno.land/p/demo/accesscontrol" -// -// Initialize timelock utility with an AVL tree and access control. -// timestamps := avl.NewTree() -// adminRole := accesscontrol.NewRole("admin", std.Address("admin-address")) -// timeLockUtil := timelock.NewTimeLockUtil(timestamps, adminRole, 30) -// -// Schedule an operation with a delay of 60 seconds. -// id := seqid.ID() -// timeLockUtil.Schedule(id, 60) -// -// Check if an operation is pending. -// isPending := timeLockUtil.IsPending(id) -// -// Execute the operation when it is pending. -// if timeLockUtil.IsPending(id) { -// timeLockUtil.Execute(id) -// } -// -// Update the minimum delay for future operations. -// timeLockUtil.UpdateDelay(45) - package timelock import (