Skip to content

Commit

Permalink
chore: add placeholders for r/system/names (#375)
Browse files Browse the repository at this point in the history
* feat: add r/system/names

Signed-off-by: Manfred Touron <[email protected]>

* chore: add placeholder comment for namespace support

Signed-off-by: Manfred Touron <[email protected]>

* fixup

Signed-off-by: Manfred Touron <[email protected]>

Signed-off-by: Manfred Touron <[email protected]>
  • Loading branch information
moul authored Oct 28, 2022
1 parent c36a2e5 commit 7205e82
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
29 changes: 29 additions & 0 deletions examples/gno.land/r/system/names/genesis.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package names

import "std"

func init() {
// Please, do not edit this file to reserve your username, use a transaction instead.
var (
jaekwon = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj")
manfred = std.Address("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq")
test1 = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
reservedAdmin = std.Address("g100000000000000000000000000000000000000") // FIXME: create a multisig.
reservedNames = []string{
// FIXME: complete this list.
"gno", "gnolang", "tendermint", "cosmos", "hub", "admin",
"ethereum", "bitcoin",
// FIXME: reserve brands? then, require KYC to unlock?
}
)
namespaces.Set("demo", &Space{Admins: []std.Address{jaekwon, manfred}})
namespaces.Set("gnoland", &Space{Admins: []std.Address{jaekwon, manfred}})
namespaces.Set("system", &Space{Admins: []std.Address{jaekwon, manfred}})
namespaces.Set("jaekwon", &Space{Admins: []std.Address{jaekwon}})
namespaces.Set("manfred", &Space{Admins: []std.Address{manfred}})
namespaces.Set("test1", &Space{Admins: []std.Address{test1}})

for _, keyword := range reservedNames {
namespaces.Set(keyword, &Space{Admins: []std.Address{reservedAdmin}})
}
}
60 changes: 60 additions & 0 deletions examples/gno.land/r/system/names/names.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// The realm r/system/names is used to manage namespaces on gno.land.
package names

import (
"std"

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

// "AddPkg" will check if r/system/names exists. If yes, it will
// inspect the realm's state and use the following variable to
// determine if an address can publish a package or not.
var namespaces avl.MutTree // name(string) -> Space

type Space struct {
Admins []std.Address
Editors []std.Address
InPause bool
}

func Register(namespace string) {
// TODO: input sanitization:
// - already exists / reserved.
// - min/max length, format.
// - fees (dynamic, based on length).
panic("not implemented")
}

func AddAdmin(namespace string, newAdmin std.Address) {
// TODO: assertIsAdmin()
panic("not implemented")
}

func RemoveAdmin(namespace string, newAdmin std.Address) {
// TODO: assertIsAdmin()
// TODO: check if self.
panic("not implemented")
}

func AddEditor(namespace string, newAdmin std.Address) {
// TODO: assertIsAdmin()
panic("not implemented")
}

func RemoveEditor(namespace string, newAdmin std.Address) {
// TODO: assertIsAdmin()
// TODO: check if self.
panic("not implemented")
}

func SetInPause(namespace string, state bool) {
// TODO: assertIsAdmin()
panic("not implemented")
}

func Render(path string) string {
// TODO: by namespace.
// TODO: by address.
return "not implemented"
}
8 changes: 8 additions & 0 deletions pkgs/sdk/vm/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ func (vm *VMKeeper) AddPackage(ctx sdk.Context, msg MsgAddPackage) error {
}
// Pay deposit from creator.
pkgAddr := gno.DerivePkgAddr(pkgPath)

// TODO: ACLs.
// - if r/system/names does not exists -> skip validation.
// - loads r/system/names data state.
// - lookup r/system/names.namespaces for `{r,p}/NAMES`.
// - check if caller is in Admins or Editors.
// - check if namespace is not in pause.

err := vm.bank.SendCoins(ctx, creator, pkgAddr, deposit)
if err != nil {
return err
Expand Down

0 comments on commit 7205e82

Please sign in to comment.