Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

hub source pure

Readme View source

hub

Simplified, read-only view types over gno.land/p/gnoland/boards data: Board, Thread, Comment, Flag and Member.

Realms use these to expose board contents through a query API without handing callers access to their own persistent state.

Invariant

A safe type is a snapshot, never a live reference.

Each NewSafe* constructor reads the fields it needs off the boards value and copies them. It keeps no pointer to the source, so a value returned to a caller cannot be used to reach — let alone mutate — the realm data it was built from. Counts (ThreadCount, FlagCount, …) are resolved at construction time and do not track later changes.

Keep it that way when adding fields:

  • Copy scalars. Never store the *boards.Board / *boards.Post the constructor was handed, and never expose a boards.PostStorage, boards.FlagStorage or boards.Permissions — those are handles onto live realm state.
  • Deep-copy slices and maps, as NewSafeBoard does for Aliases and NewSafeMember does for Roles. Copy on the way out too: a getter that returns the stored slice lets a caller mutate the snapshot and change what the same value reports on the next call, so Aliases() and Roles() each return a fresh slice.
  • Convert boards types to plain ones where practical, the way Member flattens []boards.Role to []string.

An earlier version of these types carried a ref field plus Iterate* methods that walked realm storage through it. That is the thing this package exists to not do.

Usage

 1import (
 2    "gno.land/p/gnoland/boards"
 3    hubexts "gno.land/p/gnoland/boards/exts/hub"
 4)
 5
 6func GetBoard(id uint64) (hubexts.Board, bool) {
 7    b, found := gBoards.Get(boards.ID(id))
 8    if !found {
 9        return hubexts.Board{}, false
10    }
11    return hubexts.NewSafeBoard(b), true
12}

The constructors panic on a nil reference, and on a post whose kind does not match (NewSafeThread on a comment, or NewSafeComment on a thread). Resolve and check existence before calling them.

Functions 5

func NewSafeBoard

1func NewSafeBoard(ref *boards.Board) Board
source

NewSafeBoard creates a safe board.

func NewSafeComment

1func NewSafeComment(ref *boards.Post) Comment
source

NewSafeComment creates a safe comment.

func NewSafeFlag

1func NewSafeFlag(ref boards.Flag) Flag
source

NewSafeFlag creates a safe flag.

func NewSafeMember

1func NewSafeMember(ref boards.User) Member
source

NewSafeMember creates a safe board member.

func NewSafeThread

1func NewSafeThread(ref *boards.Post) Thread
source

NewSafeThread creates a safe thread.

Types 5

type Board

struct
 1type Board struct {
 2	// id is the unique identifier of the board.
 3	id uint64
 4
 5	// name is the current name of the board.
 6	name string
 7
 8	// aliases contains a list of alternative names for the board.
 9	aliases []string
10
11	// readonly indicates that the board is readonly.
12	readonly bool
13
14	// threadCount contains the number of threads within the board.
15	threadCount int
16
17	// memberCount contains the number of members of the board.
18	memberCount int
19
20	// creator is the account address that created the board.
21	creator address
22
23	// createdAt is the board's creation time as Unix time.
24	createdAt int64
25
26	// updatedAt is the board's update time as Unix time.
27	updatedAt int64
28}
source

Board defines a safe type for boards.

Methods on Board

func Aliases

method on Board
1func (b Board) Aliases() []string
source

Aliases returns the list of alternative names for the board.

func CreatedAt

method on Board
1func (b Board) CreatedAt() int64
source

CreatedAt returns the board's creation time as Unix time.

func Creator

method on Board
1func (b Board) Creator() address
source

Creator returns the account address that created the board.

func ID

method on Board
1func (b Board) ID() uint64
source

ID returns the unique identifier of the board.

func MemberCount

method on Board
1func (b Board) MemberCount() int
source

MemberCount returns the number of members of the board.

func Name

method on Board
1func (b Board) Name() string
source

Name returns the current name of the board.

func Readonly

method on Board
1func (b Board) Readonly() bool
source

Readonly indicates that the board is readonly.

func ThreadCount

method on Board
1func (b Board) ThreadCount() int
source

ThreadCount returns the number of threads within the board.

func UpdatedAt

method on Board
1func (b Board) UpdatedAt() int64
source

UpdatedAt returns the board's update time as Unix time.

type Comment

struct
 1type Comment struct {
 2	// id is the unique identifier of the comment.
 3	id uint64
 4
 5	// boardID is the board ID where comment is created.
 6	boardID uint64
 7
 8	// threadID is the ID of the thread where comment is created.
 9	threadID uint64
10
11	// parentID is the ID of the parent comment or reply.
12	parentID uint64
13
14	// body contains the comment's content.
15	body string
16
17	// hidden indicates that comment is hidden.
18	hidden bool
19
20	// replyCount contains the number of comments replies.
21	// Count only includes top level replies, sub-replies are not included.
22	replyCount int
23
24	// flagCount contains the number of flags that comment has.
25	flagCount int
26
27	// creator is the account address that created the comment or reply.
28	creator address
29
30	// createdAt is thread's creation time as Unix time.
31	createdAt int64
32
33	// updatedAt is thread's update time as Unix time.
34	updatedAt int64
35}
source

Comment defines a type for threads comment/replies.

Methods on Comment

func BoardID

method on Comment
1func (c Comment) BoardID() uint64
source

BoardID returns the board ID where the comment is created.

func Body

method on Comment
1func (c Comment) Body() string
source

Body returns the comment's content.

func CreatedAt

method on Comment
1func (c Comment) CreatedAt() int64
source

CreatedAt returns the comment's creation time as Unix time.

func Creator

method on Comment
1func (c Comment) Creator() address
source

Creator returns the account address that created the comment or reply.

func FlagCount

method on Comment
1func (c Comment) FlagCount() int
source

FlagCount returns the number of flags that the comment has.

func Hidden

method on Comment
1func (c Comment) Hidden() bool
source

Hidden indicates that the comment is hidden.

func ID

method on Comment
1func (c Comment) ID() uint64
source

ID returns the unique identifier of the comment.

func ParentID

method on Comment
1func (c Comment) ParentID() uint64
source

ParentID returns the ID of the parent comment or reply.

func ReplyCount

method on Comment
1func (c Comment) ReplyCount() int
source

ReplyCount returns the number of comment replies. Count only includes top level replies, sub-replies are not included.

func ThreadID

method on Comment
1func (c Comment) ThreadID() uint64
source

ThreadID returns the ID of the thread where the comment is created.

func UpdatedAt

method on Comment
1func (c Comment) UpdatedAt() int64
source

UpdatedAt returns the comment's update time as Unix time.

type Flag

struct
1type Flag struct {
2	// user is the user that flagged.
3	user address
4
5	// reason is the reason for flagging.
6	reason string
7}
source

Flag defines a type for thread and comment flags.

Methods on Flag

func Reason

method on Flag
1func (f Flag) Reason() string
source

Reason returns the reason for flagging.

func User

method on Flag
1func (f Flag) User() address
source

User returns the user that flagged.

type Member

struct
1type Member struct {
2	// address is the account address of the member.
3	address address
4
5	// roles contains the names of the roles assigned to the member.
6	roles []string
7}
source

Member defines a safe type for board members.

Methods on Member

func Address

method on Member
1func (m Member) Address() address
source

Address returns the account address of the member.

func Roles

method on Member
1func (m Member) Roles() []string
source

Roles returns the names of the roles assigned to the member.

type Thread

struct
 1type Thread struct {
 2	// id is the unique identifier of the thread.
 3	id uint64
 4
 5	// originalBoardID contains the board ID of the original thread when current is a repost.
 6	originalBoardID uint64
 7
 8	// originalThreadID contains the ID of the original thread when current is a repost.
 9	originalThreadID uint64
10
11	// boardID is the board ID where thread is created.
12	boardID uint64
13
14	// title contains thread's title.
15	title string
16
17	// body contains content of the thread.
18	body string
19
20	// hidden indicates that thread is hidden.
21	hidden bool
22
23	// readonly indicates that thread is readonly.
24	readonly bool
25
26	// commentCount contains the number of thread comments.
27	// Count only includes top level comment, replies are not included.
28	commentCount int
29
30	// repostCount contains the number of times thread has been reposted.
31	repostCount int
32
33	// flagCount contains the number of flags that thread has.
34	flagCount int
35
36	// creator is the account address that created the thread.
37	creator address
38
39	// createdAt is thread's creation time as Unix time.
40	createdAt int64
41
42	// updatedAt is thread's update time as unix time.
43	updatedAt int64
44}
source

Thread defines a type for board threads.

Methods on Thread

func BoardID

method on Thread
1func (t Thread) BoardID() uint64
source

BoardID returns the board ID where the thread is created.

func Body

method on Thread
1func (t Thread) Body() string
source

Body returns the content of the thread.

func CommentCount

method on Thread
1func (t Thread) CommentCount() int
source

CommentCount returns the number of thread comments. Count only includes top level comment, replies are not included.

func CreatedAt

method on Thread
1func (t Thread) CreatedAt() int64
source

CreatedAt returns the thread's creation time as Unix time.

func Creator

method on Thread
1func (t Thread) Creator() address
source

Creator returns the account address that created the thread.

func FlagCount

method on Thread
1func (t Thread) FlagCount() int
source

FlagCount returns the number of flags that the thread has.

func Hidden

method on Thread
1func (t Thread) Hidden() bool
source

Hidden indicates that the thread is hidden.

func ID

method on Thread
1func (t Thread) ID() uint64
source

ID returns the unique identifier of the thread.

func OriginalBoardID

method on Thread
1func (t Thread) OriginalBoardID() uint64
source

OriginalBoardID returns the board ID of the original thread when current is a repost.

func OriginalThreadID

method on Thread
1func (t Thread) OriginalThreadID() uint64
source

OriginalThreadID returns the ID of the original thread when current is a repost.

func Readonly

method on Thread
1func (t Thread) Readonly() bool
source

Readonly indicates that the thread is readonly.

func RepostCount

method on Thread
1func (t Thread) RepostCount() int
source

RepostCount returns the number of times the thread has been reposted.

func Title

method on Thread
1func (t Thread) Title() string
source

Title returns the thread's title.

func UpdatedAt

method on Thread
1func (t Thread) UpdatedAt() int64
source

UpdatedAt returns the thread's update time as Unix time.

Imports 2

Source Files 12