diff --git a/examples/gno.land/r/demo/emit/emit.gno b/examples/gno.land/r/demo/emit/emit.gno new file mode 100644 index 00000000000..a3de8f764a5 --- /dev/null +++ b/examples/gno.land/r/demo/emit/emit.gno @@ -0,0 +1,12 @@ +// Package emit demonstrates how to use the std.Emit() function +// to emit Gno events that can be used to track data changes off-chain. +// std.Emit is variadic; apart from the event name, it can take in any number of key-value pairs to emit. +package emit + +import ( + "std" +) + +func Emit(value string) { + std.Emit("EventName", "key", value) +} diff --git a/examples/gno.land/r/demo/emit/gno.mod b/examples/gno.land/r/demo/emit/gno.mod new file mode 100644 index 00000000000..cf9c2b6b98e --- /dev/null +++ b/examples/gno.land/r/demo/emit/gno.mod @@ -0,0 +1 @@ +module gno.land/r/demo/emit diff --git a/examples/gno.land/r/demo/event/z1_filetest.gno b/examples/gno.land/r/demo/emit/z1_filetest.gno similarity index 61% rename from examples/gno.land/r/demo/event/z1_filetest.gno rename to examples/gno.land/r/demo/emit/z1_filetest.gno index b138aa4351c..7dcdbf8e0a3 100644 --- a/examples/gno.land/r/demo/event/z1_filetest.gno +++ b/examples/gno.land/r/demo/emit/z1_filetest.gno @@ -1,34 +1,34 @@ package main -import "gno.land/r/demo/event" +import "gno.land/r/demo/emit" func main() { - event.Emit("foo") - event.Emit("bar") + emit.Emit("foo") + emit.Emit("bar") } // Events: // [ // { -// "type": "TAG", +// "type": "EventName", // "attrs": [ // { // "key": "key", // "value": "foo" // } // ], -// "pkg_path": "gno.land/r/demo/event", +// "pkg_path": "gno.land/r/demo/emit", // "func": "Emit" // }, // { -// "type": "TAG", +// "type": "EventName", // "attrs": [ // { // "key": "key", // "value": "bar" // } // ], -// "pkg_path": "gno.land/r/demo/event", +// "pkg_path": "gno.land/r/demo/emit", // "func": "Emit" // } // ] diff --git a/examples/gno.land/r/demo/event/event.gno b/examples/gno.land/r/demo/event/event.gno deleted file mode 100644 index 9e5de540734..00000000000 --- a/examples/gno.land/r/demo/event/event.gno +++ /dev/null @@ -1,9 +0,0 @@ -package event - -import ( - "std" -) - -func Emit(value string) { - std.Emit("TAG", "key", value) -} diff --git a/examples/gno.land/r/demo/event/gno.mod b/examples/gno.land/r/demo/event/gno.mod deleted file mode 100644 index 64987d43d79..00000000000 --- a/examples/gno.land/r/demo/event/gno.mod +++ /dev/null @@ -1 +0,0 @@ -module gno.land/r/demo/event diff --git a/examples/gno.land/r/demo/hello_world/gno.mod b/examples/gno.land/r/demo/hello_world/gno.mod new file mode 100644 index 00000000000..9561cd4f077 --- /dev/null +++ b/examples/gno.land/r/demo/hello_world/gno.mod @@ -0,0 +1 @@ +module gno.land/r/demo/hello_world diff --git a/examples/gno.land/r/demo/hello_world/hello.gno b/examples/gno.land/r/demo/hello_world/hello.gno new file mode 100644 index 00000000000..312520de44d --- /dev/null +++ b/examples/gno.land/r/demo/hello_world/hello.gno @@ -0,0 +1,17 @@ +// Package hello_world demonstrates the usage of the Render() function. +// Render() can be called via the vm/qrender ABCI query off-chain to +// retrieve realm state or any other custom data defined by the realm +// developer. The vm/qrender query allows for additional data to be +// passed in with the call, which can be utilized as the path argument +// to the Render() function. This allows developers to create different +// "renders" of their realms depending on the data which is passed in, +// such as pagination, admin dashboards, and more. +package hello_world + +func Render(path string) string { + if path == "" { + return "# Hello, 世界!" + } + + return "# Hello, " + path + "!" +} diff --git a/examples/gno.land/r/demo/hello_world/hello_test.gno b/examples/gno.land/r/demo/hello_world/hello_test.gno new file mode 100644 index 00000000000..4c3d86c556a --- /dev/null +++ b/examples/gno.land/r/demo/hello_world/hello_test.gno @@ -0,0 +1,19 @@ +package hello_world + +import ( + "testing" +) + +func TestHello(t *testing.T) { + expected := "# Hello, 世界!" + got := Render("") + if got != expected { + t.Fatalf("Expected %s, got %s", expected, got) + } + + got = Render("world") + expected = "# Hello, world!" + if got != expected { + t.Fatalf("Expected %s, got %s", expected, got) + } +}