Пример #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:
                    payload_data = lz4.block.decompress(
                        payload_data, uncompressed_size=self.PAYLOAD_MAX_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()
Пример #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()
Пример #3
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)
Пример #4
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)
Пример #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)
Пример #6
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()
Пример #7
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 Nodecapbility or inherited
Пример #8
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)
Пример #9
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")
Пример #10
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)
Пример #11
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)
Пример #12
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")
Пример #13
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()