Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

storage source pure

Readme View source

CommonDAO Package Storage Extension

Storage package is an extension of gno.land/p/nt/commondao/v0 that provides alternative storage implementations.

Member Storage

This custom implementation of MemberStorage is an implementation with grouping support that automatically adds or removes members from the storage when members are added or removed from any of the member groups.

The implementation provided by the commondao package doesn't automatically add members to the storage when any of the groups change, if need then users have to be added explicitly.

Adding or removing users automatically could be beneficial in some cases where implementation requires iterating all unique users within the storage and within each group, or counting all unique users within them. It also makes it cheaper to iterate because having all users within the same storage doesn't require to iterate each group.

Package also provide a GetMemberGroups() function that takes advantage of this storage which can be used to return the names of the groups that an account is a member of.

Example usage:

 1import (
 2  "gno.land/p/nt/commondao/v0"
 3  "gno.land/p/nt/commondao/v0/exts/storage"
 4)
 5
 6func main() {
 7  // Create a new member storage with grouping
 8  s := storage.NewMemberStorage()
 9  
10  // Create a member group for moderators
11  moderators, err := s.Grouping().Add("moderators")
12  if err != nil {
13    panic(err)
14  }
15
16  // Add members to the moderators group
17  moderators.Members().Add("g1...a")
18  moderators.Members().Add("g1...b")
19
20  // Create a DAO that uses the new member storage
21  dao := commondao.New(commondao.WithMemberStorage(s))
22
23  // Output: 2
24  println(dao.Members().Size())
25}

Functions 2

func GetMemberGroups

1func GetMemberGroups(s commondao.MemberStorage, member address) []string
source

GetMemberGroups returns the groups that a member belongs to. It returns no groups if member storage was not created using this package.

func NewMemberStorage

1func NewMemberStorage() commondao.MemberStorage
source

NewMemberStorage creates a new CommonDAO member storage with grouping support.

This is a custom storage that automatically adds or removes members that are added or removed from any of the member groups. This allows for quick and inexpensive checks for the number of total unique storage users, including users added to groups, and also to iterate all of them without needing to iterate individual groups.

Imports 3

Source Files 4