Beispiel #1
0
    def __init__(self):
        from boa3.model.type.type import Type
        from boa3.model.type.primitive.bytestringtype import ByteStringType

        identifier = 'memory_search'
        native_identifier = 'memorySearch'
        byte_string_type = ByteStringType.build()

        args: Dict[str, Variable] = {
            'mem': Variable(byte_string_type),
            'value': Variable(byte_string_type),
            'start': Variable(Type.int),
            'backward': Variable(Type.bool),
        }

        start_default = set_internal_call(
            ast.parse("{0}".format(Type.int.default_value)).body[0].value)
        backward_default = set_internal_call(
            ast.parse("{0}".format(Type.bool.default_value)).body[0].value)

        super().__init__(identifier,
                         native_identifier,
                         args,
                         defaults=[start_default, backward_default],
                         return_type=Type.int)
Beispiel #2
0
    def __init__(self):
        from boa3.model.type.type import Type

        args: Dict[str, Variable] = {
            'self': Variable(Type.str),
            'value': Variable(Type.str),
            'start': Variable(Type.int),
            'end': Variable(Type.union.build([Type.int, Type.none])),
        }

        start_default = set_internal_call(
            ast.parse("{0}".format(Type.int.default_value)).body[0].value)
        end_default = set_internal_call(
            ast.parse("{0}".format(Type.none.default_value)).body[0].value)

        super().__init__(args, [start_default, end_default])
Beispiel #3
0
    def __init__(self):
        from boa3.model.type.collection.sequence.uint160type import UInt160Type
        from boa3.model.builtin.interop.contract.callflagstype import CallFlagsType
        from boa3.model.type.type import Type
        identifier = 'call_contract'
        syscall = 'System.Contract.Call'

        call_flags = CallFlagsType.build()
        args: Dict[str, Variable] = {
            'script_hash': Variable(UInt160Type.build()),
            'method': Variable(Type.str),
            'args':
            Variable(Type.sequence),  # TODO: change when *args is implemented
            'call_flags': Variable(call_flags)
        }
        args_default = ast.parse("{0}".format(
            Type.sequence.default_value)).body[0].value
        call_flags_default = set_internal_call(
            ast.parse(
                "{0}.{1}".format(call_flags.identifier,
                                 call_flags.default_value.name)).body[0].value)

        super().__init__(identifier,
                         syscall,
                         args,
                         defaults=[args_default, call_flags_default],
                         return_type=Type.any)
    def __init__(self):
        from boa3.model.type.type import Type
        from boa3.model.builtin.interop.storage.storagecontext.storagecontexttype import StorageContextType
        from boa3.model.type.primitive.bytestringtype import ByteStringType

        identifier = 'put'
        syscall = 'System.Storage.Put'
        context_type = StorageContextType.build()
        byte_string_type = ByteStringType.build()

        args: Dict[str, Variable] = {
            'key': Variable(byte_string_type),
            'value': Variable(Type.union.build([byte_string_type, Type.int])),
            'context': Variable(context_type)
        }

        from boa3.model.builtin.interop.storage.storagegetcontextmethod import StorageGetContextMethod
        default_id = StorageGetContextMethod(context_type).identifier
        context_default = set_internal_call(
            ast.parse("{0}()".format(default_id)).body[0].value)
        super().__init__(identifier,
                         syscall,
                         args,
                         defaults=[context_default],
                         return_type=Type.none)
Beispiel #5
0
    def __init__(self,
                 find_options_type: FindOptionsType,
                 prefix_type: IType = None):
        from boa3.model.type.type import Type
        from boa3.model.builtin.interop.storage.storagecontext.storagecontexttype import StorageContextType

        identifier = 'find'
        syscall = 'System.Storage.Find'
        context_type = StorageContextType.build()

        if prefix_type is None:
            from boa3.model.type.primitive.bytestringtype import ByteStringType
            prefix_type = ByteStringType.build()

        args: Dict[str, Variable] = {
            'prefix': Variable(prefix_type),
            'context': Variable(context_type),
            'options': Variable(find_options_type)
        }

        from boa3.model.builtin.interop.iterator import IteratorType
        return_type = IteratorType.build(
            Type.dict.build([
                prefix_type,  # return an Iterator[prefix, bytes]
                Type.bytes
            ]))

        from boa3.model.builtin.interop.storage.storagegetcontextmethod import StorageGetContextMethod
        default_id = StorageGetContextMethod(context_type).identifier
        context_default = set_internal_call(
            ast.parse("{0}()".format(default_id)).body[0].value)
        options_default = set_internal_call(
            ast.parse("{0}.{1}".format(
                find_options_type.identifier,
                find_options_type.default_value.name)).body[0].value)

        defaults = [context_default, options_default]

        super().__init__(identifier,
                         syscall,
                         args,
                         defaults=defaults,
                         return_type=return_type)
Beispiel #6
0
    def __init__(self):
        from boa3.model.type.type import Type
        identifier = constants.DEPLOY_METHOD_ID
        args: Dict[str, Variable] = {
            'data': Variable(Type.any),
            'update': Variable(Type.bool)
        }
        super().__init__(identifier, args, return_type=Type.none)

        self.is_public = True
        self._origin_node = set_internal_call(ast.parse(self._body).body[0])
Beispiel #7
0
    def update_args(self, args: ast.arguments, origin: Optional[ISymbol] = None):
        if isinstance(origin, UserClass) and len(args.args) == 1 and args.args[0].annotation is None:
            # the user doesn't need to explicitly write the type of the first argument if it's a classmethod
            # the first argument is a Type[Class]
            cls_type = metatype.metaType.build(origin)
            cls_type_annotation = (cls_type.meta_identifier
                                   if isinstance(cls_type, metatype.MetaType)
                                   else cls_type.identifier)

            cls_ast_annotation = ast.parse(cls_type_annotation).body[0].value
            cls_ast_annotation = set_internal_call(cls_ast_annotation)
            args.args[0].annotation = cls_ast_annotation
Beispiel #8
0
    def __init__(self, notification_type: NotificationType):
        from boa3.model.type.collection.sequence.uint160type import UInt160Type
        from boa3.model.type.type import Type

        identifier = 'get_notifications'
        syscall = 'System.Runtime.GetNotifications'
        uint160 = UInt160Type.build()

        args: Dict[str, Variable] = {'script_hash': Variable(uint160)}
        args_default = set_internal_call(
            ast.parse("{0}()".format(uint160.raw_identifier)).body[0].value)

        super().__init__(identifier,
                         syscall,
                         args, [args_default],
                         return_type=Type.list.build([notification_type]))
Beispiel #9
0
    def __init__(self,
                 args: Dict[str, Variable] = None,
                 vararg: Optional[Tuple[str, Variable]] = None,
                 kwargs: Optional[Dict[str, Variable]] = None,
                 defaults: List[ast.AST] = None,
                 return_type: IType = Type.none,
                 is_public: bool = False,
                 decorators: List[Callable] = None,
                 external_name: str = None,
                 is_safe: bool = False,
                 origin_node: Optional[ast.AST] = None):

        if args is None:
            args = {}
        self.args: Dict[str, Variable] = args.copy()

        if not isinstance(defaults, list):
            defaults = []
        self.defaults: List[ast.AST] = defaults

        self._vararg: Optional[Tuple[str, Variable]] = None
        if (isinstance(vararg, tuple) and len(vararg) == 2
                and isinstance(vararg[0], str)
                and isinstance(vararg[1], Variable)):

            from boa3.model.type.typeutils import TypeUtils

            vararg_id, vararg_var = vararg
            if vararg_var.type is not Type.any:
                default_code = "{0}({1}, {2})".format(
                    TypeUtils.cast.raw_identifier,
                    Type.tuple.build_collection(vararg_var.type),
                    Type.tuple.default_value)
            else:
                default_code = "{0}".format(Type.tuple.default_value)

            default_value = set_internal_call(
                ast.parse(default_code).body[0].value)

            self.args[vararg_id] = Variable(
                Type.tuple.build_collection([vararg_var.type]))
            self.defaults.append(default_value)
            self._vararg = vararg

        if kwargs is None:
            kwargs = {}
        self._kwargs: Dict[str, Variable] = kwargs.copy()

        self.return_type: IType = return_type

        if decorators is None:
            decorators = []
        from boa3.model.decorator import IDecorator
        self.decorators: List[IDecorator] = [
            decorator for decorator in decorators
            if isinstance(decorator, IDecorator)
        ]

        from boa3.model.builtin.decorator import PublicDecorator
        public_decorator = next((decorator for decorator in self.decorators
                                 if isinstance(decorator, PublicDecorator)),
                                None)

        self.is_public: bool = is_public or public_decorator is not None
        if self.is_public:
            if isinstance(public_decorator, PublicDecorator):
                external_name = public_decorator.name
            elif self.defined_by_entry:
                external_name = None

        self.external_name: Optional[str] = external_name
        self.is_safe: bool = is_safe or (isinstance(
            public_decorator, PublicDecorator) and public_decorator.safe)

        self._self_calls: Set[ast.AST] = set()

        super().__init__(origin_node)

        self.init_address: Optional[int] = None
        self.init_bytecode: Optional[VMCode] = None
        self.init_defaults_bytecode: Optional[VMCode] = None
        self.end_bytecode: Optional[VMCode] = None