|
17 | 17 | use stacks_common::types::StacksEpochId;
|
18 | 18 |
|
19 | 19 | use super::{
|
20 |
| - check_argument_count, check_arguments_at_least, check_arguments_at_most, |
21 |
| - compute_typecheck_cost, no_type, TypeChecker, TypingContext, |
| 20 | + TypeChecker, TypingContext, check_argument_count, check_arguments_at_least, |
| 21 | + check_arguments_at_most, compute_typecheck_cost, no_type, |
22 | 22 | };
|
23 | 23 | use crate::vm::analysis::errors::{CheckError, CheckErrors, SyntaxBindingErrorType};
|
24 | 24 | use crate::vm::costs::cost_functions::ClarityCostFunction;
|
25 |
| -use crate::vm::costs::{analysis_typecheck_cost, runtime_cost, CostErrors, CostTracker}; |
| 25 | +use crate::vm::costs::{CostErrors, CostTracker, analysis_typecheck_cost, runtime_cost}; |
26 | 26 | use crate::vm::diagnostic::DiagnosableError;
|
27 |
| -use crate::vm::functions::{handle_binding_list, NativeFunctions}; |
| 27 | +use crate::vm::functions::{NativeFunctions, handle_binding_list}; |
28 | 28 | use crate::vm::types::signatures::{
|
29 |
| - CallableSubtype, FunctionArgSignature, FunctionReturnsSignature, SequenceSubtype, ASCII_40, |
| 29 | + ASCII_40, CallableSubtype, FunctionArgSignature, FunctionReturnsSignature, SequenceSubtype, |
30 | 30 | TO_ASCII_MAX_BUFF, TO_ASCII_RESPONSE_STRING, UTF8_40,
|
31 | 31 | };
|
32 | 32 | use crate::vm::types::{
|
33 |
| - BlockInfoProperty, BufferLength, BurnBlockInfoProperty, FixedFunction, FunctionArg, |
34 |
| - FunctionSignature, FunctionType, PrincipalData, StacksBlockInfoProperty, TenureInfoProperty, |
35 |
| - TupleTypeSignature, TypeSignature, Value, BUFF_1, BUFF_20, BUFF_32, BUFF_33, BUFF_64, BUFF_65, |
36 |
| - MAX_VALUE_SIZE, |
| 33 | + BUFF_1, BUFF_20, BUFF_32, BUFF_33, BUFF_64, BUFF_65, BlockInfoProperty, BufferLength, |
| 34 | + BurnBlockInfoProperty, FixedFunction, FunctionArg, FunctionSignature, FunctionType, |
| 35 | + MAX_VALUE_SIZE, PrincipalData, StacksBlockInfoProperty, TenureInfoProperty, TupleTypeSignature, |
| 36 | + TypeSignature, Value, |
37 | 37 | };
|
38 | 38 | use crate::vm::{ClarityName, ClarityVersion, SymbolicExpression, SymbolicExpressionType};
|
39 | 39 |
|
@@ -819,6 +819,42 @@ fn check_get_tenure_info(
|
819 | 819 | Ok(TypeSignature::new_option(block_info_prop.type_result())?)
|
820 | 820 | }
|
821 | 821 |
|
| 822 | +fn check_restrict_assets( |
| 823 | + checker: &mut TypeChecker, |
| 824 | + args: &[SymbolicExpression], |
| 825 | + context: &TypingContext, |
| 826 | +) -> Result<TypeSignature, CheckError> { |
| 827 | + check_arguments_at_least(3, args)?; |
| 828 | + |
| 829 | + let asset_owner = &args[0]; |
| 830 | + let allowance_list = args[1].match_list().ok_or(CheckError::new( |
| 831 | + CheckErrors::RestrictAssetsExpectedListOfAllowances, |
| 832 | + ))?; |
| 833 | + let body_exprs = &args[2..]; |
| 834 | + |
| 835 | + runtime_cost( |
| 836 | + ClarityCostFunction::AnalysisListItemsCheck, |
| 837 | + checker, |
| 838 | + allowance_list.len() + body_exprs.len(), |
| 839 | + )?; |
| 840 | + |
| 841 | + checker.type_check_expects(asset_owner, context, &TypeSignature::PrincipalType)?; |
| 842 | + |
| 843 | + // TODO: type-check the allowances |
| 844 | + |
| 845 | + // Check the body expressions, ensuring any intermediate responses are handled |
| 846 | + let mut last_return = None; |
| 847 | + for expr in body_exprs { |
| 848 | + let type_return = checker.type_check(expr, context)?; |
| 849 | + if type_return.is_response_type() { |
| 850 | + return Err(CheckErrors::UncheckedIntermediaryResponses.into()); |
| 851 | + } |
| 852 | + last_return = Some(type_return); |
| 853 | + } |
| 854 | + |
| 855 | + last_return.ok_or_else(|| CheckError::new(CheckErrors::CheckerImplementationFailure)) |
| 856 | +} |
| 857 | + |
822 | 858 | impl TypedNativeFunction {
|
823 | 859 | pub fn type_check_application(
|
824 | 860 | &self,
|
@@ -1209,6 +1245,7 @@ impl TypedNativeFunction {
|
1209 | 1245 | CheckErrors::Expects("FATAL: Legal Clarity response type marked invalid".into())
|
1210 | 1246 | })?,
|
1211 | 1247 | ))),
|
| 1248 | + RestrictAssets => Special(SpecialNativeFunction(&check_restrict_assets)), |
1212 | 1249 | };
|
1213 | 1250 |
|
1214 | 1251 | Ok(out)
|
|
0 commit comments