def validate_values(self, *params: Any) -> List[Any]: values = [] if len(params) != 2: return values origin, visitor = params values.append(self.contract_hash) from boa3.analyser.astanalyser import IAstAnalyser if not isinstance(visitor, IAstAnalyser): return values from boa3.exception import CompilerError if not isinstance(origin, ast.Call) or len(origin.args) < 1: visitor._log_error( CompilerError.UnfilledArgument(origin.lineno, origin.col_offset, list(self.args.keys())[0])) return values argument_hash = visitor.visit(origin.args[0]) try: if isinstance(argument_hash, str): from boa3.neo import from_hex_str argument_hash = from_hex_str(argument_hash) if isinstance(argument_hash, bytes): values[0] = UInt160(argument_hash) except BaseException: visitor._log_error( CompilerError.InvalidUsage( origin.lineno, origin.col_offset, "Only literal values are accepted for 'script_hash' argument" )) return values
def validate_values(self, *params: Any) -> List[Any]: values = [] if len(params) != 2: return values origin, visitor = params values.append(self.external_name) from boa3.analyser.astanalyser import IAstAnalyser if not isinstance(visitor, IAstAnalyser): return values from boa3.exception import CompilerError if not isinstance(origin, ast.Call): visitor._log_error( CompilerError.UnfilledArgument(origin.lineno, origin.col_offset, list(self.args.keys())[0])) return values args_names = list(self.args.keys()) if len(origin.args) > len(args_names): visitor._log_error( CompilerError.UnexpectedArgument(origin.lineno, origin.col_offset)) return values # read the called arguments args_len = min(len(origin.args), len(args_names)) values.clear() for x in range(args_len): values.append(visitor.visit(origin.args[x])) if len(values) < 1: values.append(self.external_name) # read the called keyword arguments for kwarg in origin.keywords: if kwarg.arg in args_names: x = args_names.index(kwarg.arg) value = visitor.visit(kwarg.value) values[x] = value else: visitor._log_error( CompilerError.UnexpectedArgument(kwarg.lineno, kwarg.col_offset)) if not isinstance(values[0], str): visitor._log_error( CompilerError.UnfilledArgument(origin.lineno, origin.col_offset, list(self.args.keys())[0])) return values if visitor.get_symbol(values[0]) is not None: visitor._log_error( CompilerError.InvalidUsage( origin.lineno, origin.col_offset, "Only literal values are accepted for 'name' argument")) values[0] = self.external_name return values