Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add r/system/names #375

Merged
merged 3 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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