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

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