forked from onflow/flow-nft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
386 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// This transaction is what an account would run | ||
/// to set itself up to receive NFTs | ||
import "NonFungibleToken" | ||
import "ExampleNFT" | ||
import "MetadataViews" | ||
import "UniversalCollection" | ||
|
||
access(all) fun main(user:Address): [String]{ | ||
|
||
|
||
let messages : [String]=[] | ||
|
||
let signer = getAuthAccount<auth(BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue, UnpublishCapability, LoadValue) &Account>(user) | ||
|
||
let collectionData = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData? ?? panic("ViewResolver does not resolve NFTCollectionData view") | ||
|
||
let collection <- UniversalCollection.createEmptyCollection(identifier: "foo", type: ExampleNFT.getType()) | ||
signer.storage.save(<- collection, to:collectionData.storagePath) | ||
|
||
|
||
let col= signer.storage.borrow<&AnyResource>(from: collectionData.storagePath) as? &{NonFungibleToken.Collection}? | ||
if col != nil { | ||
messages.append("borrow using anyResource and then cast as restricted type") | ||
} | ||
return messages | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// This transaction is what an account would run | ||
/// to set itself up to receive NFTs | ||
import "NonFungibleToken" | ||
import "ExampleNFT" | ||
import "MetadataViews" | ||
import "UniversalCollection" | ||
|
||
access(all) fun main(user:Address): [String]{ | ||
|
||
|
||
let messages : [String]=[] | ||
|
||
let signer = getAuthAccount<auth(BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue, UnpublishCapability, LoadValue) &Account>(user) | ||
|
||
let collectionData = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData? ?? panic("ViewResolver does not resolve NFTCollectionData view") | ||
|
||
|
||
let col= signer.storage.borrow<&AnyResource>(from: collectionData.storagePath) as? &{NonFungibleToken.Collection}? | ||
if col != nil { | ||
messages.append("borrow using anyResource and then cast as restricted type") | ||
}else { | ||
|
||
messages.append("borrow using anyResource and then cast as restricted type, is empty") | ||
|
||
} | ||
return messages | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import "NonFungibleToken" | ||
import "ExampleNFT" | ||
import "MetadataViews" | ||
import "UniversalCollection" | ||
|
||
access(all) fun main(user:Address): [String]{ | ||
|
||
|
||
let messages : [String]=[] | ||
|
||
let signer = getAuthAccount<auth(BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue, UnpublishCapability, LoadValue) &Account>(user) | ||
|
||
let collectionData = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData? ?? panic("ViewResolver does not resolve NFTCollectionData view") | ||
|
||
|
||
let collection <- collectionData.createEmptyCollection() | ||
signer.storage.save(<-collection, to: collectionData.storagePath) | ||
|
||
//if we previously had a storage path there will be created a capcon for it but it will not be saved anywhere | ||
// signer.capabilities.storage.issue<auth(NonFungibleToken.Withdraw) &ExampleNFT.Collection>(collectionData.storagePath) | ||
|
||
let storagePathIdentifer = collectionData.storagePath.toString().split(separator:"/")[1] | ||
let providerIdentifier = storagePathIdentifer.concat("Provider") | ||
let providerStoragePath = StoragePath(identifier: providerIdentifier)! | ||
|
||
let existingProvider= signer.storage.borrow<&Capability>(from: providerStoragePath) | ||
if existingProvider==nil{ | ||
messages.append("could not find provider") | ||
let providerCap=signer.capabilities.storage.issue<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}>(collectionData.storagePath) | ||
signer.storage.save(providerCap, to: providerStoragePath) | ||
} | ||
|
||
if let existingProvider2= signer.storage.borrow<&Capability>(from: providerStoragePath) { | ||
messages.append("find provider second time") | ||
messages.append(existingProvider2.getType().identifier) | ||
|
||
if existingProvider2.check<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}>(){ | ||
messages.append("is provider cap") | ||
} else { | ||
messages.append("is notprovider cap") | ||
} | ||
} | ||
|
||
return messages | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import "NonFungibleToken" | ||
import "ExampleNFT" | ||
import "MetadataViews" | ||
import "UniversalCollection" | ||
|
||
access(all) fun main(user:Address): [String]{ | ||
|
||
|
||
let messages : [String]=[] | ||
|
||
let signer = getAuthAccount<auth(Storage, Capabilities) &Account>(user) | ||
|
||
let collectionData = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData? ?? panic("ViewResolver does not resolve NFTCollectionData view") | ||
|
||
|
||
let collection <- collectionData.createEmptyCollection() | ||
signer.storage.save(<-collection, to: collectionData.storagePath) | ||
|
||
//this is what will be in storage after we have migrated a public path | ||
let preCap =signer.capabilities.storage.issue<auth(NonFungibleToken.Withdraw) &ExampleNFT.Collection>(collectionData.storagePath) | ||
messages.append("cap ".concat(preCap.id.toString())) | ||
|
||
let pre2Cap =signer.capabilities.storage.issue<auth(NonFungibleToken.Withdraw) &ExampleNFT.Collection>(collectionData.storagePath) | ||
messages.append("cap ".concat(pre2Cap.id.toString())) | ||
|
||
|
||
signer.capabilities.storage.forEachController(forPath: collectionData.storagePath,fun(scc: &StorageCapabilityController): Bool { | ||
messages.append("pre ".concat(scc.capabilityID.toString()).concat(" ").concat(scc.target().toString())) | ||
return false | ||
}) | ||
|
||
|
||
let storagePathIdentifer = collectionData.storagePath.toString().split(separator:"/")[1] | ||
let providerIdentifier = storagePathIdentifer.concat("Provider") | ||
let providerStoragePath = StoragePath(identifier: providerIdentifier)! | ||
|
||
let existingProvider= signer.storage.borrow<&Capability>(from: providerStoragePath) | ||
if existingProvider==nil{ | ||
let providerCap=signer.capabilities.storage.issue<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}>(collectionData.storagePath) | ||
messages.append("issued providerCap ".concat(providerCap.id.toString())) | ||
//we save it to storage to memoize it | ||
signer.storage.save(providerCap, to: providerStoragePath) | ||
} else { | ||
if !existingProvider!.check<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}>(){ | ||
messages.append("we need to revoke") | ||
} | ||
} | ||
|
||
if let existingProvider2= signer.storage.borrow<&Capability>(from: providerStoragePath) { | ||
messages.append("find provider second time") | ||
messages.append(existingProvider2.getType().identifier) | ||
|
||
if existingProvider2.check<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Collection}>(){ | ||
messages.append("is provider cap") | ||
} else { | ||
messages.append("is notprovider cap") | ||
} | ||
} | ||
|
||
signer.capabilities.storage.forEachController(forPath: collectionData.storagePath,fun(scc: &StorageCapabilityController): Bool { | ||
messages.append("post ".concat(scc.capabilityID.toString()).concat(" ").concat(scc.target().toString())) | ||
return false | ||
}) | ||
|
||
return messages | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/// This transaction is what an account would run | ||
/// to set itself up to receive NFTs | ||
import "NonFungibleToken" | ||
import "ExampleNFT" | ||
import "MetadataViews" | ||
import "UniversalCollection" | ||
|
||
access(all) fun main(user:Address): [String]{ | ||
|
||
|
||
let messages : [String]=[] | ||
|
||
let signer = getAuthAccount<auth(BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue, UnpublishCapability, LoadValue) &Account>(user) | ||
|
||
let collectionData = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData? ?? panic("ViewResolver does not resolve NFTCollectionData view") | ||
|
||
|
||
let collection <- UniversalCollection.createEmptyCollection(identifier: "foo", type: ExampleNFT.getType()) | ||
signer.storage.save(<- collection, to:collectionData.storagePath) | ||
|
||
|
||
|
||
// Return early if the account already has a collection | ||
if let storedType =signer.storage.type(at: collectionData.storagePath) { | ||
if storedType.isSubtype(of: Type<@{NonFungibleToken.Collection}>()) { | ||
messages.append("store something that is NFT collection") | ||
} | ||
|
||
if storedType != Type<&ExampleNFT.Collection>() { | ||
messages.append("we do not store exampleNFT collection") | ||
destroy signer.storage.load<@AnyResource>(from: collectionData.storagePath) | ||
|
||
let collection <- ExampleNFT.createEmptyCollection(nftType: Type<@ExampleNFT.NFT>()) | ||
|
||
//this will not work if the storage has something else there already | ||
// save it to the account | ||
signer.storage.save(<-collection, to: collectionData.storagePath) | ||
messages.append("we could load and destory and add new collection") | ||
} | ||
} | ||
return messages | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
/// This transaction is what an account would run | ||
/// to set itself up to receive NFTs | ||
import "NonFungibleToken" | ||
import "ExampleNFT" | ||
import "MetadataViews" | ||
import "UniversalCollection" | ||
|
||
access(all) fun main(user:Address): [String]{ | ||
|
||
|
||
let messages : [String]=[] | ||
|
||
let signer = getAuthAccount<auth(BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue, UnpublishCapability, LoadValue) &Account>(user) | ||
|
||
let collectionData = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData? ?? panic("ViewResolver does not resolve NFTCollectionData view") | ||
|
||
|
||
signer.storage.save("foo", to:collectionData.storagePath) | ||
|
||
|
||
|
||
// Return early if the account already has a collection | ||
if let storedType =signer.storage.type(at: collectionData.storagePath) { | ||
if storedType.isSubtype(of: Type<@{NonFungibleToken.Collection}>()) { | ||
messages.append("store something that is NFT collection") | ||
} | ||
|
||
if storedType != Type<&ExampleNFT.Collection>() { | ||
|
||
if storedType.isSubtype(of: Type<@AnyResource>()) { | ||
destroy signer.storage.load<@AnyResource>(from: collectionData.storagePath) | ||
} else { | ||
signer.storage.load<AnyStruct>(from: collectionData.storagePath) | ||
} | ||
let collection <- ExampleNFT.createEmptyCollection(nftType: Type<@ExampleNFT.NFT>()) | ||
|
||
//this will not work if the storage has something else there already | ||
// save it to the account | ||
signer.storage.save(<-collection, to: collectionData.storagePath) | ||
messages.append("we could load and destory and add new collection") | ||
} | ||
} | ||
return messages | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/// This transaction is what an account would run | ||
/// to set itself up to receive NFTs | ||
import "NonFungibleToken" | ||
import "ExampleNFT" | ||
import "MetadataViews" | ||
import "UniversalCollection" | ||
|
||
access(all) fun main(user:Address): [String]{ | ||
|
||
|
||
let messages : [String]=[] | ||
|
||
let signer = getAuthAccount<auth(BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue, UnpublishCapability, LoadValue) &Account>(user) | ||
|
||
let collectionData = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>()) as! MetadataViews.NFTCollectionData? ?? panic("ViewResolver does not resolve NFTCollectionData view") | ||
|
||
|
||
signer.storage.save("foo", to:collectionData.storagePath) | ||
|
||
// Return early if the account already has a collection | ||
let col= signer.storage.borrow<&AnyResource>(from: collectionData.storagePath) as? &{NonFungibleToken.Collection}? | ||
if col == nil { | ||
messages.append("could not borrow string as AnyResource") | ||
} | ||
return messages | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.