-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add admindao realm to store all AdminDAO instances
IMPORTANT: There is an issue saving the boards2 realm, saving it in the admindao realm causes that board realms fail when being created/setted with the following error: "cannot modify external-realm or non-realm object". The only initial difference between realm and board DAOs is that the realm DAO is created on deploy using the `init()` function. The issue with setting the admin DAO must be figured out.
- Loading branch information
1 parent
7b2f980
commit 83d0b93
Showing
11 changed files
with
123 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package admindao | ||
|
||
import ( | ||
"path" | ||
"std" | ||
"strings" | ||
|
||
"gno.land/p/demo/avl" | ||
"gno.land/p/demo/boards2/admindao" | ||
) | ||
|
||
var ( | ||
daos avl.Tree // string(name) -> *AdminDAO | ||
boardsNS string | ||
) | ||
|
||
func init() { | ||
boardsNS = path.Dir(std.CurrentRealm().PkgPath()) + "/" | ||
} | ||
|
||
func New(name string, options ...admindao.Option) *admindao.AdminDAO { | ||
assertCallerIsBoardsRealm() | ||
|
||
dao := admindao.New(options...) | ||
daos.Set(name, dao) | ||
return dao | ||
} | ||
|
||
func Get(name string) (_ *admindao.AdminDAO, found bool) { | ||
assertCallerIsBoardsRealm() | ||
|
||
v, found := daos.Get(name) | ||
if !found { | ||
return nil, false | ||
} | ||
return v.(*admindao.AdminDAO), true | ||
} | ||
|
||
func Exists(name string) bool { | ||
return daos.Has(name) | ||
} | ||
|
||
func assertCallerIsBoardsRealm() { | ||
if !strings.HasPrefix(std.PrevRealm().PkgPath(), boardsNS) { | ||
panic("unauthorized") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module gno.land/r/demo/boards2/admindao |
37 changes: 37 additions & 0 deletions
37
examples/gno.land/r/demo/boards2/admindao/z_0_a_filetest.gno
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// PKGPATH: gno.land/r/demo/boards2/test | ||
package test | ||
|
||
import ( | ||
"std" | ||
|
||
"gno.land/r/demo/boards2/admindao" | ||
) | ||
|
||
const ( | ||
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 | ||
name = "test1" | ||
) | ||
|
||
func init() { | ||
std.TestSetOrigCaller(owner) | ||
} | ||
|
||
func main() { | ||
dao := admindao.New(name) | ||
println("ok") | ||
|
||
if admindao.Exists(name) { | ||
println("exists") | ||
} | ||
|
||
if got, found := admindao.Get(name); found { | ||
if got == dao { | ||
print("found") | ||
} | ||
} | ||
} | ||
|
||
// Output: | ||
// ok | ||
// exists | ||
// found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
package main | ||
// PKGPATH: gno.land/r/demo/boards2/test | ||
package test | ||
|
||
import ( | ||
"std" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
// PKGPATH: gno.land/r/demo/boards2/v1_test | ||
package v1_test | ||
package main | ||
|
||
import ( | ||
"std" | ||
|
||
boards2 "gno.land/r/demo/boards2/v1" | ||
) | ||
|
||
const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 | ||
|
||
func init() { | ||
std.TestSetOrigCaller(owner) | ||
} | ||
|
||
func main() { | ||
boards2.CreateBoard("foo") | ||
boards2.CreateBoard("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") | ||
} | ||
|
||
// Error: | ||
// invalid non-user call | ||
// addresses are not allowed as board name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters