Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
leohhhn committed Nov 20, 2024
1 parent 38c2b9a commit 4970a59
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
3 changes: 3 additions & 0 deletions examples/gno.land/p/demo/pausable/pausable.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pausable

import (
"errors"
"std"

"gno.land/p/demo/ownable"
Expand All @@ -11,6 +12,8 @@ type Pausable struct {
paused bool
}

var ErrPaused = errors.New("realm is currently paused")

// New returns a new Pausable struct with non-paused state as default
func New() *Pausable {
return &Pausable{
Expand Down
6 changes: 0 additions & 6 deletions examples/gno.land/p/demo/users/users.gno
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ type User struct {
Profile string
Number int
Block int
Invites int
Inviter std.Address
}

func (u *User) Render() string {
Expand All @@ -34,10 +32,6 @@ func (u *User) Render() string {
out += ufmt.Sprintf("- ID #%d\n\n", u.Number)
out += ufmt.Sprintf("- Address: %s\n\n", u.Address.String())
out += ufmt.Sprintf("- Registered at block #%d\n\n", u.Block)
out += ufmt.Sprintf("- Leftover invites: %d\n\n", u.Invites)
if u.Inviter != "" {
out += ufmt.Sprintf("- Inviter: %s\n\n", u.Inviter.String())
}

return out
}
6 changes: 6 additions & 0 deletions examples/gno.land/r/gnoland/users/errors.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package users

import "errors"

var ErrInvalidUsername = errors.New("users: invalid username")
var ErrAlreadyExists = errors.New("users: username already exists")
1 change: 1 addition & 0 deletions examples/gno.land/r/gnoland/users/render.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package users
42 changes: 42 additions & 0 deletions examples/gno.land/r/gnoland/users/users.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package users

import (
"github.com/gnolang/gno/examples/gno.land/p/demo/avl"
"github.com/gnolang/gno/examples/gno.land/p/demo/ownable"
p "github.com/gnolang/gno/examples/gno.land/p/demo/pausable"
"github.com/gnolang/gno/examples/gno.land/p/demo/seqid"
"regexp"
)

const reValidUsername = "^[a-zA-Z]{3}[a-zA-Z0-9]*[0-9]{3}$\n"

var (
store avl.Tree //
idCounter seqid.ID
admin = ownable.NewWithAddress("") // @moul /// switch to dao managed down the line
pausable = p.NewFromOwnable(admin) //
reUsername = regexp.MustCompile(reValidUsername)
)

func init() {
// PreRegister()
}

func Register(username, bio string) error {
if pausable.IsPaused() {
return p.ErrPaused
}

if store.Has(username) {
return ErrAlreadyExists
}

matched, _ := regexp.MatchString(reValidUsername, username)
if !matched {
return ErrInvalidUsername
}

store.Set(username)

return nil
}

0 comments on commit 4970a59

Please sign in to comment.