@flowtyio/flow-contracts 0.1.0-beta.4 → 0.1.0-beta.5
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.
|
@@ -143,6 +143,10 @@ access(all) contract ExampleNFT: ViewResolver {
|
|
|
143
143
|
}
|
|
144
144
|
return nil
|
|
145
145
|
}
|
|
146
|
+
|
|
147
|
+
access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
|
|
148
|
+
return <- ExampleNFT.createEmptyCollection()
|
|
149
|
+
}
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
access(all) resource interface ExampleNFTCollectionPublic: NonFungibleToken.Collection {
|
|
@@ -185,6 +189,14 @@ access(all) contract ExampleNFT: ViewResolver {
|
|
|
185
189
|
}
|
|
186
190
|
}
|
|
187
191
|
|
|
192
|
+
access(all) view fun getIDs(): [UInt64] {
|
|
193
|
+
return self.ownedNFTs.keys
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
|
|
197
|
+
return &self.ownedNFTs[id]
|
|
198
|
+
}
|
|
199
|
+
|
|
188
200
|
access(all) view fun isSupportedNFTType(type: Type): Bool {
|
|
189
201
|
return type == Type<@ExampleNFT.NFT>()
|
|
190
202
|
}
|
|
@@ -194,10 +206,10 @@ access(all) contract ExampleNFT: ViewResolver {
|
|
|
194
206
|
}
|
|
195
207
|
|
|
196
208
|
// withdraw removes an NFT from the collection and moves it to the caller
|
|
197
|
-
access(NonFungibleToken.
|
|
209
|
+
access(NonFungibleToken.Withdraw | NonFungibleToken.Owner) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
|
|
198
210
|
let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("missing NFT")
|
|
199
211
|
|
|
200
|
-
emit Withdraw(id: token.
|
|
212
|
+
emit Withdraw(id: token.id, from: self.owner?.address)
|
|
201
213
|
|
|
202
214
|
return <-token
|
|
203
215
|
}
|
|
@@ -216,17 +228,6 @@ access(all) contract ExampleNFT: ViewResolver {
|
|
|
216
228
|
|
|
217
229
|
destroy oldToken
|
|
218
230
|
}
|
|
219
|
-
|
|
220
|
-
// getIDs returns an array of the IDs that are in the collection
|
|
221
|
-
access(all) view fun getIDs(): [UInt64] {
|
|
222
|
-
return self.ownedNFTs.keys
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// borrowNFT gets a reference to an NFT in the collection
|
|
226
|
-
// so that the caller can read its metadata and call its methods
|
|
227
|
-
access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
|
|
228
|
-
return &self.ownedNFTs[id]
|
|
229
|
-
}
|
|
230
231
|
|
|
231
232
|
access(all) fun borrowExampleNFT(id: UInt64): &ExampleNFT.NFT? {
|
|
232
233
|
if self.ownedNFTs[id] != nil {
|
|
@@ -343,16 +344,14 @@ access(all) contract ExampleNFT: ViewResolver {
|
|
|
343
344
|
/// @param view: The Type of the desired view.
|
|
344
345
|
/// @return A structure representing the requested view.
|
|
345
346
|
///
|
|
346
|
-
access(all)
|
|
347
|
-
switch
|
|
347
|
+
access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
|
|
348
|
+
switch viewType {
|
|
348
349
|
case Type<MetadataViews.NFTCollectionData>():
|
|
349
350
|
return MetadataViews.NFTCollectionData(
|
|
350
351
|
storagePath: ExampleNFT.CollectionStoragePath,
|
|
351
352
|
publicPath: ExampleNFT.CollectionPublicPath,
|
|
352
|
-
providerPath: /private/exampleNFTCollection,
|
|
353
353
|
publicCollection: Type<&ExampleNFT.Collection>(),
|
|
354
354
|
publicLinkedType: Type<&ExampleNFT.Collection>(),
|
|
355
|
-
providerLinkedType: Type<auth(NonFungibleToken.Withdrawable) &ExampleNFT.Collection>(),
|
|
356
355
|
createEmptyCollectionFunction: (fun (): @{NonFungibleToken.Collection} {
|
|
357
356
|
return <-ExampleNFT.createEmptyCollection()
|
|
358
357
|
})
|
|
@@ -383,7 +382,7 @@ access(all) contract ExampleNFT: ViewResolver {
|
|
|
383
382
|
/// @return An array of Types defining the implemented views. This value will be used by
|
|
384
383
|
/// developers to know which parameter to pass to the resolveView() method.
|
|
385
384
|
///
|
|
386
|
-
access(all) view fun
|
|
385
|
+
access(all) view fun getContractViews(resourceType: Type?): [Type] {
|
|
387
386
|
return [
|
|
388
387
|
Type<MetadataViews.NFTCollectionData>(),
|
|
389
388
|
Type<MetadataViews.NFTCollectionDisplay>()
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import "FungibleToken"
|
|
2
|
+
import "FungibleTokenMetadataViews"
|
|
3
|
+
import "MetadataViews"
|
|
2
4
|
|
|
3
5
|
|
|
4
6
|
// THIS CONTRACT IS FOR TESTING PURPOSES ONLY!
|
|
@@ -80,6 +82,20 @@ access(all) contract ExampleToken {
|
|
|
80
82
|
return /public/exampleTokenPublic
|
|
81
83
|
}
|
|
82
84
|
|
|
85
|
+
access(all) view fun isAvailableToWithdraw(amount: UFix64): Bool {
|
|
86
|
+
return self.balance >= amount
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/// Same as getViews above, but on a specific NFT instead of a contract
|
|
90
|
+
access(all) view fun getViews(): [Type] {
|
|
91
|
+
return ExampleToken.getContractViews(resourceType: nil)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/// Same as resolveView above, but on a specific NFT instead of a contract
|
|
95
|
+
access(all) fun resolveView(_ view: Type): AnyStruct? {
|
|
96
|
+
return ExampleToken.resolveContractView(resourceType: nil, viewType: view)
|
|
97
|
+
}
|
|
98
|
+
|
|
83
99
|
/// withdraw
|
|
84
100
|
///
|
|
85
101
|
/// Function that takes an amount as an argument
|
|
@@ -90,7 +106,7 @@ access(all) contract ExampleToken {
|
|
|
90
106
|
/// created Vault to the context that called so it can be deposited
|
|
91
107
|
/// elsewhere.
|
|
92
108
|
///
|
|
93
|
-
access(FungibleToken.
|
|
109
|
+
access(FungibleToken.Withdraw) fun withdraw(amount: UFix64): @{FungibleToken.Vault} {
|
|
94
110
|
self.balance = self.balance - amount
|
|
95
111
|
emit TokensWithdrawn(amount: amount, from: self.owner?.address)
|
|
96
112
|
return <-create Vault(balance: amount)
|
|
@@ -211,6 +227,57 @@ access(all) contract ExampleToken {
|
|
|
211
227
|
}
|
|
212
228
|
}
|
|
213
229
|
|
|
230
|
+
access(all) view fun getContractViews(resourceType: Type?): [Type] {
|
|
231
|
+
return [Type<FungibleTokenMetadataViews.FTView>(),
|
|
232
|
+
Type<FungibleTokenMetadataViews.FTDisplay>(),
|
|
233
|
+
Type<FungibleTokenMetadataViews.FTVaultData>(),
|
|
234
|
+
Type<FungibleTokenMetadataViews.TotalSupply>()]
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
|
|
238
|
+
switch viewType {
|
|
239
|
+
case Type<FungibleTokenMetadataViews.FTView>():
|
|
240
|
+
return FungibleTokenMetadataViews.FTView(
|
|
241
|
+
ftDisplay: self.resolveContractView(resourceType: nil, viewType: Type<FungibleTokenMetadataViews.FTDisplay>()) as! FungibleTokenMetadataViews.FTDisplay?,
|
|
242
|
+
ftVaultData: self.resolveContractView(resourceType: nil, viewType: Type<FungibleTokenMetadataViews.FTVaultData>()) as! FungibleTokenMetadataViews.FTVaultData?
|
|
243
|
+
)
|
|
244
|
+
case Type<FungibleTokenMetadataViews.FTDisplay>():
|
|
245
|
+
let media = MetadataViews.Media(
|
|
246
|
+
file: MetadataViews.HTTPFile(
|
|
247
|
+
url: "https://example.com"
|
|
248
|
+
),
|
|
249
|
+
mediaType: "image/svg+xml"
|
|
250
|
+
)
|
|
251
|
+
let medias = MetadataViews.Medias([media])
|
|
252
|
+
return FungibleTokenMetadataViews.FTDisplay(
|
|
253
|
+
name: "Example Token",
|
|
254
|
+
symbol: "EXAMPLE",
|
|
255
|
+
description: "",
|
|
256
|
+
externalURL: MetadataViews.ExternalURL("https://flow.com"),
|
|
257
|
+
logos: medias,
|
|
258
|
+
socials: {
|
|
259
|
+
"twitter": MetadataViews.ExternalURL("https://twitter.com/flow_blockchain")
|
|
260
|
+
}
|
|
261
|
+
)
|
|
262
|
+
case Type<FungibleTokenMetadataViews.FTVaultData>():
|
|
263
|
+
let vaultRef = ExampleToken.account.storage.borrow<auth(FungibleToken.Withdraw) &ExampleToken.Vault>(from: /storage/exampleTokenVault)
|
|
264
|
+
?? panic("Could not borrow reference to the contract's Vault!")
|
|
265
|
+
return FungibleTokenMetadataViews.FTVaultData(
|
|
266
|
+
storagePath: /storage/exampleTokenVault,
|
|
267
|
+
receiverPath: /public/exampleTokenReceiver,
|
|
268
|
+
metadataPath: /public/exampleTokenBalance,
|
|
269
|
+
receiverLinkedType: Type<&{FungibleToken.Receiver, FungibleToken.Vault}>(),
|
|
270
|
+
metadataLinkedType: Type<&{FungibleToken.Balance, FungibleToken.Vault}>(),
|
|
271
|
+
createEmptyVaultFunction: (fun (): @{FungibleToken.Vault} {
|
|
272
|
+
return <-vaultRef.createEmptyVault()
|
|
273
|
+
})
|
|
274
|
+
)
|
|
275
|
+
case Type<FungibleTokenMetadataViews.TotalSupply>():
|
|
276
|
+
return FungibleTokenMetadataViews.TotalSupply(totalSupply: ExampleToken.totalSupply)
|
|
277
|
+
}
|
|
278
|
+
return nil
|
|
279
|
+
}
|
|
280
|
+
|
|
214
281
|
init() {
|
|
215
282
|
self.totalSupply = 1000.0
|
|
216
283
|
|