resources.gno
0.93 Kb · 42 lines
1package daokit
2
3// Maps action types to their handlers and conditions.
4//
5// Example: "transfer" action requires 3 member votes for execution.
6
7import (
8 "gno.land/p/nt/avl/v0"
9 "gno.land/p/samcrew/daocond"
10)
11
12type ResourcesStore struct {
13 Tree *avl.Tree // string -> daocond.Condition
14}
15
16type Resource struct {
17 Handler ActionHandler // Executes the action when proposal passes
18 Condition daocond.Condition // Voting rules required for approval
19 DisplayName string
20 Description string
21}
22
23func NewResourcesStore() *ResourcesStore {
24 return &ResourcesStore{
25 Tree: avl.NewTree(),
26 }
27}
28
29// Retrieves a resource by its handler type name.
30func (r *ResourcesStore) Get(name string) *Resource {
31 value, ok := r.Tree.Get(name)
32 if !ok {
33 return nil
34 }
35 res := value.(*Resource)
36 return res
37}
38
39// Registers a new resource with its handler type as key.
40func (r *ResourcesStore) Set(resource *Resource) {
41 r.Tree.Set(resource.Handler.Type(), resource)
42}