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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

Playground

gnomod.toml

module = "gno.land/r/nym-moultest123/demo/microposts/v0"
gno = "0.9"

[addpkg]
  creator = "g1ml9grtwnpzqn3hre5ve5vjdlmv2srrmpmc0dsv"
  height = 186406
  max_deposit = "5000000ugnot"

microposts_test.gno

package microposts

// empty file just to make sure that `gno test` tries to parse the implementation.

post.gno

package microposts

import (
	"time"
)

type Post struct {
	text      string
	author    address
	createdAt time.Time
}

func (p Post) String() string {
	out := p.text + "\n"
	out += "_" + p.createdAt.Format("02 Jan 2006, 15:04") + ", by " + p.author.String() + "_"
	return out
}

realm.gno

package microposts

import (
	"chain/runtime/unsafe"
	"strconv"
	"time"
)

var posts []*Post

func CreatePost(text string) {
	posts = append(posts, &Post{
		text:      text,
		author:    unsafe.PreviousRealm().Address(), // provided by env
		createdAt: time.Now(),
	})
}

func Render(_ string) string {
	out := "# Posts\n"
	for i := len(posts) - 1; i >= 0; i-- {
		out += "### Post " + strconv.Itoa(i) + "\n" + posts[i].String()
	}
	return out
}

render_example_test.gno

package microposts

// ExampleRender pins the realm's Render output as a testable example.
func ExampleRender() {
	print(Render(""))
	// Output:
	// # Posts
}