def __init__(self, self_type: IByteStringType = None): from boa3.model.type.type import Type if not isinstance(self_type, IByteStringType): from boa3.model.type.primitive.bytestringtype import ByteStringType self_type = ByteStringType.build() identifier = 'strip' args: Dict[str, Variable] = { 'self': Variable(self_type), 'chars': Variable(self_type), } from string import whitespace # whitespace is ' \t\n\r\v\f', but it needs to be r' \t\n\r\v\f' # encode('unicode-escape') will make it a bytes equivalent of r' \t\n\r\v\f' and # decode() will convert it back to str whitespace_chars = [ char.encode('unicode-escape').decode() for char in whitespace ] if Type.str.is_type_of(self_type): chars_default = ast.parse("'{0}'".format( ''.join(whitespace_chars))).body[0].value else: chars_default = ast.parse("b'{0}'".format( ''.join(whitespace_chars))).body[0].value super().__init__(identifier, args, defaults=[chars_default], return_type=self_type)
def build(self, value: Any) -> IBuiltinMethod: if not isinstance(value, (Sized, Iterable)): return self num_args: int = len(self.args) if len(value) != num_args or any( not isinstance(exp, (IExpression, IType)) for exp in value[:num_args]): return self exp = [ exp if isinstance(exp, IExpression) else Variable(exp) for exp in value ] if not self.validate_parameters(*exp): return self key_type: IType = exp[0].type value_type: IType = exp[1].type if self.key_arg.type.is_type_of( key_type) and self.value_arg.type.is_type_of(value_type): return self method: InteropMethod = StoragePutMethod() method.args['key'] = Variable(key_type) method.args['value'] = Variable(value_type) return method
def build(self, value: Any) -> IBuiltinMethod: exp: List[IExpression] = [] if isinstance(value, Sized): if len(value) > 1 or not isinstance(value, Iterable): return self exp = [ exp if isinstance(exp, IExpression) else Variable(exp) for exp in value if isinstance(exp, (IExpression, IType)) ] elif isinstance(exp, (IExpression, IType)): exp = [ value if isinstance(value, IExpression) else Variable(value) ] else: return self if not self.validate_parameters(*exp): return self method = self prefix_type: IType = exp[0].type if type(method.prefix_arg.type) != type(prefix_type): method = StorageFindMethod(self.options_arg.type, prefix_type) return method
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, prefix_type: IType = None): from boa3.model.type.type import Type from boa3.model.builtin.interop.storage.storagecontexttype import StorageContextType identifier = 'find' syscall = 'System.Storage.Find' context_type = StorageContextType.build() if prefix_type is None: prefix_type = Type.union.build([Type.bytes, Type.str]) args: Dict[str, Variable] = { 'prefix': Variable(prefix_type), 'context': Variable(context_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 = ast.parse("{0}()".format(default_id)).body[0].value context_default.is_internal_call = True context_default._fields += ('is_internal_call', ) super().__init__(identifier, syscall, args, defaults=[context_default], return_type=return_type)
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)
def build(self, value: Any) -> IBuiltinMethod: exp: List[IExpression] = [] if isinstance(value, Sized): if len(value) > 2 or not isinstance(value, Iterable): return self exp = [ exp if isinstance(exp, IExpression) else Variable(exp) for exp in value if isinstance(exp, (IExpression, IType)) ] elif isinstance(exp, (IExpression, IType)): exp = [ value if isinstance(value, IExpression) else Variable(value) ] else: return self if not self.validate_parameters(*exp): return self method = self key_type: IType = exp[0].type if not method.key_arg.type.is_type_of(key_type): method = StorageDeleteMethod() method.args['key'] = Variable(key_type) return method
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)
def __init__(self): from boa3.model.type.type import Type identifier = 'put' syscall = 'System.Storage.Put' self._storage_context = 'System.Storage.GetContext' # TODO: refactor when default arguments are implemented args: Dict[str, Variable] = {'key': Variable(Type.bytes), 'value': Variable(Type.bytes)} super().__init__(identifier, syscall, args, return_type=Type.none)
def __init__(self): from boa3.model.type.type import Type identifier = 'ceil' args: Dict[str, Variable] = { 'x': Variable(Type.int), 'decimals': Variable(Type.int) } super().__init__(identifier, args, return_type=Type.int)
def __init__(self): from boa3.model.type.type import Type identifier = 'pow' args: Dict[str, Variable] = { 'base': Variable(Type.int), 'exponent': Variable(Type.int), } super().__init__(identifier, args, return_type=Type.int)
def __init__(self): from boa3.model.type.type import Type identifier = 'check_multisig' syscall = 'Neo.Crypto.CheckMultisig' args: Dict[str, Variable] = { 'pubkeys': Variable(Type.list), 'signatures': Variable(Type.list) } super().__init__(identifier, syscall, args, return_type=Type.bool)
def __init__(self): from boa3.model.type.type import Type identifier = 'update_contract' syscall = 'update' args: Dict[str, Variable] = { 'nef_file': Variable(Type.bytes), 'manifest': Variable(Type.bytes) } super().__init__(identifier, syscall, args, return_type=Type.none)
def __init__(self): super().__init__('ContractPermission') from boa3.model.type.type import Type self._variables: Dict[str, Variable] = { 'contract': Variable(Type.str), 'methods': Variable(Type.optional.build(Type.list.build_collection([Type.str]))) } self._constructor: Method = None
def __init__( self ): # TODO: make it so that it can accept the same parameters as Python from boa3.model.type.type import Type identifier = 'min' args: Dict[str, Variable] = { 'val1': Variable(Type.int), 'val2': Variable(Type.int), } super().__init__(identifier, args, return_type=Type.int)
def __init__(self): from boa3.model.type.type import Type identifier = 'check_multisig_with_ecdsa_secp256r1' syscall = 'Neo.Crypto.CheckMultisigWithECDsaSecp256r1' args: Dict[str, Variable] = { 'item': Variable(Type.any), 'pubkeys': Variable(Type.list), 'signatures': Variable(Type.list) } super().__init__(identifier, syscall, args, return_type=Type.bool)
def __init__(self): super().__init__('Notification') from boa3.model.type.type import Type self._variables: Dict[str, Variable] = { 'script_hash': Variable(UInt160Type.build()), 'event_name': Variable(Type.str), 'state': Variable(Type.tuple) } self._constructor: Method = None
def __init__(self, return_type: StorageMapType): from boa3.model.type.type import Type from boa3.model.builtin.interop.storage.storagecontext.storagecontexttype import _StorageContext as StorageContextType identifier = '-StorageMap__init__' args: Dict[str, Variable] = { 'context': Variable(StorageContextType), 'prefix': Variable(Type.union.build([Type.bytes, Type.str])) } super().__init__(identifier, args, return_type=return_type)
def __init__(self): super().__init__('ContractGroup') from boa3.model.type.collection.sequence.ecpointtype import ECPointType from boa3.model.type.type import Type self._variables: Dict[str, Variable] = { 'pubkey': Variable(ECPointType.build()), 'signature': Variable(Type.bytes) } self._constructor: Method = None
def __init__(self): from boa3.model.type.type import Type identifier = 'Nep5TransferEvent' args: Dict[str, Variable] = { 'from_addr': Variable(Type.bytes), 'to_addr': Variable(Type.bytes), 'amount': Variable(Type.int) } super().__init__(identifier, args) self.name = 'transfer'
def __init__(self, transaction_type: TransactionType): from boa3.model.type.collection.sequence.uint256type import UInt256Type from boa3.model.type.type import Type identifier = 'get_transaction_from_block' syscall = 'getTransactionFromBlock' args: Dict[str, Variable] = {'block_hash_or_height': Variable(Type.union.build([UInt256Type.build(), Type.int])), 'tx_index': Variable(Type.int)} super().__init__(identifier, syscall, args, return_type=transaction_type)
def __init__(self): from boa3.model.type.type import Type identifier = 'verify_with_ecdsa_secp256k1' syscall = 'Neo.Crypto.VerifyWithECDsaSecp256k1' args: Dict[str, Variable] = { 'item': Variable(Type.any), 'pubkey': Variable(Type.bytes), 'signature': Variable(Type.bytes) } super().__init__(identifier, syscall, args, return_type=Type.bool)
def __init__(self): super().__init__('ContractParameterDefinition') from boa3.model.builtin.interop.contract.contractmanifest.contractparametertype import ContractParameterType from boa3.model.type.type import Type self._variables: Dict[str, Variable] = { 'name': Variable(Type.str), 'type': Variable(ContractParameterType.build()) } self._constructor: Method = None
def __init__(self, contract_type: ContractType): from boa3.model.type.type import Type identifier = 'create_contract' syscall = 'deploy' args: Dict[str, Variable] = { 'nef_file': Variable(Type.bytes), 'manifest': Variable(Type.bytes) } super().__init__(identifier, syscall, args, return_type=contract_type)
def __init__(self): from boa3.model.builtin.interop.storage.storagemap.storagemaptype import _StorageMap from boa3.model.type.type import Type identifier = 'delete' args: Dict[str, Variable] = { 'self': Variable(_StorageMap), 'key': Variable(Type.union.build([Type.bytes, Type.str])) } super().__init__(identifier, args, return_type=Type.none)
def __init__(self): from boa3.model.type.type import Type from boa3.model.type.collection.sequence.ecpointtype import ECPointType identifier = 'check_multisig' syscall = 'System.Crypto.CheckMultisig' args: Dict[str, Variable] = { 'pubkeys': Variable(Type.list.build_collection([ECPointType.build()])), 'signatures': Variable(Type.list.build_collection([Type.bytes])) } super().__init__(identifier, syscall, args, return_type=Type.bool)
def __init__(self): super().__init__('ContractPermissionDescriptor') from boa3.model.type.collection.sequence.uint160type import UInt160Type from boa3.model.type.collection.sequence.ecpointtype import ECPointType from boa3.model.type.type import Type self._variables: Dict[str, Variable] = { 'hash': Variable(Type.optional.build(UInt160Type.build())), 'group': Variable(Type.optional.build(ECPointType.build())) } self._constructor: Method = None
def __init__(self): super().__init__('NeoAccountState') from boa3.model.type.type import Type from boa3.model.type.collection.sequence.ecpointtype import ECPointType self._variables: Dict[str, Variable] = { 'balance': Variable(Type.int), 'height': Variable(Type.int), 'vote_to': Variable(ECPointType.build()), } self._constructor: Optional[Method] = None
def __init__(self): import ast from boa3.model.type.type import Type identifier = 'CreateNewEvent' args = { 'arguments': Variable(Type.list.build(Type.tuple)), 'event_name': Variable(Type.str) } event_name_default = ast.parse("'{0}'".format(Type.str.default_value) ).body[0].value super().__init__(identifier, args, defaults=[event_name_default], return_type=EventType)
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])