Skip to content

Commit

Permalink
remove all conjunctions from function acess modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
austinkline committed May 7, 2024
1 parent 6b46b3b commit 8ae4eee
Show file tree
Hide file tree
Showing 20 changed files with 32 additions and 35 deletions.
5 changes: 2 additions & 3 deletions contracts/CapabilityDelegator.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ access(all) contract CapabilityDelegator {
access(all) let PublicPath: PublicPath

access(all) entitlement Get
access(all) entitlement Owner
access(all) entitlement Add
access(all) entitlement Delete

Expand Down Expand Up @@ -126,7 +125,7 @@ access(all) contract CapabilityDelegator {
/// @param cap: Capability to add
/// @param isPublic: Whether the Capability should be public or private
///
access(Owner | Add) fun addCapability(cap: Capability, isPublic: Bool) {
access(Add) fun addCapability(cap: Capability, isPublic: Bool) {
pre {
cap.check<&AnyResource>(): "Invalid Capability provided"
}
Expand All @@ -142,7 +141,7 @@ access(all) contract CapabilityDelegator {
///
/// @param cap: Capability to remove
///
access(Owner | Delete) fun removeCapability(cap: Capability) {
access(Delete) fun removeCapability(cap: Capability) {
if let removedPublic = self.publicCapabilities.remove(key: cap.getType()) {
emit DelegatorUpdated(id: self.uuid, capabilityType: cap.getType(), isPublic: true, active: false)
}
Expand Down
7 changes: 3 additions & 4 deletions contracts/CapabilityFactory.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ access(all) contract CapabilityFactory {
access(all) let StoragePath: StoragePath
access(all) let PublicPath: PublicPath

access(all) entitlement Owner
access(all) entitlement Add
access(all) entitlement Delete

Expand Down Expand Up @@ -64,7 +63,7 @@ access(all) contract CapabilityFactory {
/// @param t: Type of Capability the Factory retrieves
/// @param f: Factory to add
///
access(Owner | Add) fun addFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
access(Add) fun addFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
pre {
!self.factories.containsKey(t): "Factory of given type already exists"
}
Expand All @@ -76,15 +75,15 @@ access(all) contract CapabilityFactory {
/// @param t: Type of Capability the Factory retrieves
/// @param f: Factory to replace existing Factory
///
access(Owner | Add) fun updateFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
access(Add) fun updateFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
self.factories[t] = f
}

/// Removes a Factory from the Manager, returning it or nil if it didn't exist
///
/// @param t: Type the Factory is indexed on
///
access(Owner | Delete) fun removeFactory(_ t: Type): {CapabilityFactory.Factory}? {
access(Delete) fun removeFactory(_ t: Type): {CapabilityFactory.Factory}? {
return self.factories.remove(key: t)
}

Expand Down
13 changes: 6 additions & 7 deletions contracts/CapabilityFilter.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ access(all) contract CapabilityFilter {
access(all) let StoragePath: StoragePath
access(all) let PublicPath: PublicPath

access(all) entitlement Owner
access(all) entitlement Add
access(all) entitlement Delete

Expand Down Expand Up @@ -42,7 +41,7 @@ access(all) contract CapabilityFilter {
///
/// @param type: The type to add to the denied types mapping
///
access(Owner | Add) fun addType(_ type: Type) {
access(Add) fun addType(_ type: Type) {
self.deniedTypes.insert(key: type, true)
emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: true)
}
Expand All @@ -51,15 +50,15 @@ access(all) contract CapabilityFilter {
///
/// @param type: The type to remove from the denied types mapping
///
access(Owner | Delete) fun removeType(_ type: Type) {
access(Delete) fun removeType(_ type: Type) {
if let removed = self.deniedTypes.remove(key: type) {
emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: false)
}
}

/// Removes all types from the mapping of denied types
///
access(Owner | Delete) fun removeAllTypes() {
access(Delete) fun removeAllTypes() {
for type in self.deniedTypes.keys {
self.removeType(type)
}
Expand Down Expand Up @@ -109,7 +108,7 @@ access(all) contract CapabilityFilter {
///
/// @param type: The type to add to the allowed types mapping
///
access(Owner | Add) fun addType(_ type: Type) {
access(Add) fun addType(_ type: Type) {
self.allowedTypes.insert(key: type, true)
emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: true)
}
Expand All @@ -118,15 +117,15 @@ access(all) contract CapabilityFilter {
///
/// @param type: The type to remove from the denied types mapping
///
access(Owner | Delete) fun removeType(_ type: Type) {
access(Delete) fun removeType(_ type: Type) {
if let removed = self.allowedTypes.remove(key: type) {
emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: false)
}
}

/// Removes all types from the mapping of denied types
///
access(Owner | Delete) fun removeAllTypes() {
access(Delete) fun removeAllTypes() {
for type in self.allowedTypes.keys {
self.removeType(type)
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/HybridCustody.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -1124,9 +1124,9 @@ access(all) contract HybridCustody {

/// Retrieves a reference to the Delegator associated with the given parent account if one exists.
///
access(Owner) fun borrowCapabilityDelegatorForParent(parent: Address): auth(CapabilityDelegator.Owner) &CapabilityDelegator.Delegator? {
access(Owner) fun borrowCapabilityDelegatorForParent(parent: Address): auth(CapabilityDelegator.Get, CapabilityDelegator.Add, CapabilityDelegator.Delete) &CapabilityDelegator.Delegator? {
let identifier = HybridCustody.getCapabilityDelegatorIdentifier(parent)
return self.borrowAccount().storage.borrow<auth(CapabilityDelegator.Owner) &CapabilityDelegator.Delegator>(from: StoragePath(identifier: identifier)!)
return self.borrowAccount().storage.borrow<auth(CapabilityDelegator.Get, CapabilityDelegator.Add, CapabilityDelegator.Delete) &CapabilityDelegator.Delegator>(from: StoragePath(identifier: identifier)!)
}

/// Adds the provided Capability to the Delegator associated with the given parent account.
Expand Down
2 changes: 1 addition & 1 deletion scripts/test/add_type_for_nft_provider_factory.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "NFTProviderFactory"
import "NonFungibleToken"

access(all) fun main(address: Address, type: Type): Bool {
let managerRef = getAuthAccount<auth(Storage) &Account>(address).storage.borrow<auth(CapabilityFactory.Owner) &CapabilityFactory.Manager>(
let managerRef = getAuthAccount<auth(Storage) &Account>(address).storage.borrow<auth(CapabilityFactory.Add) &CapabilityFactory.Manager>(
from: CapabilityFactory.StoragePath
) ?? panic("CapabilityFactory Manager not found")

Expand Down
2 changes: 1 addition & 1 deletion scripts/test/remove_nft_provider_factory.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "NonFungibleToken"

access(all) fun main(address: Address): Bool {

let managerRef = getAuthAccount<auth(Storage) &Account>(address).storage.borrow<auth(CapabilityFactory.Owner) &CapabilityFactory.Manager>(from: CapabilityFactory.StoragePath)
let managerRef = getAuthAccount<auth(Storage) &Account>(address).storage.borrow<auth(CapabilityFactory.Delete) &CapabilityFactory.Manager>(from: CapabilityFactory.StoragePath)
?? panic("CapabilityFactory Manager not found")

let expectedType = Type<NFTProviderFactory.Factory>()
Expand Down
2 changes: 1 addition & 1 deletion scripts/test/update_nft_provider_factory.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "NFTProviderFactory"
import "NonFungibleToken"

access(all) fun main(address: Address) {
let managerRef = getAuthAccount<auth(Storage) &Account>(address).storage.borrow<auth(CapabilityFactory.Owner) &CapabilityFactory.Manager>(from: CapabilityFactory.StoragePath)
let managerRef = getAuthAccount<auth(Storage) &Account>(address).storage.borrow<auth(CapabilityFactory.Add) &CapabilityFactory.Manager>(from: CapabilityFactory.StoragePath)
?? panic("CapabilityFactory Manager not found")

let nftProviderFactory = NFTProviderFactory.Factory()
Expand Down
2 changes: 1 addition & 1 deletion transactions/delegator/add_private_nft_collection.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "ExampleNFT"

transaction {
prepare(acct: auth(BorrowValue, Capabilities) &Account) {
let delegator = acct.storage.borrow<auth(CapabilityDelegator.Owner) &CapabilityDelegator.Delegator>(from: CapabilityDelegator.StoragePath)
let delegator = acct.storage.borrow<auth(CapabilityDelegator.Add) &CapabilityDelegator.Delegator>(from: CapabilityDelegator.StoragePath)
?? panic("delegator not found")

let d = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>())! as! MetadataViews.NFTCollectionData
Expand Down
4 changes: 2 additions & 2 deletions transactions/delegator/add_public_nft_collection.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import "ExampleNFT"

transaction {
prepare(acct: auth(BorrowValue) &Account) {
let delegator = acct.storage.borrow<auth(CapabilityDelegator.Owner) &CapabilityDelegator.Delegator>(from: CapabilityDelegator.StoragePath)
let delegator = acct.storage.borrow<auth(CapabilityDelegator.Add) &CapabilityDelegator.Delegator>(from: CapabilityDelegator.StoragePath)
?? panic("delegator not found")

let sharedCap
= acct.capabilities.get<&{ExampleNFT.ExampleNFTCollectionPublic, NonFungibleToken.CollectionPublic}>(ExampleNFT.CollectionPublicPath)!
= acct.capabilities.get<&{ExampleNFT.ExampleNFTCollectionPublic, NonFungibleToken.CollectionPublic}>(ExampleNFT.CollectionPublicPath)
delegator.addCapability(cap: sharedCap, isPublic: true)
}
}
2 changes: 1 addition & 1 deletion transactions/delegator/remove_private_nft_collection.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "ExampleNFT"

transaction {
prepare(acct: auth(BorrowValue, Capabilities) &Account) {
let delegator = acct.storage.borrow<auth(CapabilityDelegator.Owner) &CapabilityDelegator.Delegator>(from: CapabilityDelegator.StoragePath)
let delegator = acct.storage.borrow<auth(CapabilityDelegator.Delete) &CapabilityDelegator.Delegator>(from: CapabilityDelegator.StoragePath)
?? panic("delegator not found")

let d = ExampleNFT.resolveContractView(resourceType: nil, viewType: Type<MetadataViews.NFTCollectionData>())! as! MetadataViews.NFTCollectionData
Expand Down
4 changes: 2 additions & 2 deletions transactions/delegator/remove_public_nft_collection.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import "ExampleNFT"

transaction {
prepare(acct: auth(BorrowValue, Capabilities) &Account) {
let delegator = acct.storage.borrow<auth(CapabilityDelegator.Owner) &CapabilityDelegator.Delegator>(from: CapabilityDelegator.StoragePath)
let delegator = acct.storage.borrow<auth(CapabilityDelegator.Delete) &CapabilityDelegator.Delegator>(from: CapabilityDelegator.StoragePath)
?? panic("delegator not found")

let sharedCap
= acct.capabilities.get<&{ExampleNFT.ExampleNFTCollectionPublic, NonFungibleToken.CollectionPublic}>(ExampleNFT.CollectionPublicPath)!
= acct.capabilities.get<&{ExampleNFT.ExampleNFTCollectionPublic, NonFungibleToken.CollectionPublic}>(ExampleNFT.CollectionPublicPath)
delegator.removeCapability(cap: sharedCap)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ transaction(nftContractAddress: Address, nftContractName: String) {
message: "CapabilityFactory is not setup properly"
)

let factoryManager = acct.storage.borrow<auth(CapabilityFactory.Owner) &CapabilityFactory.Manager>(from: CapabilityFactory.StoragePath)
let factoryManager = acct.storage.borrow<auth(CapabilityFactory.Add) &CapabilityFactory.Manager>(from: CapabilityFactory.StoragePath)
?? panic("CapabilityFactory Manager not found")

// Add NFT-related Factories to the Manager
Expand Down Expand Up @@ -95,7 +95,7 @@ transaction(nftContractAddress: Address, nftContractName: String) {
message: "AllowlistFilter is not setup properly"
)

let filter = acct.storage.borrow<auth(CapabilityFilter.Owner) &CapabilityFilter.AllowlistFilter>(from: CapabilityFilter.StoragePath)
let filter = acct.storage.borrow<auth(CapabilityFilter.Add) &CapabilityFilter.AllowlistFilter>(from: CapabilityFilter.StoragePath)
?? panic("AllowlistFilter does not exist")

// Construct an NFT Collection Type from the provided args & add to the AllowlistFilter
Expand Down
2 changes: 1 addition & 1 deletion transactions/factory/setup_ft_manager.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ transaction {
message: "CapabilityFactory is not setup properly"
)

let manager = acct.storage.borrow<auth(CapabilityFactory.Owner) &CapabilityFactory.Manager>(from: CapabilityFactory.StoragePath)
let manager = acct.storage.borrow<auth(CapabilityFactory.Add) &CapabilityFactory.Manager>(from: CapabilityFactory.StoragePath)
?? panic("manager not found")

manager.updateFactory(Type<auth(FungibleToken.Withdraw) &{FungibleToken.Provider}>(), FTProviderFactory.Factory())
Expand Down
2 changes: 1 addition & 1 deletion transactions/factory/setup_nft_ft_manager.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ transaction {
message: "CapabilityFactory is not setup properly"
)

let manager = acct.storage.borrow<auth(CapabilityFactory.Owner) &CapabilityFactory.Manager>(from: CapabilityFactory.StoragePath) ?? panic("manager not found")
let manager = acct.storage.borrow<auth(CapabilityFactory.Add) &CapabilityFactory.Manager>(from: CapabilityFactory.StoragePath) ?? panic("manager not found")

manager.updateFactory(Type<&{NonFungibleToken.CollectionPublic}>(), NFTCollectionPublicFactory.Factory())
manager.updateFactory(Type<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(), NFTProviderAndCollectionFactory.Factory())
Expand Down
2 changes: 1 addition & 1 deletion transactions/factory/setup_nft_manager.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ transaction {
message: "CapabilityFactory is not setup properly"
)

let manager = acct.storage.borrow<auth(CapabilityFactory.Owner) &CapabilityFactory.Manager>(from: CapabilityFactory.StoragePath)
let manager = acct.storage.borrow<auth(CapabilityFactory.Add) &CapabilityFactory.Manager>(from: CapabilityFactory.StoragePath)
?? panic("manager not found")

manager.updateFactory(Type<&{NonFungibleToken.CollectionPublic}>(), NFTCollectionPublicFactory.Factory())
Expand Down
2 changes: 1 addition & 1 deletion transactions/filter/allow/add_type_to_list.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "CapabilityFilter"

transaction(identifier: String) {
prepare(acct: auth(Storage) &Account) {
let filter = acct.storage.borrow<auth(CapabilityFilter.Owner) &CapabilityFilter.AllowlistFilter>(from: CapabilityFilter.StoragePath)
let filter = acct.storage.borrow<auth(CapabilityFilter.Add) &CapabilityFilter.AllowlistFilter>(from: CapabilityFilter.StoragePath)
?? panic("filter does not exist")

let c = CompositeType(identifier)!
Expand Down
2 changes: 1 addition & 1 deletion transactions/filter/allow/remove_all_types.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "CapabilityFilter"

transaction() {
prepare(acct: auth(Storage) &Account) {
let filter = acct.storage.borrow<auth(CapabilityFilter.Owner) &CapabilityFilter.AllowlistFilter>(from: CapabilityFilter.StoragePath)
let filter = acct.storage.borrow<auth(CapabilityFilter.Delete) &CapabilityFilter.AllowlistFilter>(from: CapabilityFilter.StoragePath)
?? panic("filter does not exist")

filter.removeAllTypes()
Expand Down
2 changes: 1 addition & 1 deletion transactions/filter/deny/add_type_to_list.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "CapabilityFilter"

transaction(identifier: String) {
prepare(acct: auth(Storage) &Account) {
let filter = acct.storage.borrow<auth(CapabilityFilter.Owner) &CapabilityFilter.DenylistFilter>(from: CapabilityFilter.StoragePath)
let filter = acct.storage.borrow<auth(CapabilityFilter.Add) &CapabilityFilter.DenylistFilter>(from: CapabilityFilter.StoragePath)
?? panic("filter does not exist")

let c = CompositeType(identifier)!
Expand Down
2 changes: 1 addition & 1 deletion transactions/filter/deny/remove_all_types.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "CapabilityFilter"

transaction() {
prepare(acct: auth(Storage) &Account) {
let filter = acct.storage.borrow<auth(CapabilityFilter.Owner) &CapabilityFilter.DenylistFilter>(from: CapabilityFilter.StoragePath)
let filter = acct.storage.borrow<auth(CapabilityFilter.Delete) &CapabilityFilter.DenylistFilter>(from: CapabilityFilter.StoragePath)
?? panic("filter does not exist")

filter.removeAllTypes()
Expand Down
2 changes: 1 addition & 1 deletion transactions/test/add_type_for_nft_provider_factory.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "NonFungibleToken"

transaction(type: Type) {
prepare(account: auth(Storage) &Account) {
let managerRef = account.storage.borrow<auth(CapabilityFactory.Owner) &CapabilityFactory.Manager>(
let managerRef = account.storage.borrow<auth(CapabilityFactory.Add) &CapabilityFactory.Manager>(
from: CapabilityFactory.StoragePath
) ?? panic("CapabilityFactory Manager not found")

Expand Down

0 comments on commit 8ae4eee

Please sign in to comment.