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 permissions & voting power per roles per features #1443

Merged
merged 142 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 111 commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
e56ac5b
test: e2e test to create dao creation flow
MikaelVallenet Oct 10, 2024
6860ec0
wip: e2e test to create dao creation flow
MikaelVallenet Oct 10, 2024
c04bea2
wip: e2e test handle filling all steps in dao creation form
MikaelVallenet Oct 10, 2024
59680d9
wip: e2e test handle filling all steps in dao creation form
MikaelVallenet Oct 11, 2024
d3f01e3
Merge branch 'main' into e2e-test-dao-creation-gno
MikaelVallenet Oct 11, 2024
83d31c8
wip: e2e test handle filling all steps in dao creation form
MikaelVallenet Oct 14, 2024
f5a55e2
wip: e2e test handle filling all steps in dao creation form
MikaelVallenet Oct 14, 2024
a020752
fix: remove unused std from gno dao realm generation
MikaelVallenet Oct 15, 2024
7c60018
feat: add adena mock deploy pkg function
MikaelVallenet Oct 15, 2024
e4f4b20
fix: finish e2e test organization creation flow on gno
MikaelVallenet Oct 15, 2024
21567e5
chore: refactor project structure by moving all e2e test files into g…
MikaelVallenet Oct 15, 2024
9b8a071
style: run eslint
MikaelVallenet Oct 15, 2024
03f1e7c
revert: useless modification on e2e test
MikaelVallenet Oct 15, 2024
cdc95c3
fix: delete useless pkg comment
MikaelVallenet Oct 15, 2024
c0eb78c
fix: run lint on networks files
MikaelVallenet Oct 15, 2024
2ec5b9e
Merge branch 'main' into e2e-test-dao-creation-gno
MikaelVallenet Oct 15, 2024
c3516ce
fix: delete useless console.log
MikaelVallenet Oct 16, 2024
dcd664e
feat: use enum to handle adena type message value
MikaelVallenet Oct 16, 2024
55176c8
fix: delete mint & burn tori token for common dao
MikaelVallenet Oct 22, 2024
ca2b6f1
Merge branch 'main' into e2e-test-dao-creation-gno
n0izn0iz Oct 29, 2024
b0cf985
fix(dao): remove modboard related code
MikaelVallenet Oct 31, 2024
5093189
Merge branch 'e2e-test-dao-creation-gno' of github.com:TERITORI/terit…
MikaelVallenet Oct 31, 2024
c3899dd
Merge branch 'main' into e2e-test-dao-creation-gno
MikaelVallenet Oct 31, 2024
ff5bca0
fix(gnovm): remove leftover of tori import
MikaelVallenet Oct 31, 2024
5caf06f
feat: add a call to members JSON
MikaelVallenet Oct 31, 2024
ed52b3f
feat: add a call to members JSON
MikaelVallenet Oct 31, 2024
0fa0a0a
fix: remove tori admin handler
MikaelVallenet Oct 31, 2024
4e08f27
chore: run eslint
MikaelVallenet Oct 31, 2024
fce1b40
fix: add a TODO to fix later the groupId
MikaelVallenet Oct 31, 2024
ca673e0
fix: remove groupId
MikaelVallenet Oct 31, 2024
8be6a98
fix: keep only e2e related code
MikaelVallenet Nov 1, 2024
010420e
fix: keep only e2e related code
MikaelVallenet Nov 1, 2024
d9cd564
Merge branch 'main' into e2e-test-dao-creation-gno
MikaelVallenet Nov 1, 2024
c6801b3
fix(gno-daos): create proposal for post with DAO
MikaelVallenet Nov 4, 2024
3d27a0c
feat(dao): fix org on gno to post on social feed
MikaelVallenet Nov 5, 2024
49bce88
feat(dao): fix org on gno to post on social feed
MikaelVallenet Nov 5, 2024
e15b6b6
feat(dao): fix not enough funds by using user wallet instead of contr…
MikaelVallenet Nov 5, 2024
2885aa9
misc(dao): remove console log statements
MikaelVallenet Nov 5, 2024
ce5aac9
fix(dao): vote value
MikaelVallenet Nov 5, 2024
7f0de1c
chore: lint
MikaelVallenet Nov 5, 2024
4954bb8
chore: gno lint
MikaelVallenet Nov 5, 2024
95633d4
chore: gno lint
MikaelVallenet Nov 5, 2024
7eedca8
chore: gno lint
MikaelVallenet Nov 5, 2024
9b2d5ba
fix: replace function by usage of lodash lib
MikaelVallenet Nov 5, 2024
03d2edb
fix: check dao have enough money
MikaelVallenet Nov 6, 2024
ec11c14
fix: look for balance of DAO not of user
MikaelVallenet Nov 6, 2024
2088df2
fix: remove double wait on tx causing infinite waiting time
MikaelVallenet Nov 7, 2024
53793c3
fix: parse user & network
MikaelVallenet Nov 7, 2024
117295a
fix: simplify ternary operation
MikaelVallenet Nov 7, 2024
e6547dd
Merge branch 'main' into dev/mikaelvallenet/fix/organization-posting-…
MikaelVallenet Nov 7, 2024
fec6e90
Merge branch 'main' into dev/mikaelvallenet/feat/register-dao-to-prof…
MikaelVallenet Nov 7, 2024
d368965
feat(gno/dao): regiser dao conf to profile realm
MikaelVallenet Nov 7, 2024
30f69f6
chore: rename poster to author
MikaelVallenet Nov 8, 2024
3dee11a
Merge branch 'main' into dev/mikaelvallenet/fix/organization-posting-…
MikaelVallenet Nov 8, 2024
656b087
Merge branch 'dev/mikaelvallenet/fix/organization-posting-post' into …
MikaelVallenet Nov 8, 2024
cb0c544
fix(gno/dao): display dao members
MikaelVallenet Nov 11, 2024
513d6c3
fix(gno/dao): merge main
MikaelVallenet Nov 11, 2024
ee26a23
Merge branch 'dev/mikaelvallenet/feat/register-dao-to-profile-realm' …
MikaelVallenet Nov 11, 2024
2efbcf5
fix(gno/dao): delete fakeRoles
MikaelVallenet Nov 11, 2024
52e1f49
fix(gno/dao): run linter
MikaelVallenet Nov 11, 2024
ad36970
feat(gno/dao): add dao_roles_group
MikaelVallenet Nov 11, 2024
0055bda
feat(gno/dao): add dao_roles_group
MikaelVallenet Nov 11, 2024
6a15018
feat(gno/dao): implement role manager into daos realms
MikaelVallenet Nov 12, 2024
9852985
tests(gno/dao): add roles module in test dao core
MikaelVallenet Nov 12, 2024
7686f09
tests(gno/dao): add roles modules info
MikaelVallenet Nov 12, 2024
9cc37d6
feat(gno/dao): add dao_roles_group into network objects
MikaelVallenet Nov 12, 2024
e92bc8f
chore(gno/dao): generate networks.json
MikaelVallenet Nov 12, 2024
629a6d1
feat(gno/dao): add dao roles group into generated dao code
MikaelVallenet Nov 12, 2024
ec2e57f
feat(gno/dao): add dao_roles_group into network objects
MikaelVallenet Nov 12, 2024
3efeae5
feat(gno/dao): add example of role creation & assignment in dao_core
MikaelVallenet Nov 12, 2024
901146d
feat(gno/dao): add form section to add new role into dao
MikaelVallenet Nov 12, 2024
8d21e7d
feat(gno/dao): add review collapsable row for roles settings definition
MikaelVallenet Nov 13, 2024
3904387
fix(gno/dao): handle unregister field value when delete role or member
MikaelVallenet Nov 13, 2024
ccbf26c
fix(gno/dao): add field to assign roles to users
MikaelVallenet Nov 14, 2024
e928bbb
fix(gno/dao): add role & assignment to deployment contract
MikaelVallenet Nov 14, 2024
d8c1b8c
feat(gno/dao): retrive roles from members of the DAO
MikaelVallenet Nov 15, 2024
206021a
feat(gno/dao): display roles of DAO members
MikaelVallenet Nov 15, 2024
d957c11
chore: merge w/ main
MikaelVallenet Nov 29, 2024
4131ab2
fix: e2e test
MikaelVallenet Nov 29, 2024
b755fef
feat: merge main
MikaelVallenet Dec 2, 2024
438d0fb
tests: fix gno dao tests
MikaelVallenet Dec 2, 2024
4c81982
chore: run linter on e2e tests
MikaelVallenet Dec 2, 2024
841ef7e
feat: refactor organizations and slit each flow
MikaelVallenet Dec 3, 2024
c5317f1
Update packages/screens/Organizations/components/CreateDAOSection.tsx
MikaelVallenet Dec 3, 2024
a77163b
fix: add flex property create dao animation
MikaelVallenet Dec 3, 2024
5fddbc0
Merge branch 'dev/mikaelvallenet/feat/push-role-manager-into-dao' of …
MikaelVallenet Dec 3, 2024
ca3b5c1
fix: refactor gno e2e tests
MikaelVallenet Dec 3, 2024
607cebe
fix: remove roles e2e test since it's not production ready
MikaelVallenet Dec 3, 2024
b549bbc
chore: run lint
MikaelVallenet Dec 3, 2024
0ccbc60
fix: reset unlocked steps on structure change
MikaelVallenet Dec 3, 2024
c0e7c6a
test: fix e2e tests
MikaelVallenet Dec 3, 2024
4284bef
test: fix e2e tests
MikaelVallenet Dec 3, 2024
ce2571f
chore: regenerate networks.json
MikaelVallenet Dec 3, 2024
21012de
fix(org): remove unused ReviewInformationSection component
MikaelVallenet Dec 3, 2024
7695414
fix(org): remove duplicate register to realm profile
MikaelVallenet Dec 3, 2024
637d03a
style: remove stylesheet.create from evertwhere in the orgs screens &…
MikaelVallenet Dec 3, 2024
7eeb6ba
fix(org): fix split bug & add split member in two kind for roles & me…
MikaelVallenet Dec 3, 2024
4acc804
fix(org): fix deploy roles based dao without any roles
MikaelVallenet Dec 3, 2024
3d5061b
fix(org/upp): remove roles text if user card does not have any roles
MikaelVallenet Dec 3, 2024
b3de18d
Merge branch 'main' into dev/mikaelvallenet/feat/push-role-manager-in…
n0izn0iz Dec 3, 2024
5480428
feat: add token based dao
MikaelVallenet Dec 4, 2024
0add3e8
fix: import
MikaelVallenet Dec 4, 2024
9ea0010
chore: lint
MikaelVallenet Dec 4, 2024
928814e
chore: lint
MikaelVallenet Dec 4, 2024
1f77d9a
Merge branch 'main' into dev/mikaelvallenet/feat/push-role-manager-in…
MikaelVallenet Dec 4, 2024
9f9df32
fix: e2e test
MikaelVallenet Dec 4, 2024
4c659fc
feat: add new p roles based voting module that implement voting modul…
MikaelVallenet Dec 4, 2024
15f7b06
feat: create new roles dao based realm that use the new roles voting …
MikaelVallenet Dec 5, 2024
d8ae713
chore: rename role method
MikaelVallenet Dec 5, 2024
bda1fbe
feat: merge main
MikaelVallenet Dec 5, 2024
553a5f3
feat: wip
MikaelVallenet Dec 7, 2024
fa9b4df
feat: handle features selections
MikaelVallenet Dec 7, 2024
bb49a9e
feat: rename features to resources & reset checkbox on each opening o…
MikaelVallenet Dec 9, 2024
b4227b4
feat: add generation of dao for roles based org
MikaelVallenet Dec 10, 2024
f54ec40
Merge branch 'main' into dev/mikaelvallenet/feat/add-permission-in-ro…
MikaelVallenet Dec 10, 2024
33f75ac
feat: add parsing json permissions & resources
MikaelVallenet Dec 10, 2024
f81dbee
feat: adapt gno contracts to handle power per resources
MikaelVallenet Dec 10, 2024
71ae5d2
fix: adapt function call to retrieve member dao power
MikaelVallenet Dec 12, 2024
d1d6bac
fix: dao include members without roles
MikaelVallenet Dec 12, 2024
1736092
feat: adapt voting behavior
MikaelVallenet Dec 16, 2024
1ea963d
feat: change resources to display a feature name but linked it to mes…
MikaelVallenet Dec 16, 2024
4b9ffb5
feat: update contract to use term resource instead of permission
MikaelVallenet Dec 16, 2024
33f205a
test(gno/orgs): fix new gno tests
MikaelVallenet Dec 16, 2024
0002c3f
tests: add test in voting_role_dao_group
MikaelVallenet Dec 17, 2024
ff64ce5
tests: add two examples of dao_realm
MikaelVallenet Dec 17, 2024
1aaec57
chore: lint & gnomod tidy
MikaelVallenet Dec 17, 2024
1c070da
feat: add fake resources in dao_roles_realm example
MikaelVallenet Dec 17, 2024
d4c8d9e
chore: remove console.log
MikaelVallenet Dec 17, 2024
7bd29bd
Merge branch 'main' into dev/mikaelvallenet/feat/add-permission-in-ro…
MikaelVallenet Dec 18, 2024
0fb1c57
chore: refactor create role modal
MikaelVallenet Dec 18, 2024
10d39a7
feat: add roles tables
MikaelVallenet Dec 18, 2024
c99266d
fix: change features by resources
MikaelVallenet Dec 18, 2024
91b110f
fix: add spacing
MikaelVallenet Dec 18, 2024
e254883
chore: refactor checkbox
MikaelVallenet Dec 18, 2024
a56c5dd
Merge branch 'main' into dev/mikaelvallenet/feat/add-permission-in-ro…
MikaelVallenet Dec 18, 2024
07da799
chore: run lint & fix tsc
MikaelVallenet Dec 19, 2024
b84bab3
chore: generate networks.json
MikaelVallenet Dec 19, 2024
54f8050
chore: merge main
MikaelVallenet Dec 20, 2024
254e77b
fix: remove require in gno.mod
MikaelVallenet Dec 20, 2024
7fc6145
fix: remove require in gno.mod
MikaelVallenet Dec 20, 2024
d8a8542
fix: remove require in gno.mod
MikaelVallenet Dec 20, 2024
5d04978
chore: gno mod tidy
n0izn0iz Dec 20, 2024
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
2 changes: 1 addition & 1 deletion gno/p/dao_core/dao_core.gno
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (d *daoCore) GetMembersJSON(start, end string, limit uint64, height int64)
}

func (d *daoCore) VotingPowerAtHeight(address std.Address, height int64) uint64 {
return d.VotingModule().VotingPowerAtHeight(address, height)
return d.VotingModule().VotingPowerAtHeight(address, height, "")
}

func (d *daoCore) ActiveProposalModuleCount() int {
Expand Down
4 changes: 2 additions & 2 deletions gno/p/dao_interfaces/modules.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type IVotingModule interface {
ConfigJSON() string
GetMembersJSON(start, end string, limit uint64, height int64) string
Render(path string) string
VotingPowerAtHeight(address std.Address, height int64) (power uint64)
VotingPowerAtHeight(address std.Address, height int64, feature string) (power uint64)
TotalPowerAtHeight(height int64) uint64
}

Expand All @@ -44,7 +44,7 @@ type IRolesModule interface {
Render(path string) string
GetMemberRoles(address std.Address) []string
HasRole(address std.Address, role string) bool
NewRole(roleName string)
NewRole(roleName string, permissionsJSON string)
Copy link
Collaborator

@n0izn0iz n0izn0iz Dec 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't take json in this func, if we need to pass json through the interface, create a NewRoleJSON func instead

json un/marshaling should be only at the edge in most cases

DeleteRole(roleName string)
GrantRole(address std.Address, role string)
RevokeRole(address std.Address, role string)
Expand Down
2 changes: 1 addition & 1 deletion gno/p/dao_proposal_single/dao_proposal_single.gno
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (d *DAOProposalSingle) VoteJSON(proposalID int, voteJSON string) {
panic("proposal is expired")
}

votePower := d.core.VotingModule().VotingPowerAtHeight(voter, proposal.StartHeight)
votePower := d.core.VotingModule().VotingPowerAtHeight(voter, proposal.StartHeight, "")
if votePower == 0 {
panic("not registered")
}
Expand Down
1 change: 1 addition & 0 deletions gno/p/dao_roles_group/gno.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ require (
gno.land/p/teritori/dao_interfaces v0.0.0-latest
gno.land/p/teritori/jsonutil v0.0.0-latest
gno.land/p/teritori/role_manager v0.0.0-latest
gno.land/p/demo/avl v0.0.0-latest
)
20 changes: 18 additions & 2 deletions gno/p/dao_roles_group/roles_group.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dao_roles_group
import (
"std"

"gno.land/p/demo/avl"
"gno.land/p/demo/json"
dao_interfaces "gno.land/p/teritori/dao_interfaces"
"gno.land/p/teritori/jsonutil"
Expand All @@ -12,7 +13,13 @@ import (
type RolesGroup struct {
dao_interfaces.IRolesModule

rm *role_manager.RoleManager
rm *role_manager.RoleManager
permissionsPower *avl.Tree // roles -> PermissionPower
}

type PermissionPower struct {
Permission string
Power uint64
}

func NewRolesGroup() *RolesGroup {
Expand Down Expand Up @@ -42,7 +49,12 @@ func (r *RolesGroup) HasRole(address std.Address, role string) bool {
return r.rm.HasRole(address, role)
}

func (r *RolesGroup) NewRole(roleName string) {
func (r *RolesGroup) NewRole(roleName string, permissionsJSON string) {
// TODO:
// 1. Parse permissionsJSON
// 2. Create a new role with the parsed permissions
// 3. Create a new array of PermissionPower and store it in r.permissionsPower
_ = permissionsJSON
r.rm.CreateNewRole(roleName, []string{})
}

Expand All @@ -61,3 +73,7 @@ func (r *RolesGroup) RevokeRole(address std.Address, role string) {
func (r *RolesGroup) GetMemberRoles(address std.Address) []string {
return r.rm.GetUserRoles(address)
}

// TODO:
// 1. Add GetUserPower(address std.Address, permission string) uint64
// 2. Add SetRolePower(role string, permission string, power uint64)
8 changes: 8 additions & 0 deletions gno/p/dao_roles_voting_group/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module gno.land/p/teritori/dao_roles_voting_group

require (
gno.land/p/demo/json v0.0.0-latest
gno.land/p/teritori/dao_interfaces v0.0.0-latest
gno.land/p/teritori/havl v0.0.0-latest
gno.land/p/teritori/jsonutil v0.0.0-latest
)
62 changes: 62 additions & 0 deletions gno/p/dao_roles_voting_group/messages.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package dao_roles_voting_group

import (
"gno.land/p/demo/json"
"gno.land/p/teritori/dao_interfaces"
)

const updateMembersType = "gno.land/p/teritori/dao_voting_group.UpdateMembers"

type UpdateMembersExecutableMessage []Member

var _ dao_interfaces.ExecutableMessage = (*UpdateMembersExecutableMessage)(nil)

func (m *UpdateMembersExecutableMessage) FromJSON(ast *json.Node) {
changes := ast.MustArray()
*m = make([]Member, len(changes))
for i, change := range changes {
(*m)[i].FromJSON(change)
}
}

func (m *UpdateMembersExecutableMessage) ToJSON() *json.Node {
changes := make([]*json.Node, len(*m))
for i, change := range *m {
changes[i] = change.ToJSON()
}

return json.ArrayNode("", changes)
}

func (m *UpdateMembersExecutableMessage) String() string {
return m.ToJSON().String()
}

func (m *UpdateMembersExecutableMessage) Type() string {
return updateMembersType
}

type updateMembersHandler struct {
vg *RolesVotingGroup
}

var _ dao_interfaces.MessageHandler = (*updateMembersHandler)(nil)

func (h *updateMembersHandler) Type() string {
return updateMembersType
}

func (h *updateMembersHandler) Execute(msg dao_interfaces.ExecutableMessage) {
m, ok := msg.(*UpdateMembersExecutableMessage)
if !ok {
panic("unexpected message type")
}

for _, change := range *m {
h.vg.SetMemberPower(change.Address, change.Power)
}
}

func (h *updateMembersHandler) Instantiate() dao_interfaces.ExecutableMessage {
return &UpdateMembersExecutableMessage{}
}
186 changes: 186 additions & 0 deletions gno/p/dao_roles_voting_group/roles_voting_group.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
package dao_roles_voting_group

import (
"std"
"strconv"
"strings"

"gno.land/p/demo/json"
dao_interfaces "gno.land/p/teritori/dao_interfaces"
"gno.land/p/teritori/havl"
"gno.land/p/teritori/jsonutil"
)

type Member struct {
Address std.Address
Power uint64
}

func (m Member) ToJSON() *json.Node {
return json.ObjectNode("", map[string]*json.Node{
"address": jsonutil.AddressNode(m.Address),
"power": jsonutil.Uint64Node(m.Power),
})
}

func (m *Member) FromJSON(ast *json.Node) {
obj := ast.MustObject()
m.Address = jsonutil.MustAddress(obj["address"])
m.Power = jsonutil.MustUint64(obj["power"])
}

type RolesVotingGroup struct {
dao_interfaces.IVotingModule

powerByAddr *havl.Tree // std.Address -> uint64
totalPower *havl.Tree // "" -> uint64
memberCount *havl.Tree // "" -> uint32
}

func NewRolesVotingGroup() *RolesVotingGroup {
return &RolesVotingGroup{
powerByAddr: havl.NewTree(),
totalPower: havl.NewTree(),
memberCount: havl.NewTree(),
}
}

func (v *RolesVotingGroup) Info() dao_interfaces.ModuleInfo {
return dao_interfaces.ModuleInfo{
Kind: "gno.land/p/teritori/dao_voting_group",
Version: "0.1.0",
}
}

func (v *RolesVotingGroup) ConfigJSON() string {
return json.ObjectNode("", map[string]*json.Node{
"totalPower": jsonutil.Uint64Node(v.TotalPowerAtHeight(havl.Latest)),
"members": jsonutil.Uint32Node(v.MemberCount(havl.Latest)),
}).String()
}

func (v *RolesVotingGroup) GetMembersJSON(start, end string, limit uint64, height int64) string {
members := v.GetMembers(start, end, limit, height)
membersJSON := make([]*json.Node, len(members))
for i, m := range members {
membersJSON[i] = m.ToJSON()
}
return json.ArrayNode("", membersJSON).String()
}

func (v *RolesVotingGroup) VotingPowerAtHeight(addr std.Address, height int64, feature string) uint64 {
_ = feature
// TODO:
// 1. Ask dao roles group module to see if the user have a role that give him more power on the feature
// 2. If not, return the power of the user
p, ok := v.powerByAddr.Get(addr.String(), height)
if !ok {
return 0
}

return p.(uint64)
}

func (v *RolesVotingGroup) TotalPowerAtHeight(height int64) uint64 {
p, ok := v.totalPower.Get("", height)
if !ok {
return 0
}

return p.(uint64)
}

func (g *RolesVotingGroup) SetMemberPower(addr std.Address, power uint64) {
if power == 0 {
g.RemoveMember(addr)
return
}

iprevious, ok := g.powerByAddr.Get(addr.String(), havl.Latest)
if !ok {
g.memberCount.Set("", g.MemberCount(havl.Latest)+1)
}

previous := uint64(0)
if ok {
previous = iprevious.(uint64)
}

if power == previous {
return
}

g.powerByAddr.Set(addr.String(), power)

ipreviousTotal, ok := g.totalPower.Get("", havl.Latest)
previousTotal := uint64(0)
if ok {
previousTotal = ipreviousTotal.(uint64)
}

g.totalPower.Set("", (previousTotal+power)-previous)
}

func (g *RolesVotingGroup) RemoveMember(addr std.Address) (uint64, bool) {
p, removed := g.powerByAddr.Remove(addr.String())
if !removed {
return 0, false
}

g.memberCount.Set("", g.MemberCount(havl.Latest)-1)
power := p.(uint64)
g.totalPower.Set("", g.TotalPowerAtHeight(havl.Latest)-power)
return power, true
}

func (g *RolesVotingGroup) UpdateMembersHandler() dao_interfaces.MessageHandler {
return &updateMembersHandler{vg: g}
}

func (g *RolesVotingGroup) MemberCount(height int64) uint32 {
val, ok := g.memberCount.Get("", height)
if !ok {
return 0
}

return val.(uint32)
}

func (g *RolesVotingGroup) GetMembers(start, end string, limit uint64, height int64) []Member {
var members []Member
g.powerByAddr.Iterate(start, end, height, func(k string, v interface{}) bool {
if limit > 0 && uint64(len(members)) >= limit {
return true
}

members = append(members, Member{
Address: std.Address(k),
Power: v.(uint64),
})

return false
})
return members
}

func (v *RolesVotingGroup) Render(path string) string {
sb := strings.Builder{}
sb.WriteString("Member count: ")
sb.WriteString(strconv.FormatUint(uint64(v.MemberCount(havl.Latest)), 10))
sb.WriteString("\n\n")
sb.WriteString("Total power: ")
sb.WriteString(strconv.FormatUint(v.TotalPowerAtHeight(havl.Latest), 10))
sb.WriteString("\n\n")
sb.WriteString("Members:\n")
v.powerByAddr.Iterate("", "", havl.Latest, func(k string, v interface{}) bool {
sb.WriteString("- ")
sb.WriteString(k)
sb.WriteString(": ")
sb.WriteString(strconv.FormatUint(v.(uint64), 10))
sb.WriteRune('\n')
return false
})

sb.WriteRune('\n')
return sb.String()
}
29 changes: 29 additions & 0 deletions gno/p/dao_roles_voting_group/roles_voting_group_test.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package dao_roles_voting_group

import (
"testing"

dao_interfaces "gno.land/p/teritori/dao_interfaces"
)

MikaelVallenet marked this conversation as resolved.
Show resolved Hide resolved
func TestRolesVotingGroup(t *testing.T) {
rv := NewRolesVotingGroup()
var i dao_interfaces.IVotingModule
i = rv

{
got := i.TotalPowerAtHeight(0)
expected := uint64(0)
if got != expected {
t.Fatalf("expected %s, got %s.", expected, got)
}
}

{
conf := rv.ConfigJSON()
expected := `{"totalPower":"0","members":"0"}`
if conf != expected {
t.Fatalf("expected %s, got %s.", expected, conf)
}
}
}
3 changes: 2 additions & 1 deletion gno/p/dao_voting_group/voting_group.gno
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ func (v *VotingGroup) GetMembersJSON(start, end string, limit uint64, height int
return json.ArrayNode("", membersJSON).String()
}

func (v *VotingGroup) VotingPowerAtHeight(addr std.Address, height int64) uint64 {
func (v *VotingGroup) VotingPowerAtHeight(addr std.Address, height int64, feature string) uint64 {
_ = feature
p, ok := v.powerByAddr.Get(addr.String(), height)
if !ok {
return 0
Expand Down
2 changes: 1 addition & 1 deletion gno/p/role_manager/role_manager.gno
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (rm *RoleManager) HasRole(user std.Address, roleName string) bool {
return userRoles.Has(roleName)
}

func (rm *RoleManager) IsRoleExist(roleName string) bool {
func (rm *RoleManager) RoleExists(roleName string) bool {
return rm.roles.Has(roleName)
}

Expand Down
Loading
Loading