@flowtyio/flow-contracts 0.1.0-beta.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/contracts/FungibleTokenSwitchboard.cdc +360 -0
- package/contracts/MetadataViews.cdc +79 -6
- package/contracts/NonFungibleToken.cdc +17 -10
- package/contracts/TokenForwarding.cdc +19 -11
- package/contracts/capability-cache/CapabilityCache.cdc +97 -0
- package/contracts/dapper/TopShot.cdc +323 -259
- package/contracts/dapper/TopShotLocking.cdc +41 -15
- package/contracts/dapper/offers/DapperOffersV2.cdc +46 -43
- package/contracts/dapper/offers/OffersV2.cdc +40 -56
- package/contracts/dapper/offers/Resolver.cdc +20 -13
- package/contracts/emerald-city/FLOAT.cdc +259 -254
- package/contracts/example/ExampleNFT.cdc +2 -2
- package/contracts/find/FindViews.cdc +357 -353
- package/contracts/flow-utils/ScopedFTProviders.cdc +5 -2
- package/contracts/flow-utils/ScopedNFTProviders.cdc +6 -2
- package/contracts/flowty-drops/ContractManager.cdc +73 -0
- package/contracts/flowty-drops/DropFactory.cdc +75 -0
- package/contracts/flowty-drops/DropTypes.cdc +282 -0
- package/contracts/flowty-drops/FlowtyActiveCheckers.cdc +113 -0
- package/contracts/flowty-drops/FlowtyAddressVerifiers.cdc +64 -0
- package/contracts/flowty-drops/FlowtyDrops.cdc +461 -0
- package/contracts/flowty-drops/FlowtyPricers.cdc +48 -0
- package/contracts/flowty-drops/initializers/ContractBorrower.cdc +14 -0
- package/contracts/flowty-drops/initializers/ContractInitializer.cdc +7 -0
- package/contracts/flowty-drops/initializers/OpenEditionInitializer.cdc +57 -0
- package/contracts/flowty-drops/nft/BaseCollection.cdc +97 -0
- package/contracts/flowty-drops/nft/BaseNFT.cdc +107 -0
- package/contracts/flowty-drops/nft/ContractFactory.cdc +13 -0
- package/contracts/flowty-drops/nft/ContractFactoryTemplate.cdc +48 -0
- package/contracts/flowty-drops/nft/NFTMetadata.cdc +140 -0
- package/contracts/flowty-drops/nft/OpenEditionNFT.cdc +42 -0
- package/contracts/flowty-drops/nft/OpenEditionTemplate.cdc +54 -0
- package/contracts/flowty-drops/nft/UniversalCollection.cdc +29 -0
- package/contracts/fungible-token-router/FungibleTokenRouter.cdc +103 -0
- package/contracts/hybrid-custody/CapabilityDelegator.cdc +28 -26
- package/contracts/hybrid-custody/CapabilityFactory.cdc +20 -18
- package/contracts/hybrid-custody/CapabilityFilter.cdc +41 -24
- package/contracts/hybrid-custody/HybridCustody.cdc +303 -242
- package/contracts/hybrid-custody/factories/FTAllFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/FTBalanceFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/FTProviderFactory.cdc +17 -5
- package/contracts/hybrid-custody/factories/FTReceiverBalanceFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/FTReceiverFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/FTVaultFactory.cdc +46 -0
- package/contracts/hybrid-custody/factories/NFTCollectionFactory.cdc +45 -0
- package/contracts/hybrid-custody/factories/NFTCollectionPublicFactory.cdc +16 -4
- package/contracts/hybrid-custody/factories/NFTProviderAndCollectionFactory.cdc +22 -0
- package/contracts/hybrid-custody/factories/NFTProviderFactory.cdc +16 -4
- package/contracts/lost-and-found/LostAndFound.cdc +21 -17
- package/flow.json +181 -7
- package/package.json +1 -1
- package/contracts/hybrid-custody/factories/NFTProviderAndCollectionPublicFactory.cdc +0 -10
|
@@ -7,48 +7,51 @@
|
|
|
7
7
|
/// private `Delegator` can only be borrowed from the child account when you have access to the full `ChildAccount`
|
|
8
8
|
/// resource.
|
|
9
9
|
///
|
|
10
|
-
|
|
10
|
+
access(all) contract CapabilityDelegator {
|
|
11
11
|
|
|
12
12
|
/* --- Canonical Paths --- */
|
|
13
13
|
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
access(all) let StoragePath: StoragePath
|
|
15
|
+
access(all) let PublicPath: PublicPath
|
|
16
|
+
|
|
17
|
+
access(all) entitlement Get
|
|
18
|
+
access(all) entitlement Add
|
|
19
|
+
access(all) entitlement Delete
|
|
17
20
|
|
|
18
21
|
/* --- Events --- */
|
|
19
22
|
//
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
access(all) event DelegatorCreated(id: UInt64)
|
|
24
|
+
access(all) event DelegatorUpdated(id: UInt64, capabilityType: Type, isPublic: Bool, active: Bool)
|
|
22
25
|
|
|
23
26
|
/// Private interface for Capability retrieval
|
|
24
27
|
///
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
access(all) resource interface GetterPrivate {
|
|
29
|
+
access(Get) view fun getPrivateCapability(_ type: Type): Capability? {
|
|
27
30
|
post {
|
|
28
31
|
result == nil || type.isSubtype(of: result.getType()): "incorrect returned capability type"
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
access(all) view fun findFirstPrivateType(_ type: Type): Type?
|
|
35
|
+
access(Get) fun getAllPrivate(): [Capability]
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
/// Exposes public Capability retrieval
|
|
36
39
|
///
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
access(all) resource interface GetterPublic {
|
|
41
|
+
access(all) view fun getPublicCapability(_ type: Type): Capability? {
|
|
39
42
|
post {
|
|
40
|
-
result == nil || type.isSubtype(of: result.getType()): "incorrect returned capability type
|
|
43
|
+
result == nil || type.isSubtype(of: result.getType()): "incorrect returned capability type"
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
access(all) view fun findFirstPublicType(_ type: Type): Type?
|
|
48
|
+
access(all) view fun getAllPublic(): [Capability]
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
/// This Delegator is used to store Capabilities, partitioned by public and private access with corresponding
|
|
49
52
|
/// GetterPublic and GetterPrivate conformances.AccountCapabilityController
|
|
50
53
|
///
|
|
51
|
-
|
|
54
|
+
access(all) resource Delegator: GetterPublic, GetterPrivate {
|
|
52
55
|
access(self) let privateCapabilities: {Type: Capability}
|
|
53
56
|
access(self) let publicCapabilities: {Type: Capability}
|
|
54
57
|
|
|
@@ -56,7 +59,7 @@ pub contract CapabilityDelegator {
|
|
|
56
59
|
//
|
|
57
60
|
/// Returns the public Capability of the given Type if it exists
|
|
58
61
|
///
|
|
59
|
-
|
|
62
|
+
access(all) view fun getPublicCapability(_ type: Type): Capability? {
|
|
60
63
|
return self.publicCapabilities[type]
|
|
61
64
|
}
|
|
62
65
|
|
|
@@ -66,7 +69,7 @@ pub contract CapabilityDelegator {
|
|
|
66
69
|
/// @param type: Type of the Capability to retrieve
|
|
67
70
|
/// @return Capability of the given Type if it exists, nil otherwise
|
|
68
71
|
///
|
|
69
|
-
|
|
72
|
+
access(Get) view fun getPrivateCapability(_ type: Type): Capability? {
|
|
70
73
|
return self.privateCapabilities[type]
|
|
71
74
|
}
|
|
72
75
|
|
|
@@ -74,7 +77,7 @@ pub contract CapabilityDelegator {
|
|
|
74
77
|
///
|
|
75
78
|
/// @return List of all public Capabilities
|
|
76
79
|
///
|
|
77
|
-
|
|
80
|
+
access(all) view fun getAllPublic(): [Capability] {
|
|
78
81
|
return self.publicCapabilities.values
|
|
79
82
|
}
|
|
80
83
|
|
|
@@ -82,7 +85,7 @@ pub contract CapabilityDelegator {
|
|
|
82
85
|
///
|
|
83
86
|
/// @return List of all private Capabilities
|
|
84
87
|
///
|
|
85
|
-
|
|
88
|
+
access(Get) fun getAllPrivate(): [Capability] {
|
|
86
89
|
return self.privateCapabilities.values
|
|
87
90
|
}
|
|
88
91
|
|
|
@@ -91,7 +94,7 @@ pub contract CapabilityDelegator {
|
|
|
91
94
|
/// @param type: Type to check for subtypes
|
|
92
95
|
/// @return First public Type that is a subtype of the given Type, nil otherwise
|
|
93
96
|
///
|
|
94
|
-
|
|
97
|
+
access(all) view fun findFirstPublicType(_ type: Type): Type? {
|
|
95
98
|
for t in self.publicCapabilities.keys {
|
|
96
99
|
if t.isSubtype(of: type) {
|
|
97
100
|
return t
|
|
@@ -106,7 +109,7 @@ pub contract CapabilityDelegator {
|
|
|
106
109
|
/// @param type: Type to check for subtypes
|
|
107
110
|
/// @return First private Type that is a subtype of the given Type, nil otherwise
|
|
108
111
|
///
|
|
109
|
-
|
|
112
|
+
access(all) view fun findFirstPrivateType(_ type: Type): Type? {
|
|
110
113
|
for t in self.privateCapabilities.keys {
|
|
111
114
|
if t.isSubtype(of: type) {
|
|
112
115
|
return t
|
|
@@ -122,7 +125,7 @@ pub contract CapabilityDelegator {
|
|
|
122
125
|
/// @param cap: Capability to add
|
|
123
126
|
/// @param isPublic: Whether the Capability should be public or private
|
|
124
127
|
///
|
|
125
|
-
|
|
128
|
+
access(Add) fun addCapability(cap: Capability, isPublic: Bool) {
|
|
126
129
|
pre {
|
|
127
130
|
cap.check<&AnyResource>(): "Invalid Capability provided"
|
|
128
131
|
}
|
|
@@ -138,7 +141,7 @@ pub contract CapabilityDelegator {
|
|
|
138
141
|
///
|
|
139
142
|
/// @param cap: Capability to remove
|
|
140
143
|
///
|
|
141
|
-
|
|
144
|
+
access(Delete) fun removeCapability(cap: Capability) {
|
|
142
145
|
if let removedPublic = self.publicCapabilities.remove(key: cap.getType()) {
|
|
143
146
|
emit DelegatorUpdated(id: self.uuid, capabilityType: cap.getType(), isPublic: true, active: false)
|
|
144
147
|
}
|
|
@@ -158,7 +161,7 @@ pub contract CapabilityDelegator {
|
|
|
158
161
|
///
|
|
159
162
|
/// @return Newly created Delegator
|
|
160
163
|
///
|
|
161
|
-
|
|
164
|
+
access(all) fun createDelegator(): @Delegator {
|
|
162
165
|
let delegator <- create Delegator()
|
|
163
166
|
emit DelegatorCreated(id: delegator.uuid)
|
|
164
167
|
return <- delegator
|
|
@@ -167,7 +170,6 @@ pub contract CapabilityDelegator {
|
|
|
167
170
|
init() {
|
|
168
171
|
let identifier = "CapabilityDelegator_".concat(self.account.address.toString())
|
|
169
172
|
self.StoragePath = StoragePath(identifier: identifier)!
|
|
170
|
-
self.PrivatePath = PrivatePath(identifier: identifier)!
|
|
171
173
|
self.PublicPath = PublicPath(identifier: identifier)!
|
|
172
174
|
}
|
|
173
175
|
}
|
|
@@ -13,37 +13,40 @@
|
|
|
13
13
|
/// Capabilities is critical to the use case of Hybrid Custody. It's advised to use Factories sparingly and only for
|
|
14
14
|
/// cases where Capabilities must be castable by the caller.
|
|
15
15
|
///
|
|
16
|
-
|
|
16
|
+
access(all) contract CapabilityFactory {
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
access(all) let StoragePath: StoragePath
|
|
19
|
+
access(all) let PublicPath: PublicPath
|
|
20
|
+
|
|
21
|
+
access(all) entitlement Add
|
|
22
|
+
access(all) entitlement Delete
|
|
21
23
|
|
|
22
24
|
/// Factory structures a common interface for Capability retrieval from a given account at a specified path
|
|
23
25
|
///
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
access(all) struct interface Factory {
|
|
27
|
+
access(all) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability?
|
|
28
|
+
access(all) view fun getPublicCapability(acct: &Account, path: PublicPath): Capability?
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
/// Getter defines an interface for retrieval of a Factory if contained within the implementing resource
|
|
29
32
|
///
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
access(all) resource interface Getter {
|
|
34
|
+
access(all) view fun getSupportedTypes(): [Type]
|
|
35
|
+
access(all) view fun getFactory(_ t: Type): {CapabilityFactory.Factory}?
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
/// Manager is a resource that contains Factories and implements the Getter interface for retrieval of contained
|
|
36
39
|
/// Factories
|
|
37
40
|
///
|
|
38
|
-
|
|
41
|
+
access(all) resource Manager: Getter {
|
|
39
42
|
/// Mapping of Factories indexed on Type of Capability they retrieve
|
|
40
|
-
|
|
43
|
+
access(all) let factories: {Type: {CapabilityFactory.Factory}}
|
|
41
44
|
|
|
42
45
|
/// Retrieves a list of Types supported by contained Factories
|
|
43
46
|
///
|
|
44
47
|
/// @return List of Types supported by the Manager
|
|
45
48
|
///
|
|
46
|
-
|
|
49
|
+
access(all) view fun getSupportedTypes(): [Type] {
|
|
47
50
|
return self.factories.keys
|
|
48
51
|
}
|
|
49
52
|
|
|
@@ -51,7 +54,7 @@ pub contract CapabilityFactory {
|
|
|
51
54
|
///
|
|
52
55
|
/// @param t: Type the Factory is indexed on
|
|
53
56
|
///
|
|
54
|
-
|
|
57
|
+
access(all) view fun getFactory(_ t: Type): {CapabilityFactory.Factory}? {
|
|
55
58
|
return self.factories[t]
|
|
56
59
|
}
|
|
57
60
|
|
|
@@ -60,7 +63,7 @@ pub contract CapabilityFactory {
|
|
|
60
63
|
/// @param t: Type of Capability the Factory retrieves
|
|
61
64
|
/// @param f: Factory to add
|
|
62
65
|
///
|
|
63
|
-
|
|
66
|
+
access(Add) fun addFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
|
|
64
67
|
pre {
|
|
65
68
|
!self.factories.containsKey(t): "Factory of given type already exists"
|
|
66
69
|
}
|
|
@@ -72,7 +75,7 @@ pub contract CapabilityFactory {
|
|
|
72
75
|
/// @param t: Type of Capability the Factory retrieves
|
|
73
76
|
/// @param f: Factory to replace existing Factory
|
|
74
77
|
///
|
|
75
|
-
|
|
78
|
+
access(Add) fun updateFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
|
|
76
79
|
self.factories[t] = f
|
|
77
80
|
}
|
|
78
81
|
|
|
@@ -80,7 +83,7 @@ pub contract CapabilityFactory {
|
|
|
80
83
|
///
|
|
81
84
|
/// @param t: Type the Factory is indexed on
|
|
82
85
|
///
|
|
83
|
-
|
|
86
|
+
access(Delete) fun removeFactory(_ t: Type): {CapabilityFactory.Factory}? {
|
|
84
87
|
return self.factories.remove(key: t)
|
|
85
88
|
}
|
|
86
89
|
|
|
@@ -92,14 +95,13 @@ pub contract CapabilityFactory {
|
|
|
92
95
|
/// Creates a Manager resource
|
|
93
96
|
///
|
|
94
97
|
/// @return Manager resource
|
|
95
|
-
|
|
98
|
+
access(all) fun createFactoryManager(): @Manager {
|
|
96
99
|
return <- create Manager()
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
init() {
|
|
100
103
|
let identifier = "CapabilityFactory_".concat(self.account.address.toString())
|
|
101
104
|
self.StoragePath = StoragePath(identifier: identifier)!
|
|
102
|
-
self.PrivatePath = PrivatePath(identifier: identifier)!
|
|
103
105
|
self.PublicPath = PublicPath(identifier: identifier)!
|
|
104
106
|
}
|
|
105
107
|
}
|
|
@@ -6,29 +6,31 @@
|
|
|
6
6
|
/// - `AllowlistFilter` - A filter which contains a mapping of allowed Types
|
|
7
7
|
/// - `AllowAllFilter` - A passthrough, all requested capabilities are allowed
|
|
8
8
|
///
|
|
9
|
-
|
|
9
|
+
access(all) contract CapabilityFilter {
|
|
10
10
|
|
|
11
11
|
/* --- Canonical Paths --- */
|
|
12
12
|
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
access(all) let StoragePath: StoragePath
|
|
14
|
+
access(all) let PublicPath: PublicPath
|
|
15
|
+
|
|
16
|
+
access(all) entitlement Add
|
|
17
|
+
access(all) entitlement Delete
|
|
16
18
|
|
|
17
19
|
/* --- Events --- */
|
|
18
20
|
//
|
|
19
|
-
|
|
21
|
+
access(all) event FilterUpdated(id: UInt64, filterType: Type, type: Type, active: Bool)
|
|
20
22
|
|
|
21
23
|
/// `Filter` is a simple interface with methods to determine if a Capability is allowed and retrieve details about
|
|
22
24
|
/// the Filter itself
|
|
23
25
|
///
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
access(all) resource interface Filter {
|
|
27
|
+
access(all) view fun allowed(cap: Capability): Bool
|
|
28
|
+
access(all) view fun getDetails(): AnyStruct
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
/// `DenylistFilter` is a `Filter` which contains a mapping of denied Types
|
|
30
32
|
///
|
|
31
|
-
|
|
33
|
+
access(all) resource DenylistFilter: Filter {
|
|
32
34
|
|
|
33
35
|
/// Represents the underlying types which should not ever be returned by a RestrictedChildAccount. The filter
|
|
34
36
|
/// will borrow a requested capability, and make sure that the type it gets back is not in the list of denied
|
|
@@ -39,7 +41,7 @@ pub contract CapabilityFilter {
|
|
|
39
41
|
///
|
|
40
42
|
/// @param type: The type to add to the denied types mapping
|
|
41
43
|
///
|
|
42
|
-
|
|
44
|
+
access(Add) fun addType(_ type: Type) {
|
|
43
45
|
self.deniedTypes.insert(key: type, true)
|
|
44
46
|
emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: true)
|
|
45
47
|
}
|
|
@@ -48,18 +50,26 @@ pub contract CapabilityFilter {
|
|
|
48
50
|
///
|
|
49
51
|
/// @param type: The type to remove from the denied types mapping
|
|
50
52
|
///
|
|
51
|
-
|
|
53
|
+
access(Delete) fun removeType(_ type: Type) {
|
|
52
54
|
if let removed = self.deniedTypes.remove(key: type) {
|
|
53
55
|
emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: false)
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
/// Removes all types from the mapping of denied types
|
|
60
|
+
///
|
|
61
|
+
access(Delete) fun removeAllTypes() {
|
|
62
|
+
for type in self.deniedTypes.keys {
|
|
63
|
+
self.removeType(type)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
57
67
|
/// Determines if a requested capability is allowed by this `Filter`
|
|
58
68
|
///
|
|
59
69
|
/// @param cap: The capability to check
|
|
60
70
|
/// @return: true if the capability is allowed, false otherwise
|
|
61
71
|
///
|
|
62
|
-
|
|
72
|
+
access(all) view fun allowed(cap: Capability): Bool {
|
|
63
73
|
if let item = cap.borrow<&AnyResource>() {
|
|
64
74
|
return !self.deniedTypes.containsKey(item.getType())
|
|
65
75
|
}
|
|
@@ -72,7 +82,7 @@ pub contract CapabilityFilter {
|
|
|
72
82
|
/// @return A struct containing details about this filter including this Filter's Type indexed on the `type`
|
|
73
83
|
/// key as well as types denied indexed on the `deniedTypes` key
|
|
74
84
|
///
|
|
75
|
-
|
|
85
|
+
access(all) view fun getDetails(): AnyStruct {
|
|
76
86
|
return {
|
|
77
87
|
"type": self.getType(),
|
|
78
88
|
"deniedTypes": self.deniedTypes.keys
|
|
@@ -86,7 +96,7 @@ pub contract CapabilityFilter {
|
|
|
86
96
|
|
|
87
97
|
/// `AllowlistFilter` is a `Filter` which contains a mapping of allowed Types
|
|
88
98
|
///
|
|
89
|
-
|
|
99
|
+
access(all) resource AllowlistFilter: Filter {
|
|
90
100
|
// allowedTypes
|
|
91
101
|
// Represents the set of underlying types which are allowed to be
|
|
92
102
|
// returned by a RestrictedChildAccount. The filter will borrow
|
|
@@ -98,7 +108,7 @@ pub contract CapabilityFilter {
|
|
|
98
108
|
///
|
|
99
109
|
/// @param type: The type to add to the allowed types mapping
|
|
100
110
|
///
|
|
101
|
-
|
|
111
|
+
access(Add) fun addType(_ type: Type) {
|
|
102
112
|
self.allowedTypes.insert(key: type, true)
|
|
103
113
|
emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: true)
|
|
104
114
|
}
|
|
@@ -107,18 +117,26 @@ pub contract CapabilityFilter {
|
|
|
107
117
|
///
|
|
108
118
|
/// @param type: The type to remove from the denied types mapping
|
|
109
119
|
///
|
|
110
|
-
|
|
120
|
+
access(Delete) fun removeType(_ type: Type) {
|
|
111
121
|
if let removed = self.allowedTypes.remove(key: type) {
|
|
112
122
|
emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: false)
|
|
113
123
|
}
|
|
114
124
|
}
|
|
125
|
+
|
|
126
|
+
/// Removes all types from the mapping of denied types
|
|
127
|
+
///
|
|
128
|
+
access(Delete) fun removeAllTypes() {
|
|
129
|
+
for type in self.allowedTypes.keys {
|
|
130
|
+
self.removeType(type)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
115
133
|
|
|
116
134
|
/// Determines if a requested capability is allowed by this `Filter`
|
|
117
135
|
///
|
|
118
136
|
/// @param cap: The capability to check
|
|
119
137
|
/// @return: true if the capability is allowed, false otherwise
|
|
120
138
|
///
|
|
121
|
-
|
|
139
|
+
access(all) view fun allowed(cap: Capability): Bool {
|
|
122
140
|
if let item = cap.borrow<&AnyResource>() {
|
|
123
141
|
return self.allowedTypes.containsKey(item.getType())
|
|
124
142
|
}
|
|
@@ -131,7 +149,7 @@ pub contract CapabilityFilter {
|
|
|
131
149
|
/// @return A struct containing details about this filter including this Filter's Type indexed on the `type`
|
|
132
150
|
/// key as well as types allowed indexed on the `allowedTypes` key
|
|
133
151
|
///
|
|
134
|
-
|
|
152
|
+
access(all) view fun getDetails(): AnyStruct {
|
|
135
153
|
return {
|
|
136
154
|
"type": self.getType(),
|
|
137
155
|
"allowedTypes": self.allowedTypes.keys
|
|
@@ -145,13 +163,13 @@ pub contract CapabilityFilter {
|
|
|
145
163
|
|
|
146
164
|
/// AllowAllFilter is a passthrough, all requested capabilities are allowed
|
|
147
165
|
///
|
|
148
|
-
|
|
166
|
+
access(all) resource AllowAllFilter: Filter {
|
|
149
167
|
/// Determines if a requested capability is allowed by this `Filter`
|
|
150
168
|
///
|
|
151
169
|
/// @param cap: The capability to check
|
|
152
170
|
/// @return: true since this filter is a passthrough
|
|
153
171
|
///
|
|
154
|
-
|
|
172
|
+
access(all) view fun allowed(cap: Capability): Bool {
|
|
155
173
|
return true
|
|
156
174
|
}
|
|
157
175
|
|
|
@@ -160,7 +178,7 @@ pub contract CapabilityFilter {
|
|
|
160
178
|
/// @return A struct containing details about this filter including this Filter's Type indexed on the `type`
|
|
161
179
|
/// key
|
|
162
180
|
///
|
|
163
|
-
|
|
181
|
+
access(all) view fun getDetails(): AnyStruct {
|
|
164
182
|
return {
|
|
165
183
|
"type": self.getType()
|
|
166
184
|
}
|
|
@@ -172,7 +190,7 @@ pub contract CapabilityFilter {
|
|
|
172
190
|
/// @param t: The type of `Filter` to create
|
|
173
191
|
/// @return: A new instance of the given `Filter` type
|
|
174
192
|
///
|
|
175
|
-
|
|
193
|
+
access(all) fun createFilter(_ t: Type): @{Filter} {
|
|
176
194
|
post {
|
|
177
195
|
result.getType() == t
|
|
178
196
|
}
|
|
@@ -194,6 +212,5 @@ pub contract CapabilityFilter {
|
|
|
194
212
|
|
|
195
213
|
self.StoragePath = StoragePath(identifier: identifier)!
|
|
196
214
|
self.PublicPath = PublicPath(identifier: identifier)!
|
|
197
|
-
self.PrivatePath = PrivatePath(identifier: identifier)!
|
|
198
215
|
}
|
|
199
|
-
}
|
|
216
|
+
}
|