From 4c512ffe25364e3cee6e7a1a05c5ee7e76204b54 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Wed, 9 Oct 2024 13:35:06 -0700 Subject: [PATCH 1/3] remove modules dir --- modules/flow-ft | 1 - modules/flow-nft | 1 - modules/flow-utils | 1 - 3 files changed, 3 deletions(-) delete mode 160000 modules/flow-ft delete mode 160000 modules/flow-nft delete mode 160000 modules/flow-utils diff --git a/modules/flow-ft b/modules/flow-ft deleted file mode 160000 index a31032a..0000000 --- a/modules/flow-ft +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a31032af9b68d92b2c01eb85cc2103fae698bb19 diff --git a/modules/flow-nft b/modules/flow-nft deleted file mode 160000 index 4c0c684..0000000 --- a/modules/flow-nft +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4c0c684baed98e2ffd7a8f9d27973c1db5dd1239 diff --git a/modules/flow-utils b/modules/flow-utils deleted file mode 160000 index c10ce02..0000000 --- a/modules/flow-utils +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c10ce024fad1abc67cde1e551ddc1e5f5771226c From 235c24dfb322a8a6e30cb7a8ba6f8d902ce10d65 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Wed, 16 Oct 2024 15:59:37 -0600 Subject: [PATCH 2/3] update deprecated scripts & txns --- scripts/example-nft/mint_to_account.cdc | 1 - scripts/example-nft/setup_full.cdc | 20 +++---- scripts/example-nft/setup_only_save.cdc | 6 +- scripts/example-nft/setup_public.cdc | 17 ------ .../get_accessible_child_account_nfts.cdc | 56 +++++++++---------- .../get_all_collection_data_from_storage.cdc | 27 +++++---- .../get_all_vault_bal_from_storage.cdc | 14 ++--- .../get_nft_display_view_from_public.cdc | 53 ------------------ .../get_nft_display_view_from_storage.cdc | 56 +++++++++++++++++++ .../hybrid-custody/get_owned_addresses.cdc | 11 ++-- .../hybrid-custody/get_parents_from_child.cdc | 8 +-- .../can_get_child_factory_and_filter_caps.cdc | 1 - ...t_get_all_collection_data_from_storage.cdc | 2 +- ...est_get_nft_display_view_from_storage.cdc} | 38 +++++++------ test/HybridCustody_tests.cdc | 14 ++--- transactions/example-nft/setup_full.cdc | 2 +- transactions/example-nft/setup_only_save.cdc | 6 +- transactions/example-nft/setup_public.cdc | 17 ------ 18 files changed, 158 insertions(+), 191 deletions(-) delete mode 100644 scripts/example-nft/setup_public.cdc delete mode 100644 scripts/hybrid-custody/get_nft_display_view_from_public.cdc create mode 100644 scripts/hybrid-custody/get_nft_display_view_from_storage.cdc rename scripts/test/{test_get_nft_display_view_from_public.cdc => test_get_nft_display_view_from_storage.cdc} (67%) delete mode 100644 transactions/example-nft/setup_public.cdc 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) - } -} From d4cba6e4c230201093c41654d16af9f1a81c3776 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Wed, 16 Oct 2024 16:05:00 -0600 Subject: [PATCH 3/3] update flow.json FlowToken dependency & remove previewnet --- flow.json | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/flow.json b/flow.json index 3787450..93cf630 100644 --- a/flow.json +++ b/flow.json @@ -99,14 +99,6 @@ "testnet": "294e44e1ec6993c6" } }, - "FlowToken": { - "source": "./node_modules/@flowtyio/flow-contracts/contracts/FlowToken.cdc", - "aliases": { - "emulator": "0ae53cb6e3f42a79", - "mainnet": "1654653399040a61", - "testnet": "7e60df042a9c0868" - } - }, "HybridCustody": { "source": "./contracts/HybridCustody.cdc", "aliases": { @@ -177,43 +169,48 @@ "testnet": "9a0766d93b6608b7" } }, + "FlowToken": { + "source": "mainnet://1654653399040a61.FlowToken", + "hash": "cefb25fd19d9fc80ce02896267eb6157a6b0df7b1935caa8641421fe34c0e67a", + "aliases": { + "emulator": "0ae53cb6e3f42a79", + "mainnet": "1654653399040a61", + "testnet": "7e60df042a9c0868" + } + }, "FungibleToken": { "source": "mainnet://f233dcee88fe0abe.FungibleToken", - "hash": "1410889b47fef8b02f6867eef3d67a75288a56a651b67a7e815ce273ad301cff", + "hash": "050328d01c6cde307fbe14960632666848d9b7ea4fef03ca8c0bbfb0f2884068", "aliases": { "emulator": "ee82856bf20e2aa6", "mainnet": "f233dcee88fe0abe", - "previewnet": "a0225e7000ac82a9", "testnet": "9a0766d93b6608b7" } }, "FungibleTokenMetadataViews": { "source": "mainnet://f233dcee88fe0abe.FungibleTokenMetadataViews", - "hash": "294ada6a3df68757fcac4d794f62307c2ea4fe49c93f67e3771d3c6d8377dd47", + "hash": "dff704a6e3da83997ed48bcd244aaa3eac0733156759a37c76a58ab08863016a", "aliases": { "emulator": "ee82856bf20e2aa6", "mainnet": "f233dcee88fe0abe", - "previewnet": "a0225e7000ac82a9", "testnet": "9a0766d93b6608b7" } }, "MetadataViews": { "source": "mainnet://1d7e57aa55817448.MetadataViews", - "hash": "be26ea7959d7cbc06ac69fe00926b812c4da67984ea2d1bde1029141ae091378", + "hash": "10a239cc26e825077de6c8b424409ae173e78e8391df62750b6ba19ffd048f51", "aliases": { "emulator": "f8d6e0586b0a20c7", "mainnet": "1d7e57aa55817448", - "previewnet": "b6763b4399a888c8", "testnet": "631e88ae7f1d7c20" } }, "NonFungibleToken": { "source": "mainnet://1d7e57aa55817448.NonFungibleToken", - "hash": "49a58b950afdaf0728fdb7d4eb47cf4f2ec3077d655f274b7fdeb504c742f528", + "hash": "b63f10e00d1a814492822652dac7c0574428a200e4c26cb3c832c4829e2778f0", "aliases": { "emulator": "f8d6e0586b0a20c7", "mainnet": "1d7e57aa55817448", - "previewnet": "b6763b4399a888c8", "testnet": "631e88ae7f1d7c20" } }, @@ -231,7 +228,6 @@ "aliases": { "emulator": "f8d6e0586b0a20c7", "mainnet": "1d7e57aa55817448", - "previewnet": "b6763b4399a888c8", "testnet": "631e88ae7f1d7c20" } } @@ -239,7 +235,6 @@ "networks": { "emulator": "127.0.0.1:3569", "mainnet": "access.mainnet.nodes.onflow.org:9000", - "previewnet": "access.previewnet.nodes.onflow.org:9000", "sandboxnet": "access.sandboxnet.nodes.onflow.org:9000", "testing": "127.0.0.1:3569", "testnet": "access.devnet.nodes.onflow.org:9000"