@@ -50,12 +50,9 @@ pub fn check_restrict_assets(
50
50
checker. type_check_expects ( asset_owner, context, & TypeSignature :: PrincipalType ) ?;
51
51
52
52
for allowance in allowance_list {
53
- check_allowance (
54
- checker,
55
- allowance,
56
- context,
57
- & NativeFunctions :: RestrictAssets ,
58
- ) ?;
53
+ if check_allowance ( checker, allowance, context) ? {
54
+ return Err ( CheckErrors :: WithAllAllowanceNotAllowed . into ( ) ) ;
55
+ }
59
56
}
60
57
61
58
// Check the body expressions, ensuring any intermediate responses are handled
@@ -97,12 +94,9 @@ pub fn check_as_contract(
97
94
) ?;
98
95
99
96
for allowance in allowance_list {
100
- check_allowance (
101
- checker,
102
- allowance,
103
- context,
104
- & NativeFunctions :: AsContractSafe ,
105
- ) ?;
97
+ if check_allowance ( checker, allowance, context) ? && allowance_list. len ( ) > 1 {
98
+ return Err ( CheckErrors :: WithAllAllowanceNotAlone . into ( ) ) ;
99
+ }
106
100
}
107
101
108
102
// Check the body expressions, ensuring any intermediate responses are handled
@@ -133,12 +127,13 @@ pub fn check_allowance_err(
133
127
Err ( CheckErrors :: AllowanceExprNotAllowed . into ( ) )
134
128
}
135
129
130
+ /// Type check an allowance expression, returning whether it is a
131
+ /// `with-all-assets-unsafe` allowance (which has special rules).
136
132
pub fn check_allowance (
137
133
checker : & mut TypeChecker ,
138
134
allowance : & SymbolicExpression ,
139
135
context : & TypingContext ,
140
- parent_expr : & NativeFunctions ,
141
- ) -> Result < ( ) , CheckError > {
136
+ ) -> Result < bool , CheckError > {
142
137
let list = allowance
143
138
. match_list ( )
144
139
. ok_or ( CheckErrors :: ExpectedListApplication ) ?;
@@ -155,19 +150,13 @@ pub fn check_allowance(
155
150
} ;
156
151
157
152
match native_function {
158
- NativeFunctions :: AllowanceWithStx => {
159
- check_allowance_with_stx ( checker, args, context, parent_expr)
160
- }
161
- NativeFunctions :: AllowanceWithFt => {
162
- check_allowance_with_ft ( checker, args, context, parent_expr)
163
- }
164
- NativeFunctions :: AllowanceWithNft => {
165
- check_allowance_with_nft ( checker, args, context, parent_expr)
166
- }
153
+ NativeFunctions :: AllowanceWithStx => check_allowance_with_stx ( checker, args, context) ,
154
+ NativeFunctions :: AllowanceWithFt => check_allowance_with_ft ( checker, args, context) ,
155
+ NativeFunctions :: AllowanceWithNft => check_allowance_with_nft ( checker, args, context) ,
167
156
NativeFunctions :: AllowanceWithStacking => {
168
- check_allowance_with_stacking ( checker, args, context, parent_expr )
157
+ check_allowance_with_stacking ( checker, args, context)
169
158
}
170
- NativeFunctions :: AllowanceAll => check_allowance_all ( checker, args, context, parent_expr ) ,
159
+ NativeFunctions :: AllowanceAll => check_allowance_all ( checker, args, context) ,
171
160
_ => Err ( CheckErrors :: ExpectedAllowanceExpr ( function_name. to_string ( ) ) . into ( ) ) ,
172
161
}
173
162
}
@@ -178,13 +167,12 @@ fn check_allowance_with_stx(
178
167
checker : & mut TypeChecker ,
179
168
args : & [ SymbolicExpression ] ,
180
169
context : & TypingContext ,
181
- _parent_expr : & NativeFunctions ,
182
- ) -> Result < ( ) , CheckError > {
170
+ ) -> Result < bool , CheckError > {
183
171
check_argument_count ( 1 , args) ?;
184
172
185
173
checker. type_check_expects ( & args[ 0 ] , context, & TypeSignature :: UIntType ) ?;
186
174
187
- Ok ( ( ) )
175
+ Ok ( false )
188
176
}
189
177
190
178
/// Type check a `with-ft` allowance expression.
@@ -193,15 +181,14 @@ fn check_allowance_with_ft(
193
181
checker : & mut TypeChecker ,
194
182
args : & [ SymbolicExpression ] ,
195
183
context : & TypingContext ,
196
- _parent_expr : & NativeFunctions ,
197
- ) -> Result < ( ) , CheckError > {
184
+ ) -> Result < bool , CheckError > {
198
185
check_argument_count ( 3 , args) ?;
199
186
200
187
checker. type_check_expects ( & args[ 0 ] , context, & TypeSignature :: PrincipalType ) ?;
201
188
checker. type_check_expects ( & args[ 1 ] , context, & ASCII_128 ) ?;
202
189
checker. type_check_expects ( & args[ 2 ] , context, & TypeSignature :: UIntType ) ?;
203
190
204
- Ok ( ( ) )
191
+ Ok ( false )
205
192
}
206
193
207
194
/// Type check a `with-nft` allowance expression.
@@ -210,15 +197,14 @@ fn check_allowance_with_nft(
210
197
checker : & mut TypeChecker ,
211
198
args : & [ SymbolicExpression ] ,
212
199
context : & TypingContext ,
213
- _parent_expr : & NativeFunctions ,
214
- ) -> Result < ( ) , CheckError > {
200
+ ) -> Result < bool , CheckError > {
215
201
check_argument_count ( 3 , args) ?;
216
202
217
203
checker. type_check_expects ( & args[ 0 ] , context, & TypeSignature :: PrincipalType ) ?;
218
204
checker. type_check_expects ( & args[ 1 ] , context, & ASCII_128 ) ?;
219
205
// Asset ID can be any type
220
206
221
- Ok ( ( ) )
207
+ Ok ( false )
222
208
}
223
209
224
210
/// Type check a `with-stacking` allowance expression.
@@ -227,13 +213,12 @@ fn check_allowance_with_stacking(
227
213
checker : & mut TypeChecker ,
228
214
args : & [ SymbolicExpression ] ,
229
215
context : & TypingContext ,
230
- _parent_expr : & NativeFunctions ,
231
- ) -> Result < ( ) , CheckError > {
216
+ ) -> Result < bool , CheckError > {
232
217
check_argument_count ( 1 , args) ?;
233
218
234
219
checker. type_check_expects ( & args[ 0 ] , context, & TypeSignature :: UIntType ) ?;
235
220
236
- Ok ( ( ) )
221
+ Ok ( false )
237
222
}
238
223
239
224
/// Type check an `with-all-assets-unsafe` allowance expression.
@@ -242,13 +227,8 @@ fn check_allowance_all(
242
227
_checker : & mut TypeChecker ,
243
228
args : & [ SymbolicExpression ] ,
244
229
_context : & TypingContext ,
245
- parent_expr : & NativeFunctions ,
246
- ) -> Result < ( ) , CheckError > {
230
+ ) -> Result < bool , CheckError > {
247
231
check_argument_count ( 0 , args) ?;
248
232
249
- if parent_expr != & NativeFunctions :: AsContractSafe {
250
- return Err ( CheckErrors :: WithAllAllowanceNotAllowed . into ( ) ) ;
251
- }
252
-
253
- Ok ( ( ) )
233
+ Ok ( true )
254
234
}
0 commit comments