Smart Contract
FindVerifier
A.097bafa4e0b48eef.FindVerifier
1import FLOAT from 0x2d4c3caffbeab845
2import FIND from 0x097bafa4e0b48eef
3import NonFungibleToken from 0x1d7e57aa55817448
4import MetadataViews from 0x1d7e57aa55817448
5import ViewResolver from 0x1d7e57aa55817448
6
7access(all) contract FindVerifier {
8
9 access(all) struct interface Verifier {
10 access(all) let description : String
11 access(all) fun verify(_ param: {String : AnyStruct}) : Bool
12 }
13
14 access(all) struct HasOneFLOAT : Verifier {
15 access(all) let floatEventIds : [UInt64]
16 access(all) let description: String
17
18 init(_ floatEventIds: [UInt64]) {
19 pre{
20 floatEventIds.length > 0 : "list cannot be empty"
21 }
22 self.floatEventIds = floatEventIds
23 var desc = "User with one of these FLOATs are verified : "
24 for floatEventId in floatEventIds {
25 desc = desc.concat(floatEventId.toString()).concat(", ")
26 }
27 desc = desc.slice(from:0 ,upTo:desc.length-2)
28 self.description = desc
29 }
30
31 access(all) fun verify(_ param: {String : AnyStruct}) : Bool {
32
33 if self.floatEventIds.length == 0 {
34 return true
35 }
36
37 let user : Address = param["address"]! as! Address
38 let float = getAccount(user).capabilities.borrow<&FLOAT.Collection>(FLOAT.FLOATCollectionPublicPath)
39
40 if float == nil {
41 return false
42 }
43
44 let floatsCollection=float!
45
46 for eventId in self.floatEventIds {
47 let ids = floatsCollection.ownedIdsFromEvent(eventId: eventId)
48 if ids.length > 0 {
49 return true
50 }
51 }
52 return false
53 }
54
55 }
56
57 access(all) struct HasAllFLOAT : Verifier {
58 access(all) let floatEventIds : [UInt64]
59 access(all) let description: String
60
61 init(_ floatEventIds : [UInt64]) {
62 pre{
63 floatEventIds.length > 0 : "list cannot be empty"
64 }
65 self.floatEventIds = floatEventIds
66 var desc = "User with all of these FLOATs are verified : "
67 for floatEventId in floatEventIds {
68 desc = desc.concat(floatEventId.toString()).concat(", ")
69 }
70 desc = desc.slice(from:0 ,upTo:desc.length-2)
71 self.description = desc
72 }
73
74 access(all) fun verify(_ param: {String : AnyStruct}) : Bool {
75
76 if self.floatEventIds.length == 0 {
77 return true
78 }
79
80 let user : Address = param["address"]! as! Address
81 let float = getAccount(user).capabilities.borrow<&FLOAT.Collection>(FLOAT.FLOATCollectionPublicPath)
82
83 if float == nil {
84 return false
85 }
86
87 let floatsCollection=float!
88
89 let checked : [UInt64] = []
90 for eventId in self.floatEventIds {
91 let ids = floatsCollection.ownedIdsFromEvent(eventId: eventId)
92 if ids.length > 0 {
93 checked.append(ids[0])
94 }
95 }
96
97 if checked.length == self.floatEventIds.length {
98 return true
99 }
100 return false
101 }
102 }
103
104 access(all) struct IsInWhiteList : Verifier {
105 access(all) let addressList : [Address]
106 access(all) let description: String
107
108 init(_ addressList: [Address]) {
109 pre{
110 addressList.length > 0 : "list cannot be empty"
111 }
112 self.addressList = addressList
113 var desc = "Only these wallet addresses are verified : "
114 for addr in addressList {
115 desc = desc.concat(addr.toString()).concat(", ")
116 }
117 desc = desc.slice(from:0 ,upTo:desc.length-2)
118 self.description = desc
119 }
120
121 access(all) fun verify(_ param: {String : AnyStruct}) : Bool {
122 let user : Address = param["address"]! as! Address
123 return self.addressList.contains(user)
124 }
125 }
126
127 // Has Find Name
128 access(all) struct HasFINDName : Verifier {
129 access(all) let findNames: [String]
130 access(all) let description: String
131
132 init(_ findNames: [String]) {
133 pre{
134 findNames.length > 0 : "list cannot be empty"
135 }
136 self.findNames = findNames
137 var desc = "Users with one of these find names are verified : "
138 for name in findNames {
139 desc = desc.concat(name.concat(", "))
140 }
141 desc = desc.slice(from:0 ,upTo:desc.length-2)
142 self.description = desc
143 }
144
145 access(all) fun verify(_ param: {String : AnyStruct}) : Bool {
146
147 if self.findNames.length == 0 {
148 return true
149 }
150
151 let user : Address = param["address"]! as! Address
152
153 let cap = getAccount(user).capabilities.get<&{FIND.LeaseCollectionPublic}>(FIND.LeasePublicPath)
154 if !cap.check() {
155 return false
156 }
157 let ref = cap.borrow()!
158 let names = ref.getLeases()
159
160 var longerArray = self.findNames
161 var shorterArray = names
162
163 if shorterArray.length > longerArray.length {
164 longerArray = names
165 shorterArray = self.findNames
166 }
167
168 for name in shorterArray {
169 if longerArray.contains(name) {
170 return true
171 }
172 }
173
174 return false
175 }
176 }
177
178 // Has a no. of NFTs in given path
179 access(all) struct HasNFTsInPath : Verifier {
180 access(all) let path: PublicPath
181 access(all) let threshold: Int
182 access(all) let description: String
183
184 init(path: PublicPath , threshold: Int ) {
185 pre {
186 threshold > 0 : "threshold should be greater than zero"
187 }
188 self.path = path
189 self.threshold = threshold
190 var desc = "Users with at least ".concat(threshold.toString()).concat(" nos. of NFT in path ".concat(path.toString()).concat(" are verified"))
191 self.description = desc
192 }
193
194 access(all) fun verify(_ param: {String : AnyStruct}) : Bool {
195 if self.threshold == 0 {
196 return true
197 }
198
199 let user : Address = param["address"]! as! Address
200
201 let ref = getAccount(user).capabilities.borrow<&{NonFungibleToken.Collection}>(self.path)
202
203 if ref == nil{
204 return false
205 }
206 return ref!.getIDs().length >= self.threshold
207 }
208 }
209
210 // Has given NFTs in given path with rarity (can cache this with uuid)
211 access(all) struct HasNFTWithRarities : Verifier {
212 access(all) let path: PublicPath
213 access(all) let rarities: [MetadataViews.Rarity]
214 access(self) let rarityIdentifiers: [String]
215 access(all) let description: String
216
217 // leave this here for caching in case useful, but people might be able to change rarity
218 access(self) let cache : {UInt64 : Bool}
219
220 init(path: PublicPath , rarities: [MetadataViews.Rarity]) {
221 pre{
222 rarities.length > 0 : "list cannot be empty"
223 }
224 self.path = path
225 self.rarities = rarities
226 let rarityIdentifiers : [String] = []
227 var rarityDesc = ""
228 for r in rarities {
229 var rI = r.description ?? ""
230 if r.description != nil {
231 rarityDesc = rarityDesc.concat("description : ".concat(r.description!).concat(", "))
232 }
233
234 if r.score != nil {
235 rI = rI.concat(r.score!.toString())
236 rarityDesc = rarityDesc.concat("score : ".concat(r.score!.toString()).concat(", "))
237 } else {
238 rI = rI.concat(" ")
239 }
240
241 if r.max != nil {
242 rI = rI.concat(r.max!.toString())
243 rarityDesc = rarityDesc.concat("max score : ".concat(r.max!.toString()).concat(", "))
244 } else {
245 rI = rI.concat(" ")
246 }
247
248 if rI == " " {
249 panic("Rarity cannot be all nil")
250 }
251
252 rarityDesc = rarityDesc.slice(from:0 ,upTo:rarityDesc.length-2).concat("; ")
253 rarityIdentifiers.append(rI)
254 }
255 self.rarityIdentifiers = rarityIdentifiers
256 self.cache = {}
257 var desc = "Users with at least 1 NFT in path ".concat(path.toString()).concat(" with one of these rarities are verified : ").concat(rarityDesc)
258 self.description = desc
259 }
260
261 access(self) fun rarityToIdentifier(_ r: MetadataViews.Rarity) : String {
262 var rI = r.description ?? ""
263 if r.score != nil {
264 rI = rI.concat(r.score!.toString())
265 }
266 if r.max != nil {
267 rI = rI.concat(r.max!.toString())
268 }
269 return rI
270 }
271
272 access(all) fun verify(_ param: {String : AnyStruct}) : Bool {
273 if self.rarities.length == 0 {
274 return true
275 }
276
277 let user : Address = param["address"]! as! Address
278
279 let mvCap = getAccount(user).capabilities.borrow<&{ViewResolver.ResolverCollection}>(self.path)
280 if mvCap ==nil{
281 return false
282 }
283 let ref = mvCap!
284
285 for id in ref.getIDs() {
286 let resolver = ref.borrowViewResolver(id: id)!
287 if let r = MetadataViews.getRarity(resolver) {
288 if self.rarityIdentifiers.contains(self.rarityToIdentifier(r)) {
289 return true
290 }
291 }
292 }
293 return false
294 }
295 }
296}
297