Skip to content

Commit

Permalink
modify keeper to use r/sys/names instead of r/sys/users
Browse files Browse the repository at this point in the history
  • Loading branch information
leohhhn committed Jan 16, 2025
1 parent 70aae18 commit 4c6b55a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions gno.land/pkg/sdk/vm/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ var reNamespace = regexp.MustCompile(`^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/(?:r|p)/([\.

// checkNamespacePermission check if the user as given has correct permssion to on the given pkg path
func (vm *VMKeeper) checkNamespacePermission(ctx sdk.Context, creator crypto.Address, pkgPath string) error {
sysUsersPkg := vm.getSysUsersPkgParam(ctx)
if sysUsersPkg == "" {
sysNamesPkg := vm.getSysNamesPkgParam(ctx)
if sysNamesPkg == "" {
return nil
}
chainDomain := vm.getChainDomainParam(ctx)
Expand All @@ -257,7 +257,7 @@ func (vm *VMKeeper) checkNamespacePermission(ctx sdk.Context, creator crypto.Add
username := match[1]

// if `sysUsersPkg` does not exist -> skip validation.
usersPkg := store.GetPackage(sysUsersPkg, false)
usersPkg := store.GetPackage(sysNamesPkg, false)
if usersPkg == nil {
return nil
}
Expand Down Expand Up @@ -289,13 +289,13 @@ func (vm *VMKeeper) checkNamespacePermission(ctx sdk.Context, creator crypto.Add
})
defer m.Release()

// call $sysUsersPkg.IsAuthorizedAddressForName("<user>")
// We only need to check by name here, as address have already been check
// call sysNamesPkg.IsAuthorizedAddressForName("<user>")
// We only need to check by name here, as addresses have already been checked
mpv := gno.NewPackageNode("main", "main", nil).NewPackage()
m.SetActivePackage(mpv)
m.RunDeclaration(gno.ImportD("users", sysUsersPkg))
m.RunDeclaration(gno.ImportD("names", sysNamesPkg))
x := gno.Call(
gno.Sel(gno.Nx("users"), "IsAuthorizedAddressForName"),
gno.Sel(gno.Nx("names"), "IsAuthorizedAddressForName"),
gno.Str(creator.String()),
gno.Str(username),
)
Expand Down
10 changes: 5 additions & 5 deletions gno.land/pkg/sdk/vm/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package vm
import "github.com/gnolang/gno/tm2/pkg/sdk"

const (
sysUsersPkgParamPath = "gno.land/r/sys/params.sys.users_pkgpath.string"
sysNamesPkgParamPath = "gno.land/r/sys/params.sys.names_pkgpath.string"
chainDomainParamPath = "gno.land/r/sys/params.chain_domain.string"
)

Expand All @@ -13,8 +13,8 @@ func (vm *VMKeeper) getChainDomainParam(ctx sdk.Context) string {
return chainDomain
}

func (vm *VMKeeper) getSysUsersPkgParam(ctx sdk.Context) string {
var sysUsersPkg string
vm.prmk.GetString(ctx, sysUsersPkgParamPath, &sysUsersPkg)
return sysUsersPkg
func (vm *VMKeeper) getSysNamesPkgParam(ctx sdk.Context) string {
var sysNamesPkg string
vm.prmk.GetString(ctx, sysNamesPkgParamPath, &sysNamesPkg)
return sysNamesPkg
}

0 comments on commit 4c6b55a

Please sign in to comment.