From 2b229352231eb7cc1f944f9704605c1ebf7be945 Mon Sep 17 00:00:00 2001 From: Austin Kline Date: Wed, 24 Apr 2024 09:29:43 -0700 Subject: [PATCH] correct entitlements for NFT.Withdraw because migrations also need the Owner entitlement --- contracts/factories/NFTCollectionFactory.cdc | 4 ++-- .../NFTProviderAndCollectionFactory.cdc | 4 ++-- contracts/factories/NFTProviderFactory.cdc | 4 ++-- scripts/delegator/find_nft_provider_cap.cdc | 2 +- scripts/delegator/get_all_private_caps.cdc | 2 +- scripts/delegator/get_nft_provider.cdc | 4 ++-- .../factory/get_nft_provider_from_factory.cdc | 4 ++-- .../get_nft_provider_from_factory_allowed.cdc | 6 +++--- .../get_child_account_nft_capabilities.cdc | 4 ++-- .../get_nft_provider_capability.cdc | 2 +- .../get_nft_provider_capability_optional.cdc | 2 +- scripts/test/remove_nft_provider_factory.cdc | 2 +- .../test/test_get_accessible_child_nfts.cdc | 2 +- test/CapabilityDelegator_tests.cdc | 4 ++-- test/CapabilityFactory_tests.cdc | 18 +++++++++--------- .../delegator/add_private_nft_collection.cdc | 2 +- .../remove_private_nft_collection.cdc | 2 +- .../setup_nft_filter_and_factory_manager.cdc | 4 ++-- transactions/example-nft-2/setup_full.cdc | 2 +- transactions/example-nft/setup_full.cdc | 2 +- transactions/factory/setup_nft_ft_manager.cdc | 4 ++-- transactions/factory/setup_nft_manager.cdc | 4 ++-- ...dd_example_nft2_collection_to_delegator.cdc | 2 +- 23 files changed, 43 insertions(+), 43 deletions(-) diff --git a/contracts/factories/NFTCollectionFactory.cdc b/contracts/factories/NFTCollectionFactory.cdc index 9508c23..5b006bf 100644 --- a/contracts/factories/NFTCollectionFactory.cdc +++ b/contracts/factories/NFTCollectionFactory.cdc @@ -5,11 +5,11 @@ access(all) contract NFTProviderAndCollectionFactory { access(all) struct WithdrawFactory: CapabilityFactory.Factory { access(all) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability? { if let con = acct.capabilities.storage.getController(byCapabilityID: controllerID) { - if !con.capability.check() { + if !con.capability.check() { return nil } - return con.capability as! Capability + return con.capability as! Capability } return nil diff --git a/contracts/factories/NFTProviderAndCollectionFactory.cdc b/contracts/factories/NFTProviderAndCollectionFactory.cdc index ebeb4e4..cf02cf2 100644 --- a/contracts/factories/NFTProviderAndCollectionFactory.cdc +++ b/contracts/factories/NFTProviderAndCollectionFactory.cdc @@ -5,11 +5,11 @@ access(all) contract NFTProviderAndCollectionFactory { access(all) struct Factory: CapabilityFactory.Factory { access(all) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability? { if let con = acct.capabilities.storage.getController(byCapabilityID: controllerID) { - if !con.capability.check() { + if !con.capability.check() { return nil } - return con.capability as! Capability + return con.capability as! Capability } return nil diff --git a/contracts/factories/NFTProviderFactory.cdc b/contracts/factories/NFTProviderFactory.cdc index a2214dc..fcb8486 100644 --- a/contracts/factories/NFTProviderFactory.cdc +++ b/contracts/factories/NFTProviderFactory.cdc @@ -5,11 +5,11 @@ access(all) contract NFTProviderFactory { access(all) struct Factory: CapabilityFactory.Factory { access(all) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability? { if let con = acct.capabilities.storage.getController(byCapabilityID: controllerID) { - if !con.capability.check() { + if !con.capability.check() { return nil } - return con.capability as! Capability + return con.capability as! Capability } return nil diff --git a/scripts/delegator/find_nft_provider_cap.cdc b/scripts/delegator/find_nft_provider_cap.cdc index 2916183..5a60b9e 100644 --- a/scripts/delegator/find_nft_provider_cap.cdc +++ b/scripts/delegator/find_nft_provider_cap.cdc @@ -10,7 +10,7 @@ access(all) fun main(addr: Address): Bool { acct.capabilities.storage.issue(CapabilityDelegator.StoragePath).borrow() ?? panic("could not borrow delegator") - let desiredType = Type>() + let desiredType = Type>() let foundType = delegator.findFirstPrivateType(desiredType) ?? panic("no type found") let nakedCap = delegator.getPrivateCapability(foundType) ?? panic("requested capability type was not found") diff --git a/scripts/delegator/get_all_private_caps.cdc b/scripts/delegator/get_all_private_caps.cdc index 8c0b48c..12ab8ee 100644 --- a/scripts/delegator/get_all_private_caps.cdc +++ b/scripts/delegator/get_all_private_caps.cdc @@ -9,7 +9,7 @@ access(all) fun main(address: Address): Bool { ?.getAllPrivate() ?? panic("could not borrow delegator") - let desiredType: Type = Type>() + let desiredType: Type = Type>() return privateCaps.length == 1 && privateCaps[0].getType() == desiredType } \ No newline at end of file diff --git a/scripts/delegator/get_nft_provider.cdc b/scripts/delegator/get_nft_provider.cdc index 0753b65..ab4bbd0 100644 --- a/scripts/delegator/get_nft_provider.cdc +++ b/scripts/delegator/get_nft_provider.cdc @@ -10,12 +10,12 @@ access(all) fun main(addr: Address): Bool { acct.capabilities.storage.issue(CapabilityDelegator.StoragePath).borrow() ?? panic("could not borrow delegator") - let capType = Type>() + let capType = Type>() let nakedCap = delegator.getPrivateCapability(capType) ?? panic("requested capability type was not found") // we don't need to do anything with this cap, being able to cast here is enough to know // that this works - let cap = nakedCap as! Capability + let cap = nakedCap as! Capability return true } \ No newline at end of file diff --git a/scripts/factory/get_nft_provider_from_factory.cdc b/scripts/factory/get_nft_provider_from_factory.cdc index c49019c..794037a 100644 --- a/scripts/factory/get_nft_provider_from_factory.cdc +++ b/scripts/factory/get_nft_provider_from_factory.cdc @@ -13,8 +13,8 @@ access(all) fun main(addr: Address) { let controllers = acct.capabilities.storage.getControllers(forPath: d.storagePath) for c in controllers { - if c.borrowType.isSubtype(of: Type()) { - factory.getCapability(acct: acct, controllerID: c.capabilityID)! as! Capability + if c.borrowType.isSubtype(of: Type()) { + factory.getCapability(acct: acct, controllerID: c.capabilityID)! as! Capability return } } diff --git a/scripts/factory/get_nft_provider_from_factory_allowed.cdc b/scripts/factory/get_nft_provider_from_factory_allowed.cdc index 4c963da..7b8e646 100644 --- a/scripts/factory/get_nft_provider_from_factory_allowed.cdc +++ b/scripts/factory/get_nft_provider_from_factory_allowed.cdc @@ -15,14 +15,14 @@ access(all) fun main(filterFactoryAddr: Address, providerAddr: Address): Bool { let factoryManager = ruleAcct.storage.borrow<&CapabilityFactory.Manager>(from: CapabilityFactory.StoragePath) ?? panic("Problem borrowing CapabilityFactory Manager") - let factory = factoryManager.getFactory(Type()) + let factory = factoryManager.getFactory(Type()) ?? panic("No factory for NFT Provider found") let d = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type())! as! MetadataViews.NFTCollectionData var controllerID: UInt64? = nil for c in providerAcct.capabilities.storage.getControllers(forPath: d.storagePath) { - if c.borrowType.isSubtype(of: Type()) { + if c.borrowType.isSubtype(of: Type()) { controllerID = c.capabilityID break } @@ -30,7 +30,7 @@ access(all) fun main(filterFactoryAddr: Address, providerAddr: Address): Bool { assert(controllerID != nil, message: "could not find existing provider capcon") - let provider = factory.getCapability(acct: providerAcct, controllerID: controllerID!)! as! Capability + let provider = factory.getCapability(acct: providerAcct, controllerID: controllerID!)! as! Capability let filter = ruleAcct.storage.borrow<&CapabilityFilter.AllowlistFilter>(from: CapabilityFilter.StoragePath) ?? panic("Problem borrowing CapabilityFilter AllowlistFilter") diff --git a/scripts/hybrid-custody/get_child_account_nft_capabilities.cdc b/scripts/hybrid-custody/get_child_account_nft_capabilities.cdc index 85978f4..0f76545 100644 --- a/scripts/hybrid-custody/get_child_account_nft_capabilities.cdc +++ b/scripts/hybrid-custody/get_child_account_nft_capabilities.cdc @@ -9,7 +9,7 @@ access(all) fun main(addr: Address): AnyStruct { var typeIdsWithProvider: {Address: [String]} = {} - let providerType = Type() + let providerType = Type() // Iterate through child accounts for address in manager.getChildAddresses() { @@ -26,7 +26,7 @@ access(all) fun main(addr: Address): AnyStruct { } if let cap = childAcct.getCapability(controllerID: c.capabilityID, type: providerType) { - let providerCap = cap as! Capability + let providerCap = cap as! Capability if !providerCap.check(){ continue diff --git a/scripts/hybrid-custody/get_nft_provider_capability.cdc b/scripts/hybrid-custody/get_nft_provider_capability.cdc index d80c390..6ab97b6 100644 --- a/scripts/hybrid-custody/get_nft_provider_capability.cdc +++ b/scripts/hybrid-custody/get_nft_provider_capability.cdc @@ -14,7 +14,7 @@ access(all) fun main(parent: Address, child: Address) { let d = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type())! as! MetadataViews.NFTCollectionData - let desiredType = Type() + let desiredType = Type() let controllerID = childAcct.getControllerIDForType(type: desiredType, forPath: d.storagePath) ?? panic("no capability found for desired type") diff --git a/scripts/test/get_nft_provider_capability_optional.cdc b/scripts/test/get_nft_provider_capability_optional.cdc index 635cb9d..065258c 100644 --- a/scripts/test/get_nft_provider_capability_optional.cdc +++ b/scripts/test/get_nft_provider_capability_optional.cdc @@ -14,7 +14,7 @@ access(all) fun main(parent: Address, child: Address, returnsNil: Bool): Bool { let collectionData = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type())! as! MetadataViews.NFTCollectionData - let type = Type() + let type = Type() let controllerID = childAcct.getControllerIDForType(type: type, forPath: collectionData.storagePath) ?? panic("could not find controller for desired type") diff --git a/scripts/test/remove_nft_provider_factory.cdc b/scripts/test/remove_nft_provider_factory.cdc index 566b778..92537d1 100644 --- a/scripts/test/remove_nft_provider_factory.cdc +++ b/scripts/test/remove_nft_provider_factory.cdc @@ -10,7 +10,7 @@ access(all) fun main(address: Address): Bool { let expectedType = Type() - if let removed = managerRef.removeFactory(Type()) { + if let removed = managerRef.removeFactory(Type()) { return removed.getType() == expectedType } diff --git a/scripts/test/test_get_accessible_child_nfts.cdc b/scripts/test/test_get_accessible_child_nfts.cdc index 587dc6b..54f3043 100644 --- a/scripts/test/test_get_accessible_child_nfts.cdc +++ b/scripts/test/test_get_accessible_child_nfts.cdc @@ -29,7 +29,7 @@ access(all) fun main(addr: Address, expectedAddressToIDs: {Address: [UInt64]}){ var typeIdsWithProvider: {Address: [String]} = {} var nftViews: {Address: {UInt64: MetadataViews.Display}} = {} - let providerType = Type() + let providerType = Type() let collectionType: Type = Type<@{NonFungibleToken.CollectionPublic}>() for address in manager.getChildAddresses() { diff --git a/test/CapabilityDelegator_tests.cdc b/test/CapabilityDelegator_tests.cdc index 0fd099e..1c481d3 100644 --- a/test/CapabilityDelegator_tests.cdc +++ b/test/CapabilityDelegator_tests.cdc @@ -60,7 +60,7 @@ fun testShareExampleNFTCollectionPrivate() { Test.assert(e.isPublic == false) Test.assert(e.active) - let capabilityType = Type>() + let capabilityType = Type>() Test.assertEqual(capabilityType, e.capabilityType) } @@ -101,7 +101,7 @@ fun testRemoveExampleNFTCollectionPrivate() { Test.assert(e.isPublic == false) Test.assert(e.active == false) - let capabilityType = Type>() + let capabilityType = Type>() Test.assertEqual(capabilityType, e.capabilityType) let scriptCode = loadCode("delegator/find_nft_provider_cap.cdc", "scripts") diff --git a/test/CapabilityFactory_tests.cdc b/test/CapabilityFactory_tests.cdc index 2180c30..4227078 100644 --- a/test/CapabilityFactory_tests.cdc +++ b/test/CapabilityFactory_tests.cdc @@ -38,9 +38,9 @@ fun testGetSupportedTypesFromManager() { Type<&{FungibleToken.Receiver}>(), Type<&{FungibleToken.Receiver, FungibleToken.Balance}>(), Type(), - Type(), + Type(), Type<&{NonFungibleToken.CollectionPublic}>(), - Type() + Type() ] for e in expectedTypes { Test.assert(supportedTypes.contains(e), message: "missing expected type in supported types") @@ -51,7 +51,7 @@ access(all) fun testAddFactoryFails() { expectScriptFailure( "test/add_type_for_nft_provider_factory.cdc", - [creator.address, Type()], + [creator.address, Type()], "Factory of given type already exists" ) } @@ -71,9 +71,9 @@ fun testAddFactorySucceeds() { Type<&{FungibleToken.Receiver}>(), Type<&{FungibleToken.Receiver, FungibleToken.Balance}>(), Type(), - Type(), + Type(), Type<&{NonFungibleToken.CollectionPublic}>(), - Type(), + Type(), Type<&{NonFungibleToken.Receiver}>() ] @@ -121,9 +121,9 @@ fun testSetupNFTManager() { let supportedTypes = scriptExecutor("factory/get_supported_types_from_manager.cdc", [tmp.address])! as! [Type] let expectedTypes = [ - Type(), + Type(), Type<&{NonFungibleToken.CollectionPublic}>(), - Type() + Type() ] for e in expectedTypes { @@ -180,9 +180,9 @@ fun testSetupNFTFTManager() { Type<&{FungibleToken.Receiver}>(), Type<&{FungibleToken.Receiver, FungibleToken.Balance}>(), Type(), - Type(), + Type(), Type<&{NonFungibleToken.CollectionPublic}>(), - Type() + Type() ] for e in expectedTypes { diff --git a/transactions/delegator/add_private_nft_collection.cdc b/transactions/delegator/add_private_nft_collection.cdc index e24a49c..e023565 100644 --- a/transactions/delegator/add_private_nft_collection.cdc +++ b/transactions/delegator/add_private_nft_collection.cdc @@ -11,7 +11,7 @@ transaction { let d = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type())! as! MetadataViews.NFTCollectionData - let sharedCap = acct.capabilities.storage.issue(d.storagePath) + let sharedCap = acct.capabilities.storage.issue(d.storagePath) delegator.addCapability(cap: sharedCap, isPublic: false) } diff --git a/transactions/delegator/remove_private_nft_collection.cdc b/transactions/delegator/remove_private_nft_collection.cdc index 82d2ada..6eb0924 100644 --- a/transactions/delegator/remove_private_nft_collection.cdc +++ b/transactions/delegator/remove_private_nft_collection.cdc @@ -11,7 +11,7 @@ transaction { let d = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type())! as! MetadataViews.NFTCollectionData - let sharedCap = acct.capabilities.storage.issue(d.storagePath) + let sharedCap = acct.capabilities.storage.issue(d.storagePath) delegator.removeCapability(cap: sharedCap) diff --git a/transactions/dev-setup/setup_nft_filter_and_factory_manager.cdc b/transactions/dev-setup/setup_nft_filter_and_factory_manager.cdc index 92acfc4..23035d6 100644 --- a/transactions/dev-setup/setup_nft_filter_and_factory_manager.cdc +++ b/transactions/dev-setup/setup_nft_filter_and_factory_manager.cdc @@ -72,8 +72,8 @@ transaction(nftContractAddress: Address, nftContractName: String) { // Add NFT-related Factories to the Manager factoryManager.updateFactory(Type<&{NonFungibleToken.CollectionPublic}>(), NFTCollectionPublicFactory.Factory()) - factoryManager.updateFactory(Type(), NFTProviderAndCollectionFactory.Factory()) - factoryManager.updateFactory(Type(), NFTProviderFactory.Factory()) + factoryManager.updateFactory(Type(), NFTProviderAndCollectionFactory.Factory()) + factoryManager.updateFactory(Type(), NFTProviderFactory.Factory()) /* --- AllowlistFilter configuration --- */ // diff --git a/transactions/example-nft-2/setup_full.cdc b/transactions/example-nft-2/setup_full.cdc index b72b7a1..16049f1 100644 --- a/transactions/example-nft-2/setup_full.cdc +++ b/transactions/example-nft-2/setup_full.cdc @@ -17,6 +17,6 @@ transaction { at: d.publicPath ) - acct.capabilities.storage.issue(d.storagePath) + acct.capabilities.storage.issue(d.storagePath) } } diff --git a/transactions/example-nft/setup_full.cdc b/transactions/example-nft/setup_full.cdc index c20ad67..550e50a 100644 --- a/transactions/example-nft/setup_full.cdc +++ b/transactions/example-nft/setup_full.cdc @@ -15,6 +15,6 @@ transaction { let cap = acct.capabilities.storage.issue<&{ExampleNFT.ExampleNFTCollectionPublic, NonFungibleToken.CollectionPublic}>(d.storagePath) acct.capabilities.publish(cap, at: d.publicPath) - acct.capabilities.storage.issue(d.storagePath) + acct.capabilities.storage.issue(d.storagePath) } } diff --git a/transactions/factory/setup_nft_ft_manager.cdc b/transactions/factory/setup_nft_ft_manager.cdc index 8a53858..976eb87 100644 --- a/transactions/factory/setup_nft_ft_manager.cdc +++ b/transactions/factory/setup_nft_ft_manager.cdc @@ -33,8 +33,8 @@ transaction { let manager = acct.storage.borrow(from: CapabilityFactory.StoragePath) ?? panic("manager not found") manager.updateFactory(Type<&{NonFungibleToken.CollectionPublic}>(), NFTCollectionPublicFactory.Factory()) - manager.updateFactory(Type(), NFTProviderAndCollectionFactory.Factory()) - manager.updateFactory(Type(), NFTProviderFactory.Factory()) + manager.updateFactory(Type(), NFTProviderAndCollectionFactory.Factory()) + manager.updateFactory(Type(), NFTProviderFactory.Factory()) manager.updateFactory(Type(), FTProviderFactory.Factory()) manager.updateFactory(Type<&{FungibleToken.Balance}>(), FTBalanceFactory.Factory()) manager.updateFactory(Type<&{FungibleToken.Receiver}>(), FTReceiverFactory.Factory()) diff --git a/transactions/factory/setup_nft_manager.cdc b/transactions/factory/setup_nft_manager.cdc index 2c3526d..fb1ba73 100644 --- a/transactions/factory/setup_nft_manager.cdc +++ b/transactions/factory/setup_nft_manager.cdc @@ -28,7 +28,7 @@ transaction { ?? panic("manager not found") manager.updateFactory(Type<&{NonFungibleToken.CollectionPublic}>(), NFTCollectionPublicFactory.Factory()) - manager.updateFactory(Type(), NFTProviderAndCollectionFactory.Factory()) - manager.updateFactory(Type(), NFTProviderFactory.Factory()) + manager.updateFactory(Type(), NFTProviderAndCollectionFactory.Factory()) + manager.updateFactory(Type(), NFTProviderFactory.Factory()) } } diff --git a/transactions/hybrid-custody/add_example_nft2_collection_to_delegator.cdc b/transactions/hybrid-custody/add_example_nft2_collection_to_delegator.cdc index 558091c..ce420e3 100644 --- a/transactions/hybrid-custody/add_example_nft2_collection_to_delegator.cdc +++ b/transactions/hybrid-custody/add_example_nft2_collection_to_delegator.cdc @@ -11,7 +11,7 @@ transaction(parent: Address, isPublic: Bool) { let child = o.borrowChildAccount(parent: parent) ?? panic("child account not found") - let cap = acct.capabilities.storage.issue(ExampleNFT2.CollectionStoragePath) + let cap = acct.capabilities.storage.issue(ExampleNFT2.CollectionStoragePath) o.addCapabilityToDelegator(parent: parent, cap: cap, isPublic: isPublic) } } \ No newline at end of file