@@ -50,12 +50,9 @@ pub fn check_restrict_assets(
5050 checker. type_check_expects ( asset_owner, context, & TypeSignature :: PrincipalType ) ?;
5151
5252 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+ }
5956 }
6057
6158 // Check the body expressions, ensuring any intermediate responses are handled
@@ -97,12 +94,9 @@ pub fn check_as_contract(
9794 ) ?;
9895
9996 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+ }
106100 }
107101
108102 // Check the body expressions, ensuring any intermediate responses are handled
@@ -133,12 +127,13 @@ pub fn check_allowance_err(
133127 Err ( CheckErrors :: AllowanceExprNotAllowed . into ( ) )
134128}
135129
130+ /// Type check an allowance expression, returning whether it is a
131+ /// `with-all-assets-unsafe` allowance (which has special rules).
136132pub fn check_allowance (
137133 checker : & mut TypeChecker ,
138134 allowance : & SymbolicExpression ,
139135 context : & TypingContext ,
140- parent_expr : & NativeFunctions ,
141- ) -> Result < ( ) , CheckError > {
136+ ) -> Result < bool , CheckError > {
142137 let list = allowance
143138 . match_list ( )
144139 . ok_or ( CheckErrors :: ExpectedListApplication ) ?;
@@ -155,19 +150,13 @@ pub fn check_allowance(
155150 } ;
156151
157152 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) ,
167156 NativeFunctions :: AllowanceWithStacking => {
168- check_allowance_with_stacking ( checker, args, context, parent_expr )
157+ check_allowance_with_stacking ( checker, args, context)
169158 }
170- NativeFunctions :: AllowanceAll => check_allowance_all ( checker, args, context, parent_expr ) ,
159+ NativeFunctions :: AllowanceAll => check_allowance_all ( checker, args, context) ,
171160 _ => Err ( CheckErrors :: ExpectedAllowanceExpr ( function_name. to_string ( ) ) . into ( ) ) ,
172161 }
173162}
@@ -178,13 +167,12 @@ fn check_allowance_with_stx(
178167 checker : & mut TypeChecker ,
179168 args : & [ SymbolicExpression ] ,
180169 context : & TypingContext ,
181- _parent_expr : & NativeFunctions ,
182- ) -> Result < ( ) , CheckError > {
170+ ) -> Result < bool , CheckError > {
183171 check_argument_count ( 1 , args) ?;
184172
185173 checker. type_check_expects ( & args[ 0 ] , context, & TypeSignature :: UIntType ) ?;
186174
187- Ok ( ( ) )
175+ Ok ( false )
188176}
189177
190178/// Type check a `with-ft` allowance expression.
@@ -193,15 +181,14 @@ fn check_allowance_with_ft(
193181 checker : & mut TypeChecker ,
194182 args : & [ SymbolicExpression ] ,
195183 context : & TypingContext ,
196- _parent_expr : & NativeFunctions ,
197- ) -> Result < ( ) , CheckError > {
184+ ) -> Result < bool , CheckError > {
198185 check_argument_count ( 3 , args) ?;
199186
200187 checker. type_check_expects ( & args[ 0 ] , context, & TypeSignature :: PrincipalType ) ?;
201188 checker. type_check_expects ( & args[ 1 ] , context, & ASCII_128 ) ?;
202189 checker. type_check_expects ( & args[ 2 ] , context, & TypeSignature :: UIntType ) ?;
203190
204- Ok ( ( ) )
191+ Ok ( false )
205192}
206193
207194/// Type check a `with-nft` allowance expression.
@@ -210,15 +197,14 @@ fn check_allowance_with_nft(
210197 checker : & mut TypeChecker ,
211198 args : & [ SymbolicExpression ] ,
212199 context : & TypingContext ,
213- _parent_expr : & NativeFunctions ,
214- ) -> Result < ( ) , CheckError > {
200+ ) -> Result < bool , CheckError > {
215201 check_argument_count ( 3 , args) ?;
216202
217203 checker. type_check_expects ( & args[ 0 ] , context, & TypeSignature :: PrincipalType ) ?;
218204 checker. type_check_expects ( & args[ 1 ] , context, & ASCII_128 ) ?;
219205 // Asset ID can be any type
220206
221- Ok ( ( ) )
207+ Ok ( false )
222208}
223209
224210/// Type check a `with-stacking` allowance expression.
@@ -227,13 +213,12 @@ fn check_allowance_with_stacking(
227213 checker : & mut TypeChecker ,
228214 args : & [ SymbolicExpression ] ,
229215 context : & TypingContext ,
230- _parent_expr : & NativeFunctions ,
231- ) -> Result < ( ) , CheckError > {
216+ ) -> Result < bool , CheckError > {
232217 check_argument_count ( 1 , args) ?;
233218
234219 checker. type_check_expects ( & args[ 0 ] , context, & TypeSignature :: UIntType ) ?;
235220
236- Ok ( ( ) )
221+ Ok ( false )
237222}
238223
239224/// Type check an `with-all-assets-unsafe` allowance expression.
@@ -242,13 +227,8 @@ fn check_allowance_all(
242227 _checker : & mut TypeChecker ,
243228 args : & [ SymbolicExpression ] ,
244229 _context : & TypingContext ,
245- parent_expr : & NativeFunctions ,
246- ) -> Result < ( ) , CheckError > {
230+ ) -> Result < bool , CheckError > {
247231 check_argument_count ( 0 , args) ?;
248232
249- if parent_expr != & NativeFunctions :: AsContractSafe {
250- return Err ( CheckErrors :: WithAllAllowanceNotAllowed . into ( ) ) ;
251- }
252-
253- Ok ( ( ) )
233+ Ok ( true )
254234}
0 commit comments