Skip to content

Commit

Permalink
Merge branch 'master' into define-MsgNoop
Browse files Browse the repository at this point in the history
  • Loading branch information
linhpn99 authored Jul 9, 2024
2 parents 712394b + 6432573 commit 5551b30
Show file tree
Hide file tree
Showing 59 changed files with 816 additions and 228 deletions.
64 changes: 60 additions & 4 deletions docs/concepts/namespaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ id: namespaces

# Namespaces

Namespaces provide users with the exclusive capability to publish contracts under their designated namespaces, similar to GitHub's user and organization model.
Namespaces provide users with the exclusive capability to publish contracts under their designated namespaces,
similar to GitHub's user and organization model.

This feature is currently a work in progress (WIP). To learn more about namespaces, please checkout https://github.com/gnolang/gno/issues/1107.
:::warn Not enabled

This feature isn't enabled by default on the portal loop chain and is currently available only on test4.gno.land.

:::

# Package Path

A package path is a unique identifier for each package/realm. It specifies the location of the package source code which helps differentiate it from others. You can use a package path to:
A package path is a unique identifier for each package/realm. It specifies the location of the package source
code which helps differentiate it from others. You can use a package path to:

- Call a specific function from a package/realm. (e.g using `gnokey maketx call`)
- Import it in other packages/realms.
Expand All @@ -21,7 +27,9 @@ Here's a breakdown of the structure of a package path:
- Type: Defines the type of package.
- `p/`: [Package](packages.md)
- `r/`: [Realm](realms.md)
- Namespace: A namespace can be included after the type (e.g., user or organization name). Namespaces are a way to group related packages or realms, but currently ownership cannot be claimed. (see [Issue #1107](https://github.com/gnolang/gno/issues/1107) for more info)
- Namespace: A namespace can be included after the type (e.g., user or organization name). Namespaces are a
way to group related packages or realms, but currently ownership cannot be claimed. (see
[Issue#1107](https://github.com/gnolang/gno/issues/1107) for more info)
- Remaining Path: The remaining part of the path.
- Can only contain alphanumeric characters (letters and numbers) and underscores.
- No special characters allowed (except underscore).
Expand All @@ -33,3 +41,51 @@ Examples:

- `gno.land/p/demo/avl`: This signifies a package named `avl` within the `demo` namespace.
- `gno.land/r/gnoland/home`: This signifies a realm named `home` within the `gnoland` namespace.

## Registration Process

The registration process is contract-based. The `AddPkg` command references
`sys/users` for filtering, which in turn is based on `r/demo/users`.

When `sys/users` is enabled, you need to register a name using `r/demo/users`. You can call the
`r/demo/users.Register` function to register the name for the caller's address.

> ex: `test1` user registering as `patrick`
```bash
$ gnokey maketx call -pkgpath gno.land/r/demo/users \
-func Register \
-gas-fee 1000000ugnot -gas-wanted 2000000 \
-broadcast \
-chainid=test4 \
-send=20000000ugnot \
-args '' \
-args 'patrick' \
-args 'My Profile Quote' test1
```

:::note Chain-ID

Do not forget to update chain id, adequate to the network you're interacting with

:::


After successful registration, you can add a package under the registered namespace.

## Anonymous Namespace

Gno.land offers the ability to add a package without having a registered namespace.
You can do this by using your own address as a namespace. This is formatted as `{p,r}/{std.Address}/**`.

> ex: with `test1` user adding a package `microblog` using his own address as namespace
```bash
$ gnokey maketx addpkg \
--pkgpath "gno.land/r/g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5/microblog" \
--pkgdir "examples/gno.land/p/demo/microblog" \
--deposit 100000000ugnot \
--gas-fee 1000000ugnot \
--gas-wanted 2000000 \
--broadcast \
--chainid test4 \
test1
```
4 changes: 2 additions & 2 deletions examples/gno.land/r/demo/boards/z_0_b_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 199000000ugnot
// SEND: 19900000ugnot

import (
"gno.land/r/demo/boards"
Expand All @@ -20,4 +20,4 @@ func main() {
}

// Error:
// payment must not be less than 200000000
// payment must not be less than 20000000
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_0_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 200000000ugnot
// SEND: 20000000ugnot

import (
"gno.land/r/demo/boards"
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_10_b_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 2000000000ugnot
// SEND: 200000000ugnot

import (
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_11_a_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 2000000000ugnot
// SEND: 200000000ugnot

import (
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_11_b_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 2000000000ugnot
// SEND: 200000000ugnot

import (
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_11_c_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 2000000000ugnot
// SEND: 200000000ugnot

import (
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_11_d_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 2000000000ugnot
// SEND: 200000000ugnot

import (
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_11_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 2000000000ugnot
// SEND: 200000000ugnot

import (
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_5_b_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

// SEND: 2000000000ugnot
// SEND: 200000000ugnot

import (
"std"
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_5_c_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

// SEND: 2000000000ugnot
// SEND: 200000000ugnot

import (
"std"
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_5_d_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

// SEND: 2000000000ugnot
// SEND: 200000000ugnot

import (
"std"
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_7_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 2000000000ugnot
// SEND: 200000000ugnot

import (
"gno.land/r/demo/boards"
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/z_8_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// PKGPATH: gno.land/r/demo/boards_test
package boards_test

// SEND: 2000000000ugnot
// SEND: 200000000ugnot

import (
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/groups/z_0_b_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ func main() {
}

// Error:
// payment must not be less than 200000000
// payment must not be less than 20000000
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/groups/z_1_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

var gid groups.GroupID

const admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")
const admin = std.Address("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq")

func main() {
caller := std.GetOrigCaller() // main
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/groups/z_2_a_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

var gid groups.GroupID

const admin = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")
const admin = std.Address("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq")

func main() {
caller := std.GetOrigCaller() // main
Expand Down
66 changes: 66 additions & 0 deletions examples/gno.land/r/demo/users/preregister.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package users

import (
"std"

"gno.land/p/demo/users"
)

// pre-restricted names
var preRestrictedNames = []string{
"bitcoin", "cosmos", "newtendermint", "ethereum",
}

// pre-registered users
var preRegisteredUsers = []struct {
Name string
Address std.Address
}{
// system name
{"archives", "g1xlnyjrnf03ju82v0f98ruhpgnquk28knmjfe5k"}, // -> @r_archives
{"demo", "g13ek2zz9qurzynzvssyc4sthwppnruhnp0gdz8n"}, // -> @r_demo
{"gno", "g19602kd9tfxrfd60sgreadt9zvdyyuudcyxsz8a"}, // -> @r_gno
{"gnoland", "g1g3lsfxhvaqgdv4ccemwpnms4fv6t3aq3p5z6u7"}, // -> @r_gnoland
{"gnolang", "g1yjlnm3z2630gg5mryjd79907e0zx658wxs9hnd"}, // -> @r_gnolang
{"gov", "g1g73v2anukg4ej7axwqpthsatzrxjsh0wk797da"}, // -> @r_gov
{"nt", "g15ge0ae9077eh40erwrn2eq0xw6wupwqthpv34l"}, // -> @r_nt
{"sys", "g1r929wt2qplfawe4lvqv9zuwfdcz4vxdun7qh8l"}, // -> @r_sys
{"x", "g164sdpew3c2t3rvxj3kmfv7c7ujlvcw2punzzuz"}, // -> @r_x
}

func init() {
// add pre-registered users
for _, res := range preRegisteredUsers {
// assert not already registered.
_, ok := name2User.Get(res.Name)
if ok {
panic("name already registered")
}

_, ok = addr2User.Get(res.Address.String())
if ok {
panic("address already registered")
}

counter++
user := &users.User{
Address: res.Address,
Name: res.Name,
Profile: "",
Number: counter,
Invites: int(0),
Inviter: admin,
}
name2User.Set(res.Name, user)
addr2User.Set(res.Address.String(), user)
}

// add pre-restricted names
for _, name := range preRestrictedNames {
if _, ok := name2User.Get(name); ok {
panic("name already registered")
}

restricted.Set(name, true)
}
}
Loading

0 comments on commit 5551b30

Please sign in to comment.