Exemplo n.º 1
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        self.magic = reader.read_uint32()
        self.compiler = reader.read_bytes(32).decode('utf-8')
        self.version = Version.deserialize_from_bytes(reader.read_bytes(16))
        self.script_hash = reader.read_serializable(types.UInt160)
        self.checksum = reader.read_bytes(4)
        if self.checksum != self.compute_checksum():
            raise ValueError("Deserialization error - invalid checksum")

        self.script = reader.read_var_bytes()
        if self.script_hash != self.compute_script_hash():
            raise ValueError("Deserialization error - invalid script_hash")
Exemplo n.º 2
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        self.magic = reader.read_uint32()
        compiler_with_version = reader.read_bytes(64).decode('utf-8')
        self.compiler, version = compiler_with_version.rsplit('-', maxsplit=1)
        self.version = Version.deserialize_from_bytes(
            version[:32].encode('utf-8'))

        assert reader.read_uint16() == 0  # 2 reserved bytes
        reader.read_var_int(128)  # TODO: method tokens
        assert reader.read_uint16() == 0  # 2 reserved bytes

        self.script = reader.read_var_bytes()
        self.checksum = reader.read_bytes(4)
        if self.checksum != self.compute_checksum():
            raise ValueError("Deserialization error - invalid checksum")
Exemplo n.º 3
0
    def decode_from_reader(self, reader: serialization.BinaryReader) -> EllipticCurve.ECPoint:
        """
        Raises:
            NotImplementedError: if an unsupported point encoding is used
            TypeError: if unexpected encoding is read
        """
        try:
            f = reader.read_byte()
        except ValueError:
            return self.Infinity

        f = int.from_bytes(f, "little")
        if f == 0:
            return self.Infinity

        # these are compressed
        if f == 2 or f == 3:
            yTilde = f & 1
            data = bytearray(reader.read_bytes(32))
            data.reverse()
            data.append(0)
            X1 = int.from_bytes(data, 'little')
            return self.decompress_from_curve(X1, yTilde)

        # uncompressed or hybrid
        elif f == 4 or f == 6 or f == 7:
            raise NotImplementedError()

        raise ValueError(f"Invalid point encoding: {f}")
Exemplo n.º 4
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.
        """
        self._data = bytearray(reader.read_bytes(self._BYTE_LEN))
Exemplo n.º 5
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        version_str = reader.read_bytes(s.uint64 * 4).decode('utf-8')

        import re
        version_str = re.sub(r'\x00+', '', version_str)

        major, minor, build, revision = version_str.split('.')
        self.major = int(major)
        self.minor = int(minor)
        self.build = int(build)
        self.revision = int(revision)
Exemplo n.º 6
0
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.
        """
        self.timestamp = reader.read_uint32()

        full_address_bytes = bytearray(reader.read_bytes(16))
        ip_bytes = full_address_bytes[-4:]
        host = '.'.join(map(lambda b: str(b), ip_bytes))
        port = 0

        capabilities_cnt = reader.read_var_int(VersionPayload.MAX_CAPABILITIES)
        capabilities_list = []
        for _ in range(capabilities_cnt):
            capa = capabilities.NodeCapability.deserialize_from(reader)
            if isinstance(capa, capabilities.ServerCapability):
                port = capa.port
            capabilities_list.append(capa)
        self.capabilities = capabilities_list
        self.address = f"{host}:{port}"