Exemplo n.º 1
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.
        """
        self.config = MessageConfig(reader.read_uint8())
        x = reader.read_uint8()
        self.type = MessageType(x)
        # self.type = MessageType(reader.read_uint8())

        payload_data = reader.read_var_bytes(self.PAYLOAD_MAX_SIZE)
        if len(payload_data) > 0:
            if MessageConfig.COMPRESSED in self.config:
                # From the lz4 documentation:
                # "The uncompressed_size argument specifies an upper bound on the size of the uncompressed data size
                # rather than an absolute value"
                try:
                    size = int.from_bytes(payload_data[:4], 'little')
                    payload_data = lz4.block.decompress(payload_data[4:],
                                                        uncompressed_size=size)
                except lz4.block.LZ4BlockError:
                    raise ValueError(
                        "Invalid payload data - decompress failed")

            self.payload = self._payload_from_data(self.type, payload_data)

        if self.payload is None:
            self.payload = payloads.EmptyPayload()
Exemplo n.º 2
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.
        """
        self.type = ConsensusMessageType(reader.read_uint8())
        self.view_number = reader.read_uint8()
Exemplo n.º 3
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.
        """
        self.hash = reader.read_serializable(types.UInt160)
        self.method = reader.read_var_string(32)
        self.parameters_count = reader.read_uint16()
        self.has_return_value = bool(reader.read_uint8())
        self.call_flags = contracts.CallFlags(reader.read_uint8())
Exemplo n.º 4
0
 def _deserialize_without_type(self,
                               reader: serialization.BinaryReader) -> None:
     self.id = reader.read_uint64()
     self.code = OracleReponseCode(reader.read_uint8())
     self.result = reader.read_var_bytes(self._MAX_RESULT_SIZE)
     if self.code != OracleReponseCode.SUCCESS and len(self.result) > 0:
         raise ValueError(
             f"Deserialization error - oracle response: {self.code}")
Exemplo n.º 5
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.
        """
        self.type = InventoryType(reader.read_uint8())
        self.hashes = reader.read_serializable_list(types.UInt256)
Exemplo n.º 6
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.
        """
        self.usage = TransactionAttributeUsage(reader.read_uint8())
        self.data = reader.read_var_bytes(max=252)
Exemplo n.º 7
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.
        """
        self.type = NodeCapabilityType(reader.read_uint8())
        self.deserialize_without_type(reader)
Exemplo n.º 8
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.
        """
        if reader.read_uint8() != self.type_.value:
            raise ValueError("Deserialization error - transaction attribute type mismatch")
        self._deserialize_without_type(reader)
Exemplo n.º 9
0
    def deserialize_from(reader: serialization.BinaryReader) -> NodeCapability:
        capability_type = NodeCapabilityType(reader.read_uint8())
        if capability_type in [
                NodeCapabilityType.TCPSERVER, NodeCapabilityType.WSSERVER
        ]:
            capability = ServerCapability(
                capability_type)  # type: NodeCapability
        elif capability_type == NodeCapabilityType.FULLNODE:
            capability = FullNodeCapability()

        capability.deserialize_without_type(reader)
        return capability  # a type of NodeCapability or inherited
Exemplo n.º 10
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.
        """
        self.filter = reader.read_var_bytes(max=36000)
        self.K = reader.read_uint8()
        if self.K > 50:
            raise ValueError("Deserialization error - K exceeds limit of 50")
        self.tweak = reader.read_uint32()
Exemplo n.º 11
0
 def deserialize_from(reader: serialization.BinaryReader) -> TransactionAttribute:
     """
     Deserialize from a binary stream into a new TransactionAttribute
     """
     attribute_type = reader.read_uint8()
     for sub in TransactionAttribute.__subclasses__():
         child = sub._serializable_init()  # type: ignore
         if child.type_.value == attribute_type:
             child._deserialize_without_type(reader)
             return child
     else:
         raise ValueError("Deserialization error - unknown transaction attribute type")
Exemplo n.º 12
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.

        Raises:
            ValueError: if the validation byte is not 1
        """
        self.deserialize_unsigned(reader)
        if reader.read_uint8() != 1:
            raise ValueError("Deserialization error - validation byte not 1")
        self.witness = reader.read_serializable(payloads.Witness)
Exemplo n.º 13
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.

        Raises:
            ValueError: if the check byte does not equal.
        """
        super(Header, self).deserialize(reader)
        tmp = reader.read_uint8()
        if tmp != 0:
            raise ValueError("Deserialization error")
Exemplo n.º 14
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.

        Raises:
            ValueError: if no witnesses are found.
        """
        self.deserialize_unsigned(reader)
        witness_obj_count = reader.read_uint8()
        if witness_obj_count != 1:
            raise ValueError(f"Deserialization error - Witness object count is {witness_obj_count} must be 1")
        self.witness = reader.read_serializable(payloads.Witness)
Exemplo n.º 15
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.
        """
        self.account = reader.read_serializable(types.UInt160)
        self.scope = payloads.WitnessScope(reader.read_uint8())

        if payloads.WitnessScope.CUSTOM_CONTRACTS in self.scope:
            self.allowed_contracts = reader.read_serializable_list(
                types.UInt160)

        if payloads.WitnessScope.CUSTOM_GROUPS in self.scope:
            self.allowed_groups = reader.read_serializable_list(
                cryptography.EllipticCurve.ECPoint)
Exemplo n.º 16
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.
        """
        self.account = reader.read_serializable(types.UInt160)
        self.scope = payloads.WitnessScope(reader.read_uint8())

        if payloads.WitnessScope.GLOBAL in self.scope and self.scope != payloads.WitnessScope.GLOBAL:
            raise ValueError("Deserialization error - invalid scope. GLOBAL scope not allowed with other scope types")

        if payloads.WitnessScope.CUSTOM_CONTRACTS in self.scope:
            self.allowed_contracts = reader.read_serializable_list(types.UInt160)

        if payloads.WitnessScope.CUSTOM_GROUPS in self.scope:
            self.allowed_groups = reader.read_serializable_list(cryptography.ECPoint,  # type: ignore
                                                                max=self.MAX_SUB_ITEMS)
Exemplo n.º 17
0
 def deserialize_unsigned(self, reader: serialization.BinaryReader) -> None:
     self.version = reader.read_uint8()
     if self.version > 0:
         raise ValueError("Deserialization error - invalid version")
     self.nonce = reader.read_uint32()
     self.sender = reader.read_serializable(types.UInt160)
     self.system_fee = reader.read_int64()
     if self.system_fee < 0:
         raise ValueError("Deserialization error - negative system fee")
     self.network_fee = reader.read_int64()
     if self.network_fee < 0:
         raise ValueError("Deserialization error - negative network fee")
     # Impossible overflow, only applicable to the C# implementation where they use longs
     # if (self.system_fee + self.network_fee < self.system_fee):
     #     raise ValueError("Deserialization error - overflow")
     self.valid_until_block = reader.read_uint32()
     self.attributes = reader.read_serializable_list(TransactionAttribute)
     self.cosigners = reader.read_serializable_list(payloads.Cosigner)
     self.script = reader.read_var_bytes(max=65535)
     if len(self.script) == 0:
         raise ValueError("Deserialization error - invalid script length 0")
Exemplo n.º 18
0
 def deserialize_unsigned(self, reader: serialization.BinaryReader) -> None:
     self.version = reader.read_uint8()
     if self.version > 0:
         raise ValueError("Deserialization error - invalid version")
     self.nonce = reader.read_uint32()
     self.system_fee = reader.read_int64()
     if self.system_fee < 0:
         raise ValueError("Deserialization error - negative system fee")
     self.network_fee = reader.read_int64()
     if self.network_fee < 0:
         raise ValueError("Deserialization error - negative network fee")
     # Impossible overflow, only applicable to the C# implementation where they use longs
     # if (self.system_fee + self.network_fee < self.system_fee):
     #     raise ValueError("Deserialization error - overflow")
     self.valid_until_block = reader.read_uint32()
     self.signers = Transaction._deserialize_signers(
         reader, self.MAX_TRANSACTION_ATTRIBUTES)
     self.attributes = Transaction._deserialize_attributes(
         reader, self.MAX_TRANSACTION_ATTRIBUTES - len(self.signers))
     self.script = reader.read_var_bytes(max=65535)
     if len(self.script) == 0:
         raise ValueError("Deserialization error - invalid script length 0")
Exemplo n.º 19
0
 def deserialize(self, reader: BinaryReader) -> None:
     """"""
     self._attr_for_test = reader.read_uint8()
Exemplo n.º 20
0
 def deserialize_special(self, reader: serialization.BinaryReader) -> None:
     """ Internal use only - deserialize the data from the stream into a TX that includes the unofficial fields """
     self.deserialize(reader)
     self.vm_state = VMState(reader.read_uint8())
     self.block_height = reader.read_uint32()
Exemplo n.º 21
0
 def deserialize(self, reader: serialization.BinaryReader) -> None:
     self.a = reader.read_uint8()
Exemplo n.º 22
0
 def deserialize(self, reader: serialization.BinaryReader) -> None:
     self.deserialize_unsigned(reader)
     if reader.read_uint8() != 1:
         raise ValueError("Deserialization error - check byte incorrect")
     self.witness = reader.read_serializable(payloads.Witness)
Exemplo n.º 23
0
 def deserialize_special(self, reader: serialization.BinaryReader) -> None:
     self.deserialize(reader)
     self.vm_state = VMState(reader.read_uint8())
     self.block_height = reader.read_uint32()
Exemplo n.º 24
0
 def deserialize(self, reader: serialization.BinaryReader) -> None:
     self.hash = reader.read_serializable(types.UInt160)
     self.method = reader.read_var_string(32)
     self.parameters_count = reader.read_uint16()
     self.has_return_value = bool(reader.read_uint8())
     self.call_flags = contracts.CallFlags(reader.read_uint8())