diff --git a/scripts/example-nft/mint_to_account.cdc b/scripts/example-nft/mint_to_account.cdc index dd0b73d..c0d62c7 100644 --- a/scripts/example-nft/mint_to_account.cdc +++ b/scripts/example-nft/mint_to_account.cdc @@ -14,7 +14,6 @@ transaction(receiver: Address, name: String, description: String, thumbnail: Str let d = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type())! as! MetadataViews.NFTCollectionData let c = getAccount(receiver).capabilities.get<&{NonFungibleToken.CollectionPublic}>(d.publicPath) - ?? panic("no receiver capability found") let r = c.borrow() ?? panic("could not borrow collection") self.minter.mintNFT(recipient: r, name: name, description: description, thumbnail: thumbnail, royaltyReceipient: self.minter.owner!.address) } diff --git a/scripts/example-nft/setup_full.cdc b/scripts/example-nft/setup_full.cdc index 7f236d7..89dd0af 100644 --- a/scripts/example-nft/setup_full.cdc +++ b/scripts/example-nft/setup_full.cdc @@ -1,20 +1,18 @@ import "NonFungibleToken" import "MetadataViews" -import ExampleNFT from "ExampleNFT" +import "ExampleNFT" transaction { - prepare(acct: AuthAccount) { - let d = ExampleNFT.resolveView(Type())! as! MetadataViews.NFTCollectionData + prepare(acct: auth(BorrowValue, SaveValue, PublishCapability, UnpublishCapability) &Account) { + let d = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type())! as! MetadataViews.NFTCollectionData - if acct.borrow<&ExampleNFT.Collection>(from: d.storagePath) == nil { - acct.save(<- ExampleNFT.createEmptyCollection(), to: ExampleNFT.CollectionStoragePath) + if acct.storage.borrow<&ExampleNFT.Collection>(from: d.storagePath) == nil { + acct.storage.save(<- ExampleNFT.createEmptyCollection(), to: d.storagePath) } - acct.unlink(d.publicPath) - acct.link<&ExampleNFT.Collection{ExampleNFT.ExampleNFTCollectionPublic, NonFungibleToken.CollectionPublic}>(d.publicPath, target: d.storagePath) - - acct.unlink(d.providerPath) - acct.link<&ExampleNFT.Collection{ExampleNFT.ExampleNFTCollectionPublic, NonFungibleToken.CollectionPublic, NonFungibleToken.Provider}>(d.providerPath, target: d.storagePath) + acct.capabilities.unpublish(d.publicPath) + let cap = acct.capabilities.storage.issue<&ExampleNFT.Collection>(d.storagePath) + acct.capabilities.publish(cap, at: d.publicPath) } -} \ No newline at end of file +} diff --git a/scripts/example-nft/setup_only_save.cdc b/scripts/example-nft/setup_only_save.cdc index 0289a35..98c8e8d 100644 --- a/scripts/example-nft/setup_only_save.cdc +++ b/scripts/example-nft/setup_only_save.cdc @@ -4,9 +4,9 @@ import "MetadataViews" import "ExampleNFT" transaction { - prepare(acct: AuthAccount) { - if acct.borrow<&ExampleNFT.Collection>(from: ExampleNFT.CollectionStoragePath) == nil { - acct.save(<- ExampleNFT.createEmptyCollection(), to: ExampleNFT.CollectionStoragePath) + prepare(acct: auth(BorrowValue, SaveValue) &Account) { + if acct.storage.borrow<&ExampleNFT.Collection>(from: ExampleNFT.CollectionStoragePath) == nil { + acct.storage.save(<- ExampleNFT.createEmptyCollection(), to: ExampleNFT.CollectionStoragePath) } } } diff --git a/scripts/example-nft/setup_public.cdc b/scripts/example-nft/setup_public.cdc deleted file mode 100644 index 9b35d7a..0000000 --- a/scripts/example-nft/setup_public.cdc +++ /dev/null @@ -1,17 +0,0 @@ -import "NonFungibleToken" -import "MetadataViews" - -import "ExampleNFT" - -transaction { - prepare(acct: AuthAccount) { - let d = ExampleNFT.resolveView(Type())! as! MetadataViews.NFTCollectionData - - if acct.borrow<&ExampleNFT.Collection>(from: d.storagePath) == nil { - acct.save(<- ExampleNFT.createEmptyCollection(), to: ExampleNFT.CollectionStoragePath) - } - - acct.unlink(d.publicPath) - acct.link<&ExampleNFT.Collection{ExampleNFT.ExampleNFTCollectionPublic, NonFungibleToken.CollectionPublic}>(d.publicPath, target: d.storagePath) - } -} diff --git a/scripts/hybrid-custody/get_accessible_child_account_nfts.cdc b/scripts/hybrid-custody/get_accessible_child_account_nfts.cdc index 5d1c54a..5cf307a 100644 --- a/scripts/hybrid-custody/get_accessible_child_account_nfts.cdc +++ b/scripts/hybrid-custody/get_accessible_child_account_nfts.cdc @@ -5,45 +5,45 @@ import "MetadataViews" // This script iterates through a parent's child accounts, // identifies private paths with an accessible NonFungibleToken.Provider, and returns the corresponding typeIds -pub fun main(addr: Address): AnyStruct { - let manager = getAuthAccount(addr).borrow<&HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) ?? panic ("manager does not exist") - var typeIdsWithProvider = {} as {Address: [String]} +access(all) fun main(addr: Address, expectedAddressToIDs: {Address: [UInt64]}): AnyStruct { + let manager = getAuthAccount(addr).storage.borrow(from: HybridCustody.ManagerStoragePath) + ?? panic ("manager does not exist") - // Address -> nft UUID -> Display - var nftViews = {} as {Address: {UInt64: MetadataViews.Display}} + var typeIdsWithProvider: {Address: [String]} = {} + var nftViews: {Address: {UInt64: MetadataViews.Display}} = {} - - let providerType = Type>() + let providerType = Type() let collectionType: Type = Type<@{NonFungibleToken.CollectionPublic}>() - // Iterate through child accounts for address in manager.getChildAddresses() { - let acct = getAuthAccount(address) + let acct = getAuthAccount(address) let foundTypes: [String] = [] let views: {UInt64: MetadataViews.Display} = {} let childAcct = manager.borrowAccount(addr: address) ?? panic("child account not found") - // get all private paths - acct.forEachPrivate(fun (path: PrivatePath, type: Type): Bool { - // Check which private paths have NFT Provider AND can be borrowed - if !type.isSubtype(of: providerType){ - return true - } - if let cap = childAcct.getCapability(path: path, type: Type<&{NonFungibleToken.Provider}>()) { - let providerCap = cap as! Capability<&{NonFungibleToken.Provider}> - if !providerCap.check(){ - // if this isn't a provider capability, exit the account iteration function for this path - return true + for s in acct.storage.storagePaths { + for c in acct.capabilities.storage.getControllers(forPath: s) { + if !c.borrowType.isSubtype(of: providerType){ + continue + } + + if let cap: Capability = childAcct.getCapability(controllerID: c.capabilityID, type: providerType) { + let providerCap = cap as! Capability<&{NonFungibleToken.Provider}> + + if !providerCap.check(){ + continue + } + + foundTypes.append(cap.borrow<&AnyResource>()!.getType().identifier) + typeIdsWithProvider[address] = foundTypes + break } - foundTypes.append(cap.borrow<&AnyResource>()!.getType().identifier) } - return true - }) - typeIdsWithProvider[address] = foundTypes + } // iterate storage, check if typeIdsWithProvider contains the typeId, if so, add to views - acct.forEachStored(fun (path: StoragePath, type: Type): Bool { + acct.storage.forEachStored(fun (path: StoragePath, type: Type): Bool { if typeIdsWithProvider[address] == nil { return true @@ -59,12 +59,12 @@ pub fun main(addr: Address): AnyStruct { if type.isInstance(collectionType) { continue } - if let collection = acct.borrow<&{NonFungibleToken.CollectionPublic}>(from: path) { + if let collection = acct.storage.borrow<&{NonFungibleToken.CollectionPublic}>(from: path) { // Iterate over IDs & resolve the view for id in collection.getIDs() { - let nft = collection.borrowNFT(id: id) + let nft = collection.borrowNFT(id)! if let display = nft.resolveView(Type())! as? MetadataViews.Display { - views.insert(key: nft.uuid, display) + views.insert(key: id, display) } } } diff --git a/scripts/hybrid-custody/get_all_collection_data_from_storage.cdc b/scripts/hybrid-custody/get_all_collection_data_from_storage.cdc index fc60d80..8e1dc31 100644 --- a/scripts/hybrid-custody/get_all_collection_data_from_storage.cdc +++ b/scripts/hybrid-custody/get_all_collection_data_from_storage.cdc @@ -4,30 +4,31 @@ import "HybridCustody" /// Helper function that retrieves data about all publicly accessible NFTs in an account /// -pub fun getAllViewsFromAddress(_ address: Address): [MetadataViews.NFTCollectionData] { +access(all) fun getAllViewsFromAddress(_ address: Address): [MetadataViews.NFTCollectionData] { - let account: AuthAccount = getAuthAccount(address) + let account = getAuthAccount(address) let data: [MetadataViews.NFTCollectionData] = [] - let collectionType: Type = Type<@{NonFungibleToken.CollectionPublic, MetadataViews.ResolverCollection}>() + let collectionType: Type = Type<@{NonFungibleToken.Collection}>() let viewType: Type = Type() // Iterate over each public path - account.forEachStored(fun (path: StoragePath, type: Type): Bool { - // Return if not the type we're looking for - if !type.isInstance(collectionType) && !type.isSubtype(of: collectionType) { + account.storage.forEachStored(fun (path: StoragePath, type: Type): Bool { + // Return early if the collection is broken or is not the type we're looking for + if type.isRecovered || (!type.isInstance(collectionType) && !type.isSubtype(of: collectionType)) { return true } - if let collectionRef = account - .borrow<&{NonFungibleToken.CollectionPublic, MetadataViews.ResolverCollection}>(from: path) { + if let collectionRef = account.storage.borrow<&{NonFungibleToken.Collection}>(from: path) { // Return early if no Resolver found in the Collection let ids: [UInt64]= collectionRef.getIDs() if ids.length == 0 { return true } // Otherwise, attempt to get the NFTCollectionData & append if exists - if let dataView = collectionRef.borrowViewResolver(id: ids[0]).resolveView(viewType) as! MetadataViews.NFTCollectionData? { - data.append(dataView) + if let resolver = collectionRef.borrowViewResolver(id: ids[0]) { + if let dataView = resolver.resolveView(viewType) as! MetadataViews.NFTCollectionData? { + data.append(dataView) + } } } return true @@ -37,16 +38,14 @@ pub fun getAllViewsFromAddress(_ address: Address): [MetadataViews.NFTCollection /// Script that retrieve data about all NFT Collections in the storage of an account and any of its child accounts /// -pub fun main(address: Address): {Address: [MetadataViews.NFTCollectionData]} { +access(all) fun main(address: Address): {Address: [MetadataViews.NFTCollectionData]} { let allNFTData: {Address: [MetadataViews.NFTCollectionData]} = {address: getAllViewsFromAddress(address)} let seen: [Address] = [address] /* Iterate over any child accounts */ // - if let managerRef = getAccount(address).getCapability<&HybridCustody.Manager{HybridCustody.ManagerPublic}>( - HybridCustody.ManagerPublicPath - ).borrow() { + if let managerRef = getAccount(address).capabilities.borrow<&HybridCustody.Manager>(HybridCustody.ManagerPublicPath) { for childAddress in managerRef.getChildAddresses() { allNFTData.insert(key: childAddress, getAllViewsFromAddress(childAddress)) diff --git a/scripts/hybrid-custody/get_all_vault_bal_from_storage.cdc b/scripts/hybrid-custody/get_all_vault_bal_from_storage.cdc index 8516ba6..49682ed 100644 --- a/scripts/hybrid-custody/get_all_vault_bal_from_storage.cdc +++ b/scripts/hybrid-custody/get_all_vault_bal_from_storage.cdc @@ -4,9 +4,9 @@ import "HybridCustody" /// Returns a mapping of balances indexed on the Type of resource containing the balance /// -pub fun getAllBalancesInStorage(_ address: Address): {Type: UFix64} { +access(all) fun getAllBalancesInStorage(_ address: Address): {Type: UFix64} { // Get the account - let account: AuthAccount = getAuthAccount(address) + let account = getAuthAccount(address) // Init for return value let balances: {Type: UFix64} = {} // Track seen Types in array @@ -14,10 +14,10 @@ pub fun getAllBalancesInStorage(_ address: Address): {Type: UFix64} { // Assign the type we'll need let balanceType: Type = Type<@{FungibleToken.Balance}>() // Iterate over all stored items & get the path if the type is what we're looking for - account.forEachStored(fun (path: StoragePath, type: Type): Bool { - if type.isInstance(balanceType) || type.isSubtype(of: balanceType) { + account.storage.forEachStored(fun (path: StoragePath, type: Type): Bool { + if !type.isRecovered && (type.isInstance(balanceType) || type.isSubtype(of: balanceType)) { // Get a reference to the resource & its balance - let vaultRef = account.borrow<&{FungibleToken.Balance}>(from: path)! + let vaultRef = account.storage.borrow<&{FungibleToken.Balance}>(from: path)! // Insert a new values if it's the first time we've seen the type if !seen.contains(type) { balances.insert(key: type, vaultRef.balance) @@ -34,7 +34,7 @@ pub fun getAllBalancesInStorage(_ address: Address): {Type: UFix64} { /// Queries for FT.Vault balance of all FT.Vaults in the specified account and all of its associated accounts /// -pub fun main(address: Address): {Address: {Type: UFix64}} { +access(all) fun main(address: Address): {Address: {Type: UFix64}} { // Get the balance for the given address let balances: {Address: {Type: UFix64}} = { address: getAllBalancesInStorage(address) } @@ -43,7 +43,7 @@ pub fun main(address: Address): {Address: {Type: UFix64}} { /* Iterate over any associated accounts */ // - if let managerRef = getAuthAccount(address) + if let managerRef = getAuthAccount(address).storage .borrow<&HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) { for childAccount in managerRef.getChildAddresses() { diff --git a/scripts/hybrid-custody/get_nft_display_view_from_public.cdc b/scripts/hybrid-custody/get_nft_display_view_from_public.cdc deleted file mode 100644 index a4aaac1..0000000 --- a/scripts/hybrid-custody/get_nft_display_view_from_public.cdc +++ /dev/null @@ -1,53 +0,0 @@ -import "NonFungibleToken" -import "MetadataViews" -import "HybridCustody" - -/// Returns resolved Display from given address at specified path for each ID or nil if ResolverCollection is not found -/// -pub fun getViews(_ address: Address, _ resolverCollectionPath: PublicPath): {UInt64: MetadataViews.Display} { - - let account: PublicAccount = getAccount(address) - let views: {UInt64: MetadataViews.Display} = {} - - // Borrow the Collection - if let collection = account - .getCapability<&{NonFungibleToken.CollectionPublic, MetadataViews.ResolverCollection}>(resolverCollectionPath).borrow() { - // Iterate over IDs & resolve the view - for id in collection.getIDs() { - if let display = collection.borrowViewResolver(id: id).resolveView(Type()) as? MetadataViews.Display { - views.insert(key: id, display) - } - } - } - - return views -} - -/// Queries for MetadataViews.Display each NFT across all associated accounts from Collections at the provided -/// PublicPath -/// -pub fun main(address: Address, resolverCollectionPath: PublicPath): {Address: {UInt64: MetadataViews.Display}} { - - let allViews: {Address: {UInt64: MetadataViews.Display}} = {address: getViews(address, resolverCollectionPath)} - let seen: [Address] = [address] - - /* Iterate over any associated accounts */ - // - if let managerRef = getAuthAccount(address).borrow<&HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) { - - for childAccount in managerRef.getChildAddresses() { - allViews.insert(key: childAccount, getViews(address, resolverCollectionPath)) - seen.append(childAccount) - } - - for ownedAccount in managerRef.getOwnedAddresses() { - if seen.contains(ownedAccount) == false { - allViews.insert(key: ownedAccount, getViews(address, resolverCollectionPath)) - seen.append(ownedAccount) - } - } - } - - return allViews -} - \ No newline at end of file diff --git a/scripts/hybrid-custody/get_nft_display_view_from_storage.cdc b/scripts/hybrid-custody/get_nft_display_view_from_storage.cdc new file mode 100644 index 0000000..5395a61 --- /dev/null +++ b/scripts/hybrid-custody/get_nft_display_view_from_storage.cdc @@ -0,0 +1,56 @@ +import "NonFungibleToken" +import "ViewResolver" +import "MetadataViews" +import "HybridCustody" + +/// Returns resolved Display from given address at specified path for each ID or nil if ResolverCollection is not found +/// +access(all) fun getViews(_ address: Address, _ collectionPath: StoragePath): {UInt64: MetadataViews.Display} { + + let account = getAuthAccount(address) + let views: {UInt64: MetadataViews.Display} = {} + + // Borrow the Collection + if let collection = account.storage + .borrow<&{NonFungibleToken.Collection}>(from: collectionPath) { + // Iterate over IDs & resolve the view + for id in collection.getIDs() { + if let resolver = collection.borrowViewResolver(id: id) { + if let display = resolver.resolveView(Type()) as! MetadataViews.Display? { + views.insert(key: id, display) + } + } + } + } + + return views +} + +/// Queries for the MetadataViews.Display of each NFT across all associated accounts from Collections at the provided +/// PublicPath +/// +access(all) fun main(address: Address, collectionPath: StoragePath): {Address: {UInt64: MetadataViews.Display}} { + + let allViews: {Address: {UInt64: MetadataViews.Display}} = {address: getViews(address, collectionPath)} + let seen: [Address] = [address] + + /* Iterate over any associated accounts */ + // + if let managerRef = getAuthAccount(address).storage + .borrow<&HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) { + + for childAccount in managerRef.getChildAddresses() { + allViews.insert(key: childAccount, getViews(address, collectionPath)) + seen.append(childAccount) + } + + for ownedAccount in managerRef.getOwnedAddresses() { + if seen.contains(ownedAccount) == false { + allViews.insert(key: ownedAccount, getViews(address, collectionPath)) + seen.append(ownedAccount) + } + } + } + + return allViews +} diff --git a/scripts/hybrid-custody/get_owned_addresses.cdc b/scripts/hybrid-custody/get_owned_addresses.cdc index 555d7e6..4e8921c 100644 --- a/scripts/hybrid-custody/get_owned_addresses.cdc +++ b/scripts/hybrid-custody/get_owned_addresses.cdc @@ -2,9 +2,10 @@ import "HybridCustody" /// Returns a list of all ownedAccount addresses in the `parent` account's `HybridCustody.Manager` /// -pub fun main(parent: Address): [Address] { - let acct = getAuthAccount(parent) - let manager = acct.borrow<&HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) - ?? panic("manager not found") +access(all) fun main(parent: Address): [Address] { + let acct = getAuthAccount(parent) + let manager = acct.storage.borrow<&HybridCustody.Manager>( + from: HybridCustody.ManagerStoragePath + ) ?? panic("A HybridCustody Manager has not been initialized in account with address ".concat(parent.toString())) return manager.getOwnedAddresses() -} \ No newline at end of file +} diff --git a/scripts/hybrid-custody/get_parents_from_child.cdc b/scripts/hybrid-custody/get_parents_from_child.cdc index 91bff85..716c759 100644 --- a/scripts/hybrid-custody/get_parents_from_child.cdc +++ b/scripts/hybrid-custody/get_parents_from_child.cdc @@ -1,9 +1,9 @@ import "HybridCustody" -pub fun main(child: Address): {Address: Bool} { - let acct = getAuthAccount(child) - let o = acct.borrow<&HybridCustody.OwnedAccount>(from: HybridCustody.OwnedAccountStoragePath) - ?? panic("owned account not found") +access(all) fun main(child: Address): {Address: Bool} { + let acct = getAuthAccount(child) + let o = acct.storage.borrow<&HybridCustody.OwnedAccount>(from: HybridCustody.OwnedAccountStoragePath) + ?? panic("OwnedAccount not found in account with address ".concat(child.toString())) return o.getParentStatuses() } \ No newline at end of file diff --git a/scripts/test/can_get_child_factory_and_filter_caps.cdc b/scripts/test/can_get_child_factory_and_filter_caps.cdc index 03c9f7d..605c559 100644 --- a/scripts/test/can_get_child_factory_and_filter_caps.cdc +++ b/scripts/test/can_get_child_factory_and_filter_caps.cdc @@ -4,7 +4,6 @@ import "HybridCustody" // @parent - The parent account that this child is assigned to access(all) fun main(addr: Address, parent: Address): Bool { let identifier = HybridCustody.getChildAccountIdentifier(parent) - let path = PrivatePath(identifier: identifier) ?? panic("invalid public path identifier for parent address") let acct = getAuthAccount(addr) var controllerID: UInt64? = nil diff --git a/scripts/test/test_get_all_collection_data_from_storage.cdc b/scripts/test/test_get_all_collection_data_from_storage.cdc index 78cd3a4..362d80d 100644 --- a/scripts/test/test_get_all_collection_data_from_storage.cdc +++ b/scripts/test/test_get_all_collection_data_from_storage.cdc @@ -59,7 +59,7 @@ access(all) fun getAllViewsFromAddress(_ address: Address): [MetadataViews.NFTCo /// Script that retrieve data about all NFT Collections in the storage of an account and any of its child accounts /// -// pub fun main(address: Address): {Address: [MetadataViews.NFTCollectionData]} { +// access(all) fun main(address: Address): {Address: [MetadataViews.NFTCollectionData]} { access(all) fun main(address: Address, expectedAddressToCollectionLength: {Address: Int}) { let allNFTData: {Address: [MetadataViews.NFTCollectionData]} = {address: getAllViewsFromAddress(address)} diff --git a/scripts/test/test_get_nft_display_view_from_public.cdc b/scripts/test/test_get_nft_display_view_from_storage.cdc similarity index 67% rename from scripts/test/test_get_nft_display_view_from_public.cdc rename to scripts/test/test_get_nft_display_view_from_storage.cdc index 4ecd874..b0fded8 100644 --- a/scripts/test/test_get_nft_display_view_from_public.cdc +++ b/scripts/test/test_get_nft_display_view_from_storage.cdc @@ -5,7 +5,7 @@ import "ExampleNFT" import "HybridCustody" -/* +/* * TEST SCRIPT * This script is a replication of that found in hybrid-custody/get_nft_display_view_from_public as it's the best as * as can be done without accessing the script's return type in the Cadence testing framework @@ -25,18 +25,20 @@ access(all) fun assertPassing(result: {Address: {UInt64: MetadataViews.Display}} /// Returns resolved Display from given address at specified path for each ID or nil if ResolverCollection is not found /// -access(all) fun getViews(_ address: Address, _ resolverCollectionPath: PublicPath): {UInt64: MetadataViews.Display} { - let account: &Account = getAccount(address) +access(all) fun getViews(_ address: Address, _ collectionPath: StoragePath): {UInt64: MetadataViews.Display} { + let account = getAuthAccount(address) let views: {UInt64: MetadataViews.Display} = {} // Borrow the Collection - if let collection = account - .capabilities.get<&{NonFungibleToken.CollectionPublic}>(resolverCollectionPath)!.borrow() { + if let collection = account.storage + .borrow<&{NonFungibleToken.Collection}>(from: collectionPath) { // Iterate over IDs & resolve the view for id in collection.getIDs() { - let nft = collection.borrowNFT(id) ?? panic("could not borrow NFT") - let display = nft.resolveView(Type())! as! MetadataViews.Display - views.insert(key: id, display) + if let resolver = collection.borrowViewResolver(id: id) { + if let display = resolver.resolveView(Type()) as! MetadataViews.Display? { + views.insert(key: id, display) + } + } } } @@ -46,29 +48,29 @@ access(all) fun getViews(_ address: Address, _ resolverCollectionPath: PublicPat /// Queries for MetadataViews.Display each NFT across all associated accounts from Collections at the provided /// PublicPath /// -access(all) fun main(address: Address, resolverCollectionPath: PublicPath, expectedAddressToIDs: {Address: [UInt64]}) { - let allViews: {Address: {UInt64: MetadataViews.Display}} = {address: getViews(address, resolverCollectionPath)} +access(all) fun main(address: Address, collectionPath: StoragePath, expectedAddressToIDs: {Address: [UInt64]}) { + let allViews: {Address: {UInt64: MetadataViews.Display}} = {address: getViews(address, collectionPath)} let seen: [Address] = [address] - - /* Iterate over any associated accounts */ + + /* Iterate over any associated accounts */ // - if let managerRef = getAuthAccount(address).storage.borrow<&HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) { - + if let managerRef = getAuthAccount(address).storage + .borrow<&HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) { + for childAccount in managerRef.getChildAddresses() { - let views = getViews(childAccount, resolverCollectionPath) + let views = getViews(childAccount, collectionPath) allViews.insert(key: childAccount, views) seen.append(childAccount) } for ownedAccount in managerRef.getOwnedAddresses() { if seen.contains(ownedAccount) == false { - allViews.insert(key: ownedAccount, getViews(address, resolverCollectionPath)) + allViews.insert(key: ownedAccount, getViews(address, collectionPath)) seen.append(ownedAccount) } } } // Assert instead of return for testing purposes here assertPassing(result: allViews, expectedAddressToIDs: expectedAddressToIDs) - // return allViews + // return allViews } - \ No newline at end of file diff --git a/test/HybridCustody_tests.cdc b/test/HybridCustody_tests.cdc index 9781ca7..44a85af 100644 --- a/test/HybridCustody_tests.cdc +++ b/test/HybridCustody_tests.cdc @@ -649,7 +649,7 @@ fun testGetFlowBalanceByStoragePath() { } access(all) -fun testGetNFTDisplayViewFromPublic() { +fun testGetNFTDisplayViewFromStorage() { let child = Test.createAccount() let parent = Test.createAccount() @@ -669,8 +669,8 @@ fun testGetNFTDisplayViewFromPublic() { let expectedAddressToIDs: {Address: [UInt64]} = {parent.address: expectedParentIDs, child.address: expectedChildIDs} scriptExecutor( - "test/test_get_nft_display_view_from_public.cdc", - [parent.address, PublicPath(identifier: exampleNFTPublicIdentifier)!, expectedAddressToIDs] + "test/test_get_nft_display_view_from_storage.cdc", + [parent.address, StoragePath(identifier: exampleNFTPublicIdentifier)!, expectedAddressToIDs] ) } @@ -822,8 +822,8 @@ fun testGetNFTsAccessibleFromChildAccount(){ let expectedAddressToIDs: {Address: [UInt64]} = {child.address: expectedChildIDs, parent.address: expectedParentIDs} scriptExecutor( - "test/test_get_nft_display_view_from_public.cdc", - [parent.address, PublicPath(identifier: exampleNFTPublicIdentifier)!, expectedAddressToIDs] + "test/test_get_nft_display_view_from_storage.cdc", + [parent.address, StoragePath(identifier: exampleNFTPublicIdentifier)!, expectedAddressToIDs] ) // Test we have capabilities to access the minted NFTs @@ -838,8 +838,8 @@ fun testGetNFTsAccessibleFromChildAccount(){ let expectedAddressToIDs2: {Address: [UInt64]} = {child.address: expectedChildIDs2, parent.address: expectedParentIDs} scriptExecutor( - "test/test_get_nft_display_view_from_public.cdc", - [parent.address, PublicPath(identifier: exampleNFT2PublicIdentifier)!, expectedAddressToIDs2] + "test/test_get_nft_display_view_from_storage.cdc", + [parent.address, StoragePath(identifier: exampleNFT2PublicIdentifier)!, expectedAddressToIDs2] ) // revoke the ExampleNFT2 provider capability, preventing it from being returned. diff --git a/transactions/example-nft/setup_full.cdc b/transactions/example-nft/setup_full.cdc index c20ad67..8218855 100644 --- a/transactions/example-nft/setup_full.cdc +++ b/transactions/example-nft/setup_full.cdc @@ -4,7 +4,7 @@ import "MetadataViews" import "ExampleNFT" transaction { - prepare(acct: auth(Storage, Capabilities) &Account) { + prepare(acct: auth(BorrowValue, SaveValue, StorageCapabilities, PublishCapability, UnpublishCapability) &Account) { let d = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type())! as! MetadataViews.NFTCollectionData if acct.storage.borrow<&ExampleNFT.Collection>(from: d.storagePath) == nil { diff --git a/transactions/example-nft/setup_only_save.cdc b/transactions/example-nft/setup_only_save.cdc index 0289a35..98c8e8d 100644 --- a/transactions/example-nft/setup_only_save.cdc +++ b/transactions/example-nft/setup_only_save.cdc @@ -4,9 +4,9 @@ import "MetadataViews" import "ExampleNFT" transaction { - prepare(acct: AuthAccount) { - if acct.borrow<&ExampleNFT.Collection>(from: ExampleNFT.CollectionStoragePath) == nil { - acct.save(<- ExampleNFT.createEmptyCollection(), to: ExampleNFT.CollectionStoragePath) + prepare(acct: auth(BorrowValue, SaveValue) &Account) { + if acct.storage.borrow<&ExampleNFT.Collection>(from: ExampleNFT.CollectionStoragePath) == nil { + acct.storage.save(<- ExampleNFT.createEmptyCollection(), to: ExampleNFT.CollectionStoragePath) } } } diff --git a/transactions/example-nft/setup_public.cdc b/transactions/example-nft/setup_public.cdc deleted file mode 100644 index 9b35d7a..0000000 --- a/transactions/example-nft/setup_public.cdc +++ /dev/null @@ -1,17 +0,0 @@ -import "NonFungibleToken" -import "MetadataViews" - -import "ExampleNFT" - -transaction { - prepare(acct: AuthAccount) { - let d = ExampleNFT.resolveView(Type())! as! MetadataViews.NFTCollectionData - - if acct.borrow<&ExampleNFT.Collection>(from: d.storagePath) == nil { - acct.save(<- ExampleNFT.createEmptyCollection(), to: ExampleNFT.CollectionStoragePath) - } - - acct.unlink(d.publicPath) - acct.link<&ExampleNFT.Collection{ExampleNFT.ExampleNFTCollectionPublic, NonFungibleToken.CollectionPublic}>(d.publicPath, target: d.storagePath) - } -}