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

ns/v0 package

Overview

Package ns is a Plan 9 namespace server for gno.land.

Every account gets a private, persistent namespace: its own RAM root plus a mount table it alone controls. Realms publish file trees into /srv, accounts bind those trees wherever they like, and a read-only rc shell renders the whole thing in gnoweb.

This is the part of Plan 9 that gno does not otherwise have. The chain has a single global tree of realm paths that looks the same to everybody; here a name means what YOU bound it to. Composing two realms that were never written to work together stops being a redeploy and becomes a transaction:

Example
1gnokey maketx call -pkgpath gno.land/r/moul/x/plan9/ns/v0 -func Exec \
2  -args 'bind -ac /srv/dev /dev; echo hello > /tmp/greeting'

SECURITY. Mounted trees are READ-ONLY by construction: ninep.File has no mutating method, so grafting a foreign realm's tree into your namespace cannot be turned into a write against that realm. Writes only ever reach a memfs tree this realm created for you. A crossing write method would mint THIS realm's frame for the callee, which is the confused-deputy shape that r/gov/dao's Executor relies on deliberately and p/nt/grc20's Teller refuses deliberately; it is out of scope for v0. See moul/gno-contracts#136.

NOTICE. 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 is not affiliated with, endorsed by, or sponsored by them, and contains no Plan 9 code: it borrows the vocabulary so that the design reads without a glossary, and it is an homage, asking what that ecosystem's spirit looks like on a chain. Full attribution: NOTICE.md at the root of moul/gno-contracts.

Functions

Exec

func Exec(cur realm, line string) string

Exec runs a command line against the CALLER's namespace and returns its output. The namespace belongs to cur.Previous().Address(), so a user gets theirs and a realm gets its own.

An error panics, so a half-applied command line reverts with the transaction rather than leaving a namespace nobody asked for.

Param

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/moul/x/plan9/ns/v0" -func "Exec" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "https://rpc.gno.land" ADDRESSgnokey query -remote "https://rpc.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/x/plan9/ns/v0" -func "Exec" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.gno.land" call.tx
  

Keys

func Keys() []string

Keys lists the namespaces that exist, in order.

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/plan9/ns/v0.Keys()"

Result

Namespace

func Namespace(key string) string

Namespace returns key's mount table, in ns(1) format.

Param

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/plan9/ns/v0.Namespace()"

Result

Post

func Post(cur realm, name string, f ninep.File)

Post publishes a file tree under name in /srv, where any account can bind it. The posting realm is recorded and is the only one that may Unpost.

Names are first come, first served, which is fine for an experiment and would not be for anything else.

Params

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/moul/x/plan9/ns/v0" -func "Post" -args $'' -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "https://rpc.gno.land" ADDRESSgnokey query -remote "https://rpc.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/x/plan9/ns/v0" -func "Post" -args $'' -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.gno.land" call.tx
  

Render

func Render(path string) string

Render browses a namespace.

Example
1Render("")                  overview, posted services, how to drive it
2Render("ns?u=<key>")        the mount table
3Render("ls/bin?u=<key>")    a directory listing (ls -l)
4Render("cat/tmp/greeting")  a file
5Render("stat/bin")          the 9P stat, with the union width
6Render("walk/bin/rc")       how each element of a path resolves
7Render("rc?c=<command>")    any read-only rc command line

?u= selects the namespace; it defaults to the demo one.

Param

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/plan9/ns/v0.Render()"

Result

Reset

func Reset(cur realm)

Reset discards the caller's namespace, so the next use rebuilds the default.

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/moul/x/plan9/ns/v0" -func "Reset" -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "https://rpc.gno.land" ADDRESSgnokey query -remote "https://rpc.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/x/plan9/ns/v0" -func "Reset" -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.gno.land" call.tx
  

ResetDemo

func ResetDemo(cur realm)

ResetDemo rebuilds the demo namespace. Anyone may call it: it is a demo, and the alternative is a demo that the first visitor ruins for everybody.

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/moul/x/plan9/ns/v0" -func "ResetDemo" -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "https://rpc.gno.land" ADDRESSgnokey query -remote "https://rpc.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/x/plan9/ns/v0" -func "ResetDemo" -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.gno.land" call.tx
  

Run

func Run(key, line string) (string, error)

Run executes a READ-ONLY command line against key's namespace. It is the query side of Exec: no transaction, no writes, safe from Render.

Params

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/plan9/ns/v0.Run(,)"

Result

Services

func Services() []string

Services lists the posted service names, in order.

Command

gnokey query vm/qeval -remote "https://rpc.gno.land" -data "gno.land/r/moul/x/plan9/ns/v0.Services()"

Result

Unpost

func Unpost(cur realm, name string)

Unpost withdraws a service. Only the realm that posted it may do so.

Param

Command

# WARNING: This command is running in an INSECURE mode.
# It is strongly recommended to use a hardware device for signing
# and avoid trusting any computer connected to the internet,
# as your private keys could be exposed.

gnokey maketx call -pkgpath "gno.land/r/moul/x/plan9/ns/v0" -func "Unpost" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -chainid "gnoland-1" -remote "https://rpc.gno.land" ADDRESSgnokey query -remote "https://rpc.gno.land" auth/accounts/ADDRESS
gnokey maketx call -pkgpath "gno.land/r/moul/x/plan9/ns/v0" -func "Unpost" -args $'' -gas-fee 1000000ugnot -gas-wanted 1_000_000_000 -send "" -broadcast=false ADDRESS > call.tx
gnokey sign -tx-path call.tx -chainid "gnoland-1" -account-number ACCOUNTNUMBER -account-sequence SEQUENCENUMBER ADDRESS
gnokey broadcast -remote "https://rpc.gno.land" call.tx