Smart Contract

FindRulesCache

A.097bafa4e0b48eef.FindRulesCache

Deployed

2d ago
Feb 26, 2026, 03:12:51 AM UTC

Dependents

0 imports
1import MetadataViews from 0x1d7e57aa55817448
2
3access(all) contract FindRulesCache {
4
5    access(contract) let tenantFindRules : {String : {String : ActionResult}}
6    access(contract) let tenantTenantRules : {String : {String : ActionResult}}
7    access(contract) let tenantCuts : {String : {String : TenantCuts}}
8
9    access(all) struct ActionResult {
10        access(all) let allowed:Bool
11        access(all) let message:String
12        access(all) let name:String
13
14        init(allowed:Bool, message:String, name:String) {
15            self.allowed=allowed
16            self.message=message
17            self.name =name
18        }
19    }
20
21    access(all) struct TenantCuts {
22        access(all) let findCut:MetadataViews.Royalty?
23        access(all) let tenantCut:MetadataViews.Royalty?
24
25        init(findCut:MetadataViews.Royalty?, tenantCut:MetadataViews.Royalty?) {
26            self.findCut=findCut
27            self.tenantCut=tenantCut
28        }
29    }
30
31    // Tenant Find Rules
32    access(account) fun setTenantFindRulesCache(tenant: String, ruleId: String, result: ActionResult) {
33        if self.tenantFindRules[tenant] == nil {
34            self.tenantFindRules[tenant] = {}
35            self.tenantFindRules[tenant]!.insert(key: ruleId, result)
36            return
37        }
38
39        if self.tenantFindRules[tenant]![ruleId] == nil {
40            self.tenantFindRules[tenant]!.insert(key: ruleId, result)
41            return
42        }
43
44        panic("There is already a cache for this find rule. RuleId : ".concat(ruleId))
45    }
46
47    access(all) fun getTenantFindRules(tenant: String, ruleId: String) : ActionResult? {
48        if self.tenantFindRules[tenant] == nil {
49            return nil
50        }
51        return self.tenantFindRules[tenant]![ruleId]
52    }
53
54    access(account) fun resetTenantFindRulesCache(_ tenant: String) {
55        self.tenantFindRules.remove(key: tenant)
56    }
57
58    // Tenant Tenant Rules
59    access(account) fun setTenantTenantRulesCache(tenant: String, ruleId: String, result: ActionResult) {
60        if self.tenantTenantRules[tenant] == nil {
61            self.tenantTenantRules[tenant] = {}
62            self.tenantTenantRules[tenant]!.insert(key: ruleId, result)
63            return
64        }
65
66        if self.tenantTenantRules[tenant]![ruleId] == nil {
67            self.tenantTenantRules[tenant]!.insert(key: ruleId, result)
68            return
69        }
70
71        panic("There is already a cache for this tenant rule. RuleId : ".concat(ruleId))
72    }
73
74    access(all) fun getTenantTenantRules(tenant: String, ruleId: String) : ActionResult? {
75        if self.tenantTenantRules[tenant] == nil {
76            return nil
77        }
78        return self.tenantTenantRules[tenant]![ruleId]
79    }
80
81    access(account) fun resetTenantTenantRulesCache(_ tenant: String) {
82        self.tenantTenantRules.remove(key: tenant)
83    }
84
85    access(account) fun setTenantCutCache(tenant: String, ruleId: String, cut: TenantCuts) {
86        if self.tenantCuts[tenant] == nil {
87            self.tenantCuts[tenant] = {}
88            self.tenantCuts[tenant]!.insert(key: ruleId, cut)
89            return
90        }
91
92        if self.tenantCuts[tenant]![ruleId] == nil {
93            self.tenantCuts[tenant]!.insert(key: ruleId, cut)
94            return
95        }
96
97        panic("There is already a cache for this tenant cut information. RuleId : ".concat(ruleId))
98    }
99
100    access(all) fun getTenantCut(tenant: String, ruleId: String) : TenantCuts? {
101        if self.tenantCuts[tenant] == nil {
102            return nil
103        }
104        return self.tenantCuts[tenant]![ruleId]
105    }
106
107    access(account) fun resetTenantCutCache(_ tenant: String) {
108        self.tenantCuts.remove(key: tenant)
109    }
110
111    init() {
112        self.tenantFindRules = {}
113        self.tenantTenantRules = {}
114        self.tenantCuts = {}
115    }
116}
117