@flowtyio/flow-contracts 0.1.0-beta.11 → 0.1.0-beta.12

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.
@@ -7,48 +7,48 @@
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
- pub contract CapabilityDelegator {
10
+ access(all) contract CapabilityDelegator {
11
11
 
12
12
  /* --- Canonical Paths --- */
13
13
  //
14
- pub let StoragePath: StoragePath
15
- pub let PrivatePath: PrivatePath
16
- pub let PublicPath: PublicPath
14
+ access(all) let StoragePath: StoragePath
15
+ access(all) let PrivatePath: PrivatePath
16
+ access(all) let PublicPath: PublicPath
17
17
 
18
18
  /* --- Events --- */
19
19
  //
20
- pub event DelegatorCreated(id: UInt64)
21
- pub event DelegatorUpdated(id: UInt64, capabilityType: Type, isPublic: Bool, active: Bool)
20
+ access(all) event DelegatorCreated(id: UInt64)
21
+ access(all) event DelegatorUpdated(id: UInt64, capabilityType: Type, isPublic: Bool, active: Bool)
22
22
 
23
23
  /// Private interface for Capability retrieval
24
24
  ///
25
- pub resource interface GetterPrivate {
26
- pub fun getPrivateCapability(_ type: Type): Capability? {
25
+ access(all) resource interface GetterPrivate {
26
+ access(Capabilities) view fun getPrivateCapability(_ type: Type): Capability? {
27
27
  post {
28
28
  result == nil || type.isSubtype(of: result.getType()): "incorrect returned capability type"
29
29
  }
30
30
  }
31
- pub fun findFirstPrivateType(_ type: Type): Type?
32
- pub fun getAllPrivate(): [Capability]
31
+ access(all) view fun findFirstPrivateType(_ type: Type): Type?
32
+ access(Capabilities) fun getAllPrivate(): [Capability]
33
33
  }
34
34
 
35
35
  /// Exposes public Capability retrieval
36
36
  ///
37
- pub resource interface GetterPublic {
38
- pub fun getPublicCapability(_ type: Type): Capability? {
37
+ access(all) resource interface GetterPublic {
38
+ access(all) view fun getPublicCapability(_ type: Type): Capability? {
39
39
  post {
40
- result == nil || type.isSubtype(of: result.getType()): "incorrect returned capability type "
40
+ result == nil || type.isSubtype(of: result.getType()): "incorrect returned capability type"
41
41
  }
42
42
  }
43
43
 
44
- pub fun findFirstPublicType(_ type: Type): Type?
45
- pub fun getAllPublic(): [Capability]
44
+ access(all) view fun findFirstPublicType(_ type: Type): Type?
45
+ access(all) view fun getAllPublic(): [Capability]
46
46
  }
47
47
 
48
48
  /// This Delegator is used to store Capabilities, partitioned by public and private access with corresponding
49
49
  /// GetterPublic and GetterPrivate conformances.AccountCapabilityController
50
50
  ///
51
- pub resource Delegator: GetterPublic, GetterPrivate {
51
+ access(all) resource Delegator: GetterPublic, GetterPrivate {
52
52
  access(self) let privateCapabilities: {Type: Capability}
53
53
  access(self) let publicCapabilities: {Type: Capability}
54
54
 
@@ -56,7 +56,7 @@ pub contract CapabilityDelegator {
56
56
  //
57
57
  /// Returns the public Capability of the given Type if it exists
58
58
  ///
59
- pub fun getPublicCapability(_ type: Type): Capability? {
59
+ access(all) view fun getPublicCapability(_ type: Type): Capability? {
60
60
  return self.publicCapabilities[type]
61
61
  }
62
62
 
@@ -66,7 +66,7 @@ pub contract CapabilityDelegator {
66
66
  /// @param type: Type of the Capability to retrieve
67
67
  /// @return Capability of the given Type if it exists, nil otherwise
68
68
  ///
69
- pub fun getPrivateCapability(_ type: Type): Capability? {
69
+ access(Capabilities) view fun getPrivateCapability(_ type: Type): Capability? {
70
70
  return self.privateCapabilities[type]
71
71
  }
72
72
 
@@ -74,7 +74,7 @@ pub contract CapabilityDelegator {
74
74
  ///
75
75
  /// @return List of all public Capabilities
76
76
  ///
77
- pub fun getAllPublic(): [Capability] {
77
+ access(all) view fun getAllPublic(): [Capability] {
78
78
  return self.publicCapabilities.values
79
79
  }
80
80
 
@@ -82,7 +82,7 @@ pub contract CapabilityDelegator {
82
82
  ///
83
83
  /// @return List of all private Capabilities
84
84
  ///
85
- pub fun getAllPrivate(): [Capability] {
85
+ access(Capabilities) fun getAllPrivate(): [Capability] {
86
86
  return self.privateCapabilities.values
87
87
  }
88
88
 
@@ -91,7 +91,7 @@ pub contract CapabilityDelegator {
91
91
  /// @param type: Type to check for subtypes
92
92
  /// @return First public Type that is a subtype of the given Type, nil otherwise
93
93
  ///
94
- pub fun findFirstPublicType(_ type: Type): Type? {
94
+ access(all) view fun findFirstPublicType(_ type: Type): Type? {
95
95
  for t in self.publicCapabilities.keys {
96
96
  if t.isSubtype(of: type) {
97
97
  return t
@@ -106,7 +106,7 @@ pub contract CapabilityDelegator {
106
106
  /// @param type: Type to check for subtypes
107
107
  /// @return First private Type that is a subtype of the given Type, nil otherwise
108
108
  ///
109
- pub fun findFirstPrivateType(_ type: Type): Type? {
109
+ access(all) view fun findFirstPrivateType(_ type: Type): Type? {
110
110
  for t in self.privateCapabilities.keys {
111
111
  if t.isSubtype(of: type) {
112
112
  return t
@@ -122,7 +122,7 @@ pub contract CapabilityDelegator {
122
122
  /// @param cap: Capability to add
123
123
  /// @param isPublic: Whether the Capability should be public or private
124
124
  ///
125
- pub fun addCapability(cap: Capability, isPublic: Bool) {
125
+ access(Mutate) fun addCapability(cap: Capability, isPublic: Bool) {
126
126
  pre {
127
127
  cap.check<&AnyResource>(): "Invalid Capability provided"
128
128
  }
@@ -138,7 +138,7 @@ pub contract CapabilityDelegator {
138
138
  ///
139
139
  /// @param cap: Capability to remove
140
140
  ///
141
- pub fun removeCapability(cap: Capability) {
141
+ access(Mutate) fun removeCapability(cap: Capability) {
142
142
  if let removedPublic = self.publicCapabilities.remove(key: cap.getType()) {
143
143
  emit DelegatorUpdated(id: self.uuid, capabilityType: cap.getType(), isPublic: true, active: false)
144
144
  }
@@ -158,7 +158,7 @@ pub contract CapabilityDelegator {
158
158
  ///
159
159
  /// @return Newly created Delegator
160
160
  ///
161
- pub fun createDelegator(): @Delegator {
161
+ access(all) fun createDelegator(): @Delegator {
162
162
  let delegator <- create Delegator()
163
163
  emit DelegatorCreated(id: delegator.uuid)
164
164
  return <- delegator
@@ -13,37 +13,38 @@
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
- pub contract CapabilityFactory {
16
+ access(all) contract CapabilityFactory {
17
17
 
18
- pub let StoragePath: StoragePath
19
- pub let PrivatePath: PrivatePath
20
- pub let PublicPath: PublicPath
18
+ access(all) let StoragePath: StoragePath
19
+ access(all) let PrivatePath: PrivatePath
20
+ access(all) let PublicPath: PublicPath
21
21
 
22
22
  /// Factory structures a common interface for Capability retrieval from a given account at a specified path
23
23
  ///
24
- pub struct interface Factory {
25
- pub fun getCapability(acct: &AuthAccount, path: CapabilityPath): Capability
24
+ access(all) struct interface Factory {
25
+ access(Capabilities) view fun getCapability(acct: auth(Capabilities) &Account, controllerID: UInt64): Capability?
26
+ access(all) view fun getPublicCapability(acct: auth(Capabilities) &Account, path: PublicPath): Capability?
26
27
  }
27
28
 
28
29
  /// Getter defines an interface for retrieval of a Factory if contained within the implementing resource
29
30
  ///
30
- pub resource interface Getter {
31
- pub fun getSupportedTypes(): [Type]
32
- pub fun getFactory(_ t: Type): {CapabilityFactory.Factory}?
31
+ access(all) resource interface Getter {
32
+ access(all) view fun getSupportedTypes(): [Type]
33
+ access(all) view fun getFactory(_ t: Type): {CapabilityFactory.Factory}?
33
34
  }
34
35
 
35
36
  /// Manager is a resource that contains Factories and implements the Getter interface for retrieval of contained
36
37
  /// Factories
37
38
  ///
38
- pub resource Manager: Getter {
39
+ access(all) resource Manager: Getter {
39
40
  /// Mapping of Factories indexed on Type of Capability they retrieve
40
- pub let factories: {Type: {CapabilityFactory.Factory}}
41
+ access(all) let factories: {Type: {CapabilityFactory.Factory}}
41
42
 
42
43
  /// Retrieves a list of Types supported by contained Factories
43
44
  ///
44
45
  /// @return List of Types supported by the Manager
45
46
  ///
46
- pub fun getSupportedTypes(): [Type] {
47
+ access(all) view fun getSupportedTypes(): [Type] {
47
48
  return self.factories.keys
48
49
  }
49
50
 
@@ -51,7 +52,7 @@ pub contract CapabilityFactory {
51
52
  ///
52
53
  /// @param t: Type the Factory is indexed on
53
54
  ///
54
- pub fun getFactory(_ t: Type): {CapabilityFactory.Factory}? {
55
+ access(all) view fun getFactory(_ t: Type): {CapabilityFactory.Factory}? {
55
56
  return self.factories[t]
56
57
  }
57
58
 
@@ -60,7 +61,7 @@ pub contract CapabilityFactory {
60
61
  /// @param t: Type of Capability the Factory retrieves
61
62
  /// @param f: Factory to add
62
63
  ///
63
- pub fun addFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
64
+ access(Mutate) fun addFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
64
65
  pre {
65
66
  !self.factories.containsKey(t): "Factory of given type already exists"
66
67
  }
@@ -72,7 +73,7 @@ pub contract CapabilityFactory {
72
73
  /// @param t: Type of Capability the Factory retrieves
73
74
  /// @param f: Factory to replace existing Factory
74
75
  ///
75
- pub fun updateFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
76
+ access(Mutate) fun updateFactory(_ t: Type, _ f: {CapabilityFactory.Factory}) {
76
77
  self.factories[t] = f
77
78
  }
78
79
 
@@ -80,7 +81,7 @@ pub contract CapabilityFactory {
80
81
  ///
81
82
  /// @param t: Type the Factory is indexed on
82
83
  ///
83
- pub fun removeFactory(_ t: Type): {CapabilityFactory.Factory}? {
84
+ access(Mutate) fun removeFactory(_ t: Type): {CapabilityFactory.Factory}? {
84
85
  return self.factories.remove(key: t)
85
86
  }
86
87
 
@@ -92,7 +93,7 @@ pub contract CapabilityFactory {
92
93
  /// Creates a Manager resource
93
94
  ///
94
95
  /// @return Manager resource
95
- pub fun createFactoryManager(): @Manager {
96
+ access(all) fun createFactoryManager(): @Manager {
96
97
  return <- create Manager()
97
98
  }
98
99
 
@@ -6,29 +6,29 @@
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
- pub contract CapabilityFilter {
9
+ access(all) contract CapabilityFilter {
10
10
 
11
11
  /* --- Canonical Paths --- */
12
12
  //
13
- pub let StoragePath: StoragePath
14
- pub let PublicPath: PublicPath
15
- pub let PrivatePath: PrivatePath
13
+ access(all) let StoragePath: StoragePath
14
+ access(all) let PublicPath: PublicPath
15
+ access(all) let PrivatePath: PrivatePath
16
16
 
17
17
  /* --- Events --- */
18
18
  //
19
- pub event FilterUpdated(id: UInt64, filterType: Type, type: Type, active: Bool)
19
+ access(all) event FilterUpdated(id: UInt64, filterType: Type, type: Type, active: Bool)
20
20
 
21
21
  /// `Filter` is a simple interface with methods to determine if a Capability is allowed and retrieve details about
22
22
  /// the Filter itself
23
23
  ///
24
- pub resource interface Filter {
25
- pub fun allowed(cap: Capability): Bool
26
- pub fun getDetails(): AnyStruct
24
+ access(all) resource interface Filter {
25
+ access(all) view fun allowed(cap: Capability): Bool
26
+ access(all) view fun getDetails(): AnyStruct
27
27
  }
28
28
 
29
29
  /// `DenylistFilter` is a `Filter` which contains a mapping of denied Types
30
30
  ///
31
- pub resource DenylistFilter: Filter {
31
+ access(all) resource DenylistFilter: Filter {
32
32
 
33
33
  /// Represents the underlying types which should not ever be returned by a RestrictedChildAccount. The filter
34
34
  /// will borrow a requested capability, and make sure that the type it gets back is not in the list of denied
@@ -39,7 +39,7 @@ pub contract CapabilityFilter {
39
39
  ///
40
40
  /// @param type: The type to add to the denied types mapping
41
41
  ///
42
- pub fun addType(_ type: Type) {
42
+ access(Mutate) fun addType(_ type: Type) {
43
43
  self.deniedTypes.insert(key: type, true)
44
44
  emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: true)
45
45
  }
@@ -48,18 +48,26 @@ pub contract CapabilityFilter {
48
48
  ///
49
49
  /// @param type: The type to remove from the denied types mapping
50
50
  ///
51
- pub fun removeType(_ type: Type) {
51
+ access(Mutate) fun removeType(_ type: Type) {
52
52
  if let removed = self.deniedTypes.remove(key: type) {
53
53
  emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: false)
54
54
  }
55
55
  }
56
56
 
57
+ /// Removes all types from the mapping of denied types
58
+ ///
59
+ access(Mutate) fun removeAllTypes() {
60
+ for type in self.deniedTypes.keys {
61
+ self.removeType(type)
62
+ }
63
+ }
64
+
57
65
  /// Determines if a requested capability is allowed by this `Filter`
58
66
  ///
59
67
  /// @param cap: The capability to check
60
68
  /// @return: true if the capability is allowed, false otherwise
61
69
  ///
62
- pub fun allowed(cap: Capability): Bool {
70
+ access(all) view fun allowed(cap: Capability): Bool {
63
71
  if let item = cap.borrow<&AnyResource>() {
64
72
  return !self.deniedTypes.containsKey(item.getType())
65
73
  }
@@ -72,7 +80,7 @@ pub contract CapabilityFilter {
72
80
  /// @return A struct containing details about this filter including this Filter's Type indexed on the `type`
73
81
  /// key as well as types denied indexed on the `deniedTypes` key
74
82
  ///
75
- pub fun getDetails(): AnyStruct {
83
+ access(all) view fun getDetails(): AnyStruct {
76
84
  return {
77
85
  "type": self.getType(),
78
86
  "deniedTypes": self.deniedTypes.keys
@@ -86,7 +94,7 @@ pub contract CapabilityFilter {
86
94
 
87
95
  /// `AllowlistFilter` is a `Filter` which contains a mapping of allowed Types
88
96
  ///
89
- pub resource AllowlistFilter: Filter {
97
+ access(all) resource AllowlistFilter: Filter {
90
98
  // allowedTypes
91
99
  // Represents the set of underlying types which are allowed to be
92
100
  // returned by a RestrictedChildAccount. The filter will borrow
@@ -98,7 +106,7 @@ pub contract CapabilityFilter {
98
106
  ///
99
107
  /// @param type: The type to add to the allowed types mapping
100
108
  ///
101
- pub fun addType(_ type: Type) {
109
+ access(Mutate) fun addType(_ type: Type) {
102
110
  self.allowedTypes.insert(key: type, true)
103
111
  emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: true)
104
112
  }
@@ -107,18 +115,26 @@ pub contract CapabilityFilter {
107
115
  ///
108
116
  /// @param type: The type to remove from the denied types mapping
109
117
  ///
110
- pub fun removeType(_ type: Type) {
118
+ access(Mutate) fun removeType(_ type: Type) {
111
119
  if let removed = self.allowedTypes.remove(key: type) {
112
120
  emit FilterUpdated(id: self.uuid, filterType: self.getType(), type: type, active: false)
113
121
  }
114
122
  }
123
+
124
+ /// Removes all types from the mapping of denied types
125
+ ///
126
+ access(Mutate) fun removeAllTypes() {
127
+ for type in self.allowedTypes.keys {
128
+ self.removeType(type)
129
+ }
130
+ }
115
131
 
116
132
  /// Determines if a requested capability is allowed by this `Filter`
117
133
  ///
118
134
  /// @param cap: The capability to check
119
135
  /// @return: true if the capability is allowed, false otherwise
120
136
  ///
121
- pub fun allowed(cap: Capability): Bool {
137
+ access(all) view fun allowed(cap: Capability): Bool {
122
138
  if let item = cap.borrow<&AnyResource>() {
123
139
  return self.allowedTypes.containsKey(item.getType())
124
140
  }
@@ -131,7 +147,7 @@ pub contract CapabilityFilter {
131
147
  /// @return A struct containing details about this filter including this Filter's Type indexed on the `type`
132
148
  /// key as well as types allowed indexed on the `allowedTypes` key
133
149
  ///
134
- pub fun getDetails(): AnyStruct {
150
+ access(all) view fun getDetails(): AnyStruct {
135
151
  return {
136
152
  "type": self.getType(),
137
153
  "allowedTypes": self.allowedTypes.keys
@@ -145,13 +161,13 @@ pub contract CapabilityFilter {
145
161
 
146
162
  /// AllowAllFilter is a passthrough, all requested capabilities are allowed
147
163
  ///
148
- pub resource AllowAllFilter: Filter {
164
+ access(all) resource AllowAllFilter: Filter {
149
165
  /// Determines if a requested capability is allowed by this `Filter`
150
166
  ///
151
167
  /// @param cap: The capability to check
152
168
  /// @return: true since this filter is a passthrough
153
169
  ///
154
- pub fun allowed(cap: Capability): Bool {
170
+ access(all) view fun allowed(cap: Capability): Bool {
155
171
  return true
156
172
  }
157
173
 
@@ -160,7 +176,7 @@ pub contract CapabilityFilter {
160
176
  /// @return A struct containing details about this filter including this Filter's Type indexed on the `type`
161
177
  /// key
162
178
  ///
163
- pub fun getDetails(): AnyStruct {
179
+ access(all) view fun getDetails(): AnyStruct {
164
180
  return {
165
181
  "type": self.getType()
166
182
  }
@@ -172,7 +188,7 @@ pub contract CapabilityFilter {
172
188
  /// @param t: The type of `Filter` to create
173
189
  /// @return: A new instance of the given `Filter` type
174
190
  ///
175
- pub fun create(_ t: Type): @AnyResource{Filter} {
191
+ access(all) fun createFilter(_ t: Type): @{Filter} {
176
192
  post {
177
193
  result.getType() == t
178
194
  }