@flowtyio/flow-contracts 0.1.0-beta.8 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +1 -1
  2. package/contracts/FungibleTokenSwitchboard.cdc +360 -0
  3. package/contracts/MetadataViews.cdc +79 -6
  4. package/contracts/NonFungibleToken.cdc +17 -10
  5. package/contracts/TokenForwarding.cdc +19 -11
  6. package/contracts/capability-cache/CapabilityCache.cdc +97 -0
  7. package/contracts/dapper/TopShot.cdc +323 -259
  8. package/contracts/dapper/TopShotLocking.cdc +41 -15
  9. package/contracts/dapper/offers/DapperOffersV2.cdc +46 -43
  10. package/contracts/dapper/offers/OffersV2.cdc +40 -56
  11. package/contracts/dapper/offers/Resolver.cdc +20 -13
  12. package/contracts/emerald-city/FLOAT.cdc +259 -254
  13. package/contracts/example/ExampleNFT.cdc +2 -2
  14. package/contracts/find/FindViews.cdc +357 -353
  15. package/contracts/flow-utils/ScopedFTProviders.cdc +5 -2
  16. package/contracts/flow-utils/ScopedNFTProviders.cdc +6 -2
  17. package/contracts/flowty-drops/ContractManager.cdc +73 -0
  18. package/contracts/flowty-drops/DropFactory.cdc +75 -0
  19. package/contracts/flowty-drops/DropTypes.cdc +282 -0
  20. package/contracts/flowty-drops/FlowtyActiveCheckers.cdc +113 -0
  21. package/contracts/flowty-drops/FlowtyAddressVerifiers.cdc +64 -0
  22. package/contracts/flowty-drops/FlowtyDrops.cdc +461 -0
  23. package/contracts/flowty-drops/FlowtyPricers.cdc +48 -0
  24. package/contracts/flowty-drops/initializers/ContractBorrower.cdc +14 -0
  25. package/contracts/flowty-drops/initializers/ContractInitializer.cdc +7 -0
  26. package/contracts/flowty-drops/initializers/OpenEditionInitializer.cdc +57 -0
  27. package/contracts/flowty-drops/nft/BaseCollection.cdc +97 -0
  28. package/contracts/flowty-drops/nft/BaseNFT.cdc +107 -0
  29. package/contracts/flowty-drops/nft/ContractFactory.cdc +13 -0
  30. package/contracts/flowty-drops/nft/ContractFactoryTemplate.cdc +48 -0
  31. package/contracts/flowty-drops/nft/NFTMetadata.cdc +140 -0
  32. package/contracts/flowty-drops/nft/OpenEditionNFT.cdc +42 -0
  33. package/contracts/flowty-drops/nft/OpenEditionTemplate.cdc +54 -0
  34. package/contracts/flowty-drops/nft/UniversalCollection.cdc +29 -0
  35. package/contracts/fungible-token-router/FungibleTokenRouter.cdc +103 -0
  36. package/contracts/hybrid-custody/CapabilityDelegator.cdc +28 -26
  37. package/contracts/hybrid-custody/CapabilityFactory.cdc +20 -18
  38. package/contracts/hybrid-custody/CapabilityFilter.cdc +41 -24
  39. package/contracts/hybrid-custody/HybridCustody.cdc +303 -242
  40. package/contracts/hybrid-custody/factories/FTAllFactory.cdc +16 -4
  41. package/contracts/hybrid-custody/factories/FTBalanceFactory.cdc +16 -4
  42. package/contracts/hybrid-custody/factories/FTProviderFactory.cdc +17 -5
  43. package/contracts/hybrid-custody/factories/FTReceiverBalanceFactory.cdc +16 -4
  44. package/contracts/hybrid-custody/factories/FTReceiverFactory.cdc +16 -4
  45. package/contracts/hybrid-custody/factories/FTVaultFactory.cdc +46 -0
  46. package/contracts/hybrid-custody/factories/NFTCollectionFactory.cdc +45 -0
  47. package/contracts/hybrid-custody/factories/NFTCollectionPublicFactory.cdc +16 -4
  48. package/contracts/hybrid-custody/factories/NFTProviderAndCollectionFactory.cdc +22 -0
  49. package/contracts/hybrid-custody/factories/NFTProviderFactory.cdc +16 -4
  50. package/contracts/lost-and-found/LostAndFound.cdc +21 -17
  51. package/flow.json +181 -7
  52. package/package.json +1 -1
  53. package/contracts/hybrid-custody/factories/NFTProviderAndCollectionPublicFactory.cdc +0 -10
@@ -1,67 +1,64 @@
1
1
  import "NonFungibleToken"
2
2
  import "FungibleToken"
3
3
  import "MetadataViews"
4
+ import "ViewResolver"
4
5
 
5
- pub contract FindViews {
6
-
7
- pub struct OnChainFile : MetadataViews.File{
8
- pub let content: String
9
- pub let mediaType: String
10
- pub let protocol: String
11
-
12
- init(content:String, mediaType: String) {
13
- self.content=content
14
- self.protocol="onChain"
15
- self.mediaType=mediaType
16
- }
17
-
18
- pub fun uri(): String {
19
- return "data:".concat(self.mediaType).concat(",").concat(self.content)
20
- }
21
- }
22
-
23
- pub struct SharedMedia : MetadataViews.File {
24
- pub let mediaType: String
25
- pub let pointer: ViewReadPointer
26
- pub let protocol: String
27
-
28
- init(pointer: ViewReadPointer, mediaType: String) {
29
- self.pointer=pointer
30
- self.mediaType=mediaType
31
- self.protocol="shared"
32
-
33
- if pointer.resolveView(Type<OnChainFile>()) == nil {
34
- panic("Cannot create shared media if the pointer does not contain StringMedia")
35
- }
36
- }
37
-
38
- pub fun uri(): String {
39
- let media = self.pointer.resolveView(Type<OnChainFile>())
40
- if media == nil {
41
- return ""
42
- }
43
- return (media as! OnChainFile).uri()
44
- }
45
- }
46
-
47
- pub resource interface VaultViews {
48
- pub var balance: UFix64
49
-
50
- pub fun getViews() : [Type]
51
- pub fun resolveView(_ view: Type): AnyStruct?
6
+ access(all) contract FindViews {
7
+
8
+ access(all) struct OnChainFile : MetadataViews.File{
9
+ access(all) let content: String
10
+ access(all) let mediaType: String
11
+ access(all) let protocol: String
12
+
13
+ init(content:String, mediaType: String) {
14
+ self.content=content
15
+ self.protocol="onChain"
16
+ self.mediaType=mediaType
17
+ }
18
+
19
+ access(all) view fun uri(): String {
20
+ return "data:".concat(self.mediaType).concat(",").concat(self.content)
21
+ }
52
22
  }
53
23
 
54
- pub struct FTVaultData {
55
- pub let tokenAlias: String
56
- pub let storagePath: StoragePath
57
- pub let receiverPath: PublicPath
58
- pub let balancePath: PublicPath
59
- pub let providerPath: PrivatePath
60
- pub let vaultType: Type
61
- pub let receiverType: Type
62
- pub let balanceType: Type
63
- pub let providerType: Type
64
- pub let createEmptyVault: ((): @FungibleToken.Vault)
24
+ access(all) struct SharedMedia : MetadataViews.File {
25
+ access(all) let mediaType: String
26
+ access(all) let pointer: ViewReadPointer
27
+ access(all) let protocol: String
28
+
29
+ init(pointer: ViewReadPointer, mediaType: String) {
30
+ self.pointer=pointer
31
+ self.mediaType=mediaType
32
+ self.protocol="shared"
33
+
34
+ if pointer.resolveView(Type<OnChainFile>()) == nil {
35
+ panic("Cannot create shared media if the pointer does not contain StringMedia")
36
+ }
37
+ }
38
+
39
+ // todo: this is not working so we have a workaround in the contract
40
+ access(all) view fun uri(): String {
41
+ return "data:".concat(self.mediaType).concat(",").concat(self.protocol)
42
+ }
43
+ }
44
+
45
+ access(all) resource interface VaultViews {
46
+ access(all) var balance: UFix64
47
+ access(all) view fun getViews() : [Type]
48
+ access(all) fun resolveView(_ view: Type): AnyStruct?
49
+ }
50
+
51
+ access(all) struct FTVaultData {
52
+ access(all) let tokenAlias: String
53
+ access(all) let storagePath: StoragePath
54
+ access(all) let receiverPath: PublicPath
55
+ access(all) let balancePath: PublicPath
56
+ access(all) let providerPath: PrivatePath
57
+ access(all) let vaultType: Type
58
+ access(all) let receiverType: Type
59
+ access(all) let balanceType: Type
60
+ access(all) let providerType: Type
61
+ access(all) let createEmptyVault: (fun(): @{FungibleToken.Vault})
65
62
 
66
63
  init(
67
64
  tokenAlias: String,
@@ -73,11 +70,11 @@ pub contract FindViews {
73
70
  receiverType: Type,
74
71
  balanceType: Type,
75
72
  providerType: Type,
76
- createEmptyVault: ((): @FungibleToken.Vault)
73
+ createEmptyVault: (fun(): @{FungibleToken.Vault})
77
74
  ) {
78
75
  pre {
79
76
  receiverType.isSubtype(of: Type<&{FungibleToken.Receiver}>()): "Receiver type must include FungibleToken.Receiver interfaces."
80
- balanceType.isSubtype(of: Type<&{FungibleToken.Balance}>()): "Balance type must include FungibleToken.Balance interfaces."
77
+ balanceType.isSubtype(of: Type<&{FungibleToken.Vault}>()): "Balance type must include FungibleToken.Vault interfaces."
81
78
  providerType.isSubtype(of: Type<&{FungibleToken.Provider}>()): "Provider type must include FungibleToken.Provider interface."
82
79
  }
83
80
  self.tokenAlias=tokenAlias
@@ -93,300 +90,307 @@ pub contract FindViews {
93
90
  }
94
91
  }
95
92
 
96
- // This is an example taken from Versus
97
- pub struct CreativeWork {
98
- pub let artist: String
99
- pub let name: String
100
- pub let description: String
101
- pub let type: String
102
-
103
- init(artist: String, name: String, description: String, type: String) {
104
- self.artist=artist
105
- self.name=name
106
- self.description=description
107
- self.type=type
108
- }
109
- }
110
-
111
-
112
- /// A basic pointer that can resolve data and get owner/id/uuid and gype
113
- pub struct interface Pointer {
114
- pub let id: UInt64
115
- pub fun resolveView(_ type: Type) : AnyStruct?
116
- pub fun getUUID() :UInt64
117
- pub fun getViews() : [Type]
118
- pub fun owner() : Address
119
- pub fun valid() : Bool
120
- pub fun getItemType() : Type
121
- pub fun getViewResolver() : &AnyResource{MetadataViews.Resolver}
122
-
123
- //There are just convenience functions for shared views in the standard
124
- pub fun getRoyalty() : MetadataViews.Royalties
125
- pub fun getTotalRoyaltiesCut() : UFix64
126
-
127
- //Requred views
128
- pub fun getDisplay() : MetadataViews.Display
129
- pub fun getNFTCollectionData() : MetadataViews.NFTCollectionData
130
-
131
- pub fun checkSoulBound() : Bool
132
-
133
- }
134
-
135
- //An interface to say that this pointer can withdraw
136
- pub struct interface AuthPointer {
137
- pub fun withdraw() : @AnyResource
138
- }
139
-
140
- pub struct ViewReadPointer : Pointer {
141
- access(self) let cap: Capability<&{MetadataViews.ResolverCollection}>
142
- pub let id: UInt64
143
- pub let uuid: UInt64
144
- pub let itemType: Type
145
-
146
- init(cap: Capability<&{MetadataViews.ResolverCollection}>, id: UInt64) {
147
- self.cap=cap
148
- self.id=id
149
-
150
- if !self.cap.check() {
151
- panic("The capability is not valid.")
152
- }
153
- let viewResolver=self.cap.borrow()!.borrowViewResolver(id: self.id)
154
- let display = MetadataViews.getDisplay(viewResolver) ?? panic("MetadataViews Display View is not implemented on this NFT.")
155
- let nftCollectionData = MetadataViews.getNFTCollectionData(viewResolver) ?? panic("MetadataViews NFTCollectionData View is not implemented on this NFT.")
156
- self.uuid=viewResolver.uuid
157
- self.itemType=viewResolver.getType()
158
- }
159
-
160
- pub fun resolveView(_ type: Type) : AnyStruct? {
161
- return self.getViewResolver().resolveView(type)
162
- }
163
-
164
- pub fun getUUID() :UInt64{
165
- return self.uuid
166
- }
167
-
168
- pub fun getViews() : [Type]{
169
- return self.getViewResolver().getViews()
170
- }
171
-
172
- pub fun owner() : Address {
173
- return self.cap.address
174
- }
175
-
176
- pub fun getTotalRoyaltiesCut() :UFix64 {
177
- var total=0.0
178
- for royalty in self.getRoyalty().getRoyalties() {
179
- total = total + royalty.cut
180
- }
181
- return total
182
- }
183
-
184
- pub fun getRoyalty() : MetadataViews.Royalties {
185
- if let v = MetadataViews.getRoyalties(self.getViewResolver()) {
186
- return v
187
- }
188
- return MetadataViews.Royalties([])
189
- }
190
-
191
- pub fun valid() : Bool {
192
- if !self.cap.check() || !self.cap.borrow()!.getIDs().contains(self.id) {
193
- return false
194
- }
195
- return true
196
- }
197
-
198
- pub fun getItemType() : Type {
199
- return self.itemType
200
- }
201
-
202
- pub fun getViewResolver() : &AnyResource{MetadataViews.Resolver} {
203
- return self.cap.borrow()?.borrowViewResolver(id: self.id) ?? panic("The capability of view pointer is not linked.")
204
- }
205
-
206
- pub fun getDisplay() : MetadataViews.Display {
207
- if let v = MetadataViews.getDisplay(self.getViewResolver()) {
208
- return v
209
- }
210
- panic("MetadataViews Display View is not implemented on this NFT.")
211
- }
212
-
213
- pub fun getNFTCollectionData() : MetadataViews.NFTCollectionData {
214
- if let v = MetadataViews.getNFTCollectionData(self.getViewResolver()) {
215
- return v
216
- }
217
- panic("MetadataViews NFTCollectionData View is not implemented on this NFT.")
218
- }
219
-
220
- pub fun checkSoulBound() : Bool {
221
- return FindViews.checkSoulBound(self.getViewResolver())
222
- }
223
- }
224
-
225
-
226
- pub fun getNounce(_ viewResolver: &{MetadataViews.Resolver}) : UInt64 {
227
- if let nounce = viewResolver.resolveView(Type<FindViews.Nounce>()) {
228
- if let v = nounce as? FindViews.Nounce {
229
- return v.nounce
230
- }
231
- }
232
- return 0
233
- }
234
-
235
-
236
- pub struct AuthNFTPointer : Pointer, AuthPointer{
237
- access(self) let cap: Capability<&{MetadataViews.ResolverCollection, NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>
238
- pub let id: UInt64
239
- pub let nounce: UInt64
240
- pub let uuid: UInt64
241
- pub let itemType: Type
242
-
243
- init(cap: Capability<&{MetadataViews.ResolverCollection, NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>, id: UInt64) {
244
- self.cap=cap
245
- self.id=id
246
-
247
- if !self.cap.check() {
248
- panic("The capability is not valid.")
249
- }
250
-
251
- let viewResolver=self.cap.borrow()!.borrowViewResolver(id: self.id)
252
- let display = MetadataViews.getDisplay(viewResolver) ?? panic("MetadataViews Display View is not implemented on this NFT.")
253
- let nftCollectionData = MetadataViews.getNFTCollectionData(viewResolver) ?? panic("MetadataViews NFTCollectionData View is not implemented on this NFT.")
254
- self.nounce=FindViews.getNounce(viewResolver)
255
- self.uuid=viewResolver.uuid
256
- self.itemType=viewResolver.getType()
257
- }
258
-
259
- pub fun getViewResolver() : &AnyResource{MetadataViews.Resolver} {
260
- return self.cap.borrow()?.borrowViewResolver(id: self.id) ?? panic("The capability of view pointer is not linked.")
261
- }
262
-
263
- pub fun resolveView(_ type: Type) : AnyStruct? {
264
- return self.getViewResolver().resolveView(type)
265
- }
266
-
267
- pub fun getUUID() :UInt64{
268
- return self.uuid
269
- }
270
-
271
- pub fun getViews() : [Type]{
272
- return self.getViewResolver().getViews()
273
- }
274
-
275
- pub fun valid() : Bool {
276
- if !self.cap.check() || !self.cap.borrow()!.getIDs().contains(self.id) {
277
- return false
278
- }
279
-
280
- let viewResolver=self.getViewResolver()
281
-
282
- if let nounce = viewResolver.resolveView(Type<FindViews.Nounce>()) {
283
- if let v = nounce as? FindViews.Nounce {
284
- return v.nounce==self.nounce
285
- }
286
- }
287
- return true
288
- }
289
-
290
- pub fun getTotalRoyaltiesCut() :UFix64 {
291
- var total=0.0
292
- for royalty in self.getRoyalty().getRoyalties() {
293
- total = total + royalty.cut
294
- }
295
- return total
296
- }
297
-
298
- pub fun getRoyalty() : MetadataViews.Royalties {
299
- if let v = MetadataViews.getRoyalties(self.getViewResolver()) {
300
- return v
301
- }
302
- return MetadataViews.Royalties([])
303
- }
304
-
305
- pub fun getDisplay() : MetadataViews.Display {
306
- if let v = MetadataViews.getDisplay(self.getViewResolver()) {
307
- return v
308
- }
309
- panic("MetadataViews Display View is not implemented on this NFT.")
310
- }
311
-
312
- pub fun getNFTCollectionData() : MetadataViews.NFTCollectionData {
313
- if let v = MetadataViews.getNFTCollectionData(self.getViewResolver()) {
314
- return v
315
- }
316
- panic("MetadataViews NFTCollectionData View is not implemented on this NFT.")
317
- }
318
-
319
- pub fun withdraw() :@NonFungibleToken.NFT {
320
- if !self.cap.check() {
321
- panic("The pointer capability is invalid.")
322
- }
323
- return <- self.cap.borrow()!.withdraw(withdrawID: self.id)
324
- }
325
-
326
- pub fun deposit(_ nft: @NonFungibleToken.NFT){
93
+ // This is an example taken from Versus
94
+ access(all) struct CreativeWork {
95
+ access(all) let artist: String
96
+ access(all) let name: String
97
+ access(all) let description: String
98
+ access(all) let type: String
99
+
100
+ init(artist: String, name: String, description: String, type: String) {
101
+ self.artist=artist
102
+ self.name=name
103
+ self.description=description
104
+ self.type=type
105
+ }
106
+ }
107
+
108
+ /// A basic pointer that can resolve data and get owner/id/uuid and gype
109
+ access(all) struct interface Pointer {
110
+ access(all) let id: UInt64
111
+ access(all) fun resolveView(_ type: Type) : AnyStruct?
112
+ access(all) fun getUUID() :UInt64
113
+ access(all) fun getViews() : [Type]
114
+ access(all) fun owner() : Address
115
+ access(all) fun valid() : Bool
116
+ access(all) fun getItemType() : Type
117
+ access(all) fun getViewResolver() : &{ViewResolver.Resolver}
118
+
119
+ //There are just convenience functions for shared views in the standard
120
+ access(all) fun getRoyalty() : MetadataViews.Royalties
121
+ access(all) fun getTotalRoyaltiesCut() : UFix64
122
+
123
+ //Requred views
124
+ access(all) fun getDisplay() : MetadataViews.Display
125
+ access(all) fun getNFTCollectionData() : MetadataViews.NFTCollectionData
126
+
127
+ access(all) fun checkSoulBound() : Bool
128
+
129
+ }
130
+
131
+ //An interface to say that this pointer can withdraw
132
+ access(all) struct interface AuthPointer {
133
+ access(all) fun withdraw() : @AnyResource
134
+ }
135
+
136
+ access(all) struct ViewReadPointer : Pointer {
137
+ access(self) let cap: Capability<&{ViewResolver.ResolverCollection}>
138
+ access(all) let id: UInt64
139
+ access(all) let uuid: UInt64
140
+ access(all) let itemType: Type
141
+
142
+ init(cap: Capability<&{ViewResolver.ResolverCollection}>, id: UInt64) {
143
+ self.cap=cap
144
+ self.id=id
145
+
146
+ if !self.cap.check() {
147
+ panic("The capability is not valid.")
148
+ }
149
+ let viewResolver=self.cap.borrow()!.borrowViewResolver(id: self.id)!
150
+ let display = MetadataViews.getDisplay(viewResolver) ?? panic("MetadataViews Display View is not implemented on this NFT.")
151
+ let nftCollectionData = MetadataViews.getNFTCollectionData(viewResolver) ?? panic("MetadataViews NFTCollectionData View is not implemented on this NFT.")
152
+ self.uuid=viewResolver.uuid
153
+ self.itemType=viewResolver.getType()
154
+ }
155
+
156
+ access(all) fun resolveView(_ type: Type) : AnyStruct? {
157
+ return self.getViewResolver().resolveView(type)
158
+ }
159
+
160
+ access(all) fun getUUID() :UInt64{
161
+ return self.uuid
162
+ }
163
+
164
+ access(all) fun getViews() : [Type]{
165
+ return self.getViewResolver().getViews()
166
+ }
167
+
168
+ access(all) fun owner() : Address {
169
+ return self.cap.address
170
+ }
171
+
172
+ access(all) fun getTotalRoyaltiesCut() :UFix64 {
173
+ var total=0.0
174
+ for royalty in self.getRoyalty().getRoyalties() {
175
+ total = total + royalty.cut
176
+ }
177
+ return total
178
+ }
179
+
180
+ access(all) fun getRoyalty() : MetadataViews.Royalties {
181
+ if let v = MetadataViews.getRoyalties(self.getViewResolver()) {
182
+ return v
183
+ }
184
+ return MetadataViews.Royalties([])
185
+ }
186
+
187
+ access(all) fun valid() : Bool {
188
+ if !self.cap.check() || self.cap.borrow()!.borrowViewResolver(id: self.id) == nil {
189
+ return false
190
+ }
191
+ return true
192
+ }
193
+
194
+ access(all) fun getItemType() : Type {
195
+ return self.itemType
196
+ }
197
+
198
+ access(all) fun getViewResolver() : &{ViewResolver.Resolver} {
199
+ let nft=self.cap.borrow()!.borrowViewResolver(id: self.id) ?? panic("The capability of view pointer is not linked.")
200
+ return nft
201
+
202
+ }
203
+
204
+ access(all) fun getDisplay() : MetadataViews.Display {
205
+ if let v = MetadataViews.getDisplay(self.getViewResolver()) {
206
+ return v
207
+ }
208
+ panic("MetadataViews Display View is not implemented on this NFT.")
209
+ }
210
+
211
+ access(all) fun getNFTCollectionData() : MetadataViews.NFTCollectionData {
212
+ if let v = MetadataViews.getNFTCollectionData(self.getViewResolver()) {
213
+ return v
214
+ }
215
+ panic("MetadataViews NFTCollectionData View is not implemented on this NFT.")
216
+ }
217
+
218
+ access(all) fun checkSoulBound() : Bool {
219
+ return FindViews.checkSoulBound(self.getViewResolver())
220
+ }
221
+ }
222
+
223
+
224
+ access(all) fun getNounce(_ viewResolver: &{ViewResolver.Resolver}) : UInt64 {
225
+ if let nounce = viewResolver.resolveView(Type<FindViews.Nounce>()) {
226
+ if let v = nounce as? FindViews.Nounce {
227
+ return v.nounce
228
+ }
229
+ }
230
+ return 0
231
+ }
232
+
233
+ access(all) struct AuthNFTPointer : Pointer, AuthPointer{
234
+ access(self) let cap: Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.CollectionPublic, NonFungibleToken.Provider, ViewResolver.ResolverCollection}>
235
+ access(all) let id: UInt64
236
+ access(all) let nounce: UInt64
237
+ access(all) let uuid: UInt64
238
+ access(all) let itemType: Type
239
+
240
+ init(cap: Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection, NonFungibleToken.Provider, ViewResolver.ResolverCollection}>, id: UInt64) {
241
+ self.cap=cap
242
+ self.id=id
243
+
244
+ if !self.cap.check() {
245
+ panic("The capability is not valid.")
246
+ }
247
+
248
+ let collection = self.cap.borrow() ?? panic("could not find collection")
249
+ let viewResolver=collection.borrowNFT(self.id) ?? panic("could not borrow nft")
250
+ let display = MetadataViews.getDisplay(viewResolver) ?? panic("MetadataViews Display View is not implemented on this NFT.")
251
+ let nftCollectionData = MetadataViews.getNFTCollectionData(viewResolver) ?? panic("MetadataViews NFTCollectionData View is not implemented on this NFT.")
252
+ self.nounce=FindViews.getNounce(viewResolver)
253
+ self.uuid=viewResolver.uuid
254
+ self.itemType=viewResolver.getType()
255
+ }
256
+
257
+ access(all) fun getViewResolver() : &{ViewResolver.Resolver} {
258
+ let cap = self.cap.borrow()!
259
+ let viewResolver = cap.borrowNFT(self.id) ?? panic("The capability of view pointer is not linked.")
260
+ return viewResolver
261
+ }
262
+
263
+ access(all) fun resolveView(_ type: Type) : AnyStruct? {
264
+ return self.getViewResolver().resolveView(type)
265
+ }
266
+
267
+ access(all) fun getUUID() :UInt64{
268
+ return self.uuid
269
+ }
270
+
271
+ access(all) fun getViews() : [Type]{
272
+ return self.getViewResolver().getViews()
273
+ }
274
+
275
+ access(all) fun valid() : Bool {
276
+ if !self.cap.check() {
277
+ return false
278
+ }
279
+
280
+ let nft= self.cap.borrow()!.borrowNFT(self.id)
281
+
282
+ if nft ==nil {
283
+ return false
284
+ }
285
+
286
+ if let nounce = nft!.resolveView(Type<FindViews.Nounce>()) {
287
+ if let v = nounce as? FindViews.Nounce {
288
+ return v.nounce==self.nounce
289
+ }
290
+ }
291
+ return true
292
+ }
293
+
294
+ access(all) fun getTotalRoyaltiesCut() :UFix64 {
295
+ var total=0.0
296
+ for royalty in self.getRoyalty().getRoyalties() {
297
+ total = total + royalty.cut
298
+ }
299
+ return total
300
+ }
301
+
302
+ access(all) fun getRoyalty() : MetadataViews.Royalties {
303
+ if let v = MetadataViews.getRoyalties(self.getViewResolver()) {
304
+ return v
305
+ }
306
+ return MetadataViews.Royalties([])
307
+ }
308
+
309
+ access(all) fun getDisplay() : MetadataViews.Display {
310
+ if let v = MetadataViews.getDisplay(self.getViewResolver()) {
311
+ return v
312
+ }
313
+ panic("MetadataViews Display View is not implemented on this NFT.")
314
+ }
315
+
316
+ access(all) fun getNFTCollectionData() : MetadataViews.NFTCollectionData {
317
+ if let v = MetadataViews.getNFTCollectionData(self.getViewResolver()) {
318
+ return v
319
+ }
320
+ panic("MetadataViews NFTCollectionData View is not implemented on this NFT.")
321
+ }
322
+
323
+ access(all) fun withdraw() :@{NonFungibleToken.NFT} {
324
+ if !self.cap.check() {
325
+ panic("The pointer capability is invalid.")
326
+ }
327
+ return <- self.cap.borrow()!.withdraw(withdrawID: self.id)
328
+ }
329
+
330
+ access(all) fun deposit(_ nft: @{NonFungibleToken.NFT}){
327
331
  if !self.cap.check(){
328
332
  panic("The pointer capablity is invalid.")
329
333
  }
330
- self.cap.borrow()!.deposit(token: <- nft)
331
- }
332
-
333
- pub fun owner() : Address {
334
- return self.cap.address
335
- }
336
-
337
- pub fun getItemType() : Type {
338
- return self.itemType
339
- }
340
-
341
- pub fun checkSoulBound() : Bool {
342
- return FindViews.checkSoulBound(self.getViewResolver())
343
- }
344
- }
345
-
346
- pub fun createViewReadPointer(address:Address, path:PublicPath, id:UInt64) : ViewReadPointer {
347
- let cap= getAccount(address).getCapability<&{MetadataViews.ResolverCollection}>(path)
348
- let pointer= FindViews.ViewReadPointer(cap: cap, id: id)
349
- return pointer
350
- }
351
-
352
- pub struct Nounce {
353
- pub let nounce: UInt64
354
-
355
- init(_ nounce: UInt64) {
356
- self.nounce=nounce
357
- }
358
- }
359
-
360
- pub struct SoulBound {
361
-
362
- pub let message: String
363
-
364
- init(_ message:String) {
365
- self.message=message
366
-
367
- }
368
- }
369
-
370
- pub fun checkSoulBound(_ viewResolver: &{MetadataViews.Resolver}) : Bool {
371
- if let soulBound = viewResolver.resolveView(Type<FindViews.SoulBound>()) {
372
- if let v = soulBound as? FindViews.SoulBound {
373
- return true
374
- }
375
- }
376
- return false
377
- }
378
-
379
- pub fun getDapperAddress(): Address {
380
- switch FindViews.account.address.toString() {
381
- case "0x097bafa4e0b48eef":
382
- //mainnet
383
- return 0xead892083b3e2c6c
384
- case "0x35717efbbce11c74":
385
- //testnet
386
- return 0x82ec283f88a62e65
387
- default:
388
- //emulator
389
- return 0x01cf0e2f2f715450
390
- }
391
- }
334
+ self.cap.borrow()!.deposit(token: <- nft)
335
+ }
336
+
337
+ access(all) fun owner() : Address {
338
+ return self.cap.address
339
+ }
340
+
341
+ access(all) fun getItemType() : Type {
342
+ return self.itemType
343
+ }
344
+
345
+ access(all) fun checkSoulBound() : Bool {
346
+ return FindViews.checkSoulBound(self.getViewResolver())
347
+ }
348
+ }
349
+
350
+ access(all) fun createViewReadPointer(address:Address, path:PublicPath, id:UInt64) : ViewReadPointer {
351
+ let cap= getAccount(address).capabilities.get<&{ViewResolver.ResolverCollection}>(path)!
352
+ let pointer= FindViews.ViewReadPointer(cap: cap, id: id)
353
+ return pointer
354
+ }
355
+
356
+ access(all) struct Nounce {
357
+ access(all) let nounce: UInt64
358
+
359
+ init(_ nounce: UInt64) {
360
+ self.nounce=nounce
361
+ }
362
+ }
363
+
364
+ access(all) struct SoulBound {
365
+
366
+ access(all) let message: String
367
+
368
+ init(_ message:String) {
369
+ self.message=message
370
+
371
+ }
372
+ }
373
+
374
+ access(all) fun checkSoulBound(_ viewResolver: &{ViewResolver.Resolver}) : Bool {
375
+ if let soulBound = viewResolver.resolveView(Type<FindViews.SoulBound>()) {
376
+ if let v = soulBound as? FindViews.SoulBound {
377
+ return true
378
+ }
379
+ }
380
+ return false
381
+ }
382
+
383
+ access(all) fun getDapperAddress(): Address {
384
+ switch FindViews.account.address.toString() {
385
+ case "0x097bafa4e0b48eef":
386
+ //mainnet
387
+ return 0xead892083b3e2c6c
388
+ case "0x35717efbbce11c74":
389
+ //testnet
390
+ return 0x82ec283f88a62e65
391
+ default:
392
+ //emulator
393
+ return 0x01cf0e2f2f715450
394
+ }
395
+ }
392
396
  }