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

render_example_test.gno

2.57 Kb · 61 lines
 1package dev
 2
 3// ExampleRender pins the device index. It carries no chain value, so it does
 4// not move with the block height the way the devices themselves do.
 5func ExampleRender() {
 6	print(Render(""))
 7	// Output:
 8	// # /dev
 9	//
10	// The chain as a Plan 9 device tree. Each file is a function: reading it runs code, so `/dev/height` is never stale.
11	//
12	// Posted to [`r/moul/x/plan9/ns`](/r/moul/x/plan9/ns/v0)'s `/srv` at deploy time, so no realm has to import this one to use it:
13	//
14	// ```
15	// bind /srv/dev /dev
16	// ```
17	//
18	// | device | contents |
19	// |---|---|
20	// | [`caller`](:cat/caller) | pkgpath of the realm that crossed into this read |
21	// | [`domain`](:cat/domain) | the chain domain |
22	// | [`drivers`](:cat/drivers) | this table |
23	// | [`height`](:cat/height) | current block height |
24	// | [`null`](:cat/null) | always empty; the bit bucket |
25	// | [`random`](:cat/random) | sha256 of chain id and height, hex; block-deterministic, NOT unpredictable |
26	// | [`session`](:cat/session) | the calling key's session scope, one AllowPath per line |
27	// | [`sysname`](:cat/sysname) | the chain id |
28	// | [`time`](:cat/time) | block time, RFC3339 |
29	// | [`user`](:cat/user) | the origin caller's address |
30	// | [`zero`](:cat/zero) | endless NUL bytes; reads exactly what you ask for |
31	//
32	// Design and analysis: [moul/gno-contracts#136](https://github.com/moul/gno-contracts/issues/136).
33	//
34	// _Not affiliated with Plan 9. Plan 9 from Bell Labs is the work of the Computing Science Research Center at Bell Labs; the name and the marks are theirs, and the copyright is held by the [Plan 9 Foundation](https://p9f.org). This realm borrows the vocabulary and none of the code: it is an homage, asking what that ecosystem's spirit looks like on a chain._
35}
36
37// ExampleRender_cat pins one device read. /dev/drivers is the one device whose
38// contents are fixed, which makes it the only one an example can assert; the
39// chain-derived ones are checked against chain/runtime in dev_test.gno.
40func ExampleRender_cat() {
41	print(Render("cat/drivers"))
42	// Output:
43	// # /dev/drivers
44	//
45	// ```
46	// caller	pkgpath of the realm that crossed into this read
47	// domain	the chain domain
48	// drivers	this table
49	// height	current block height
50	// null	always empty; the bit bucket
51	// random	sha256 of chain id and height, hex; block-deterministic, NOT unpredictable
52	// session	the calling key's session scope, one AllowPath per line
53	// sysname	the chain id
54	// time	block time, RFC3339
55	// user	the origin caller's address
56	// zero	endless NUL bytes; reads exactly what you ask for
57	//
58	// ```
59	//
60	// [all devices](:)
61}