예제 #1
0
파일: block.py 프로젝트: EdgeDLT/neo3-boa
 def deserialize_unsigned(self, reader: serialization.BinaryReader) -> None:
     self.version = reader.read_uint32()
     self.prev_hash = reader.read_serializable(types.UInt256)
     self.merkle_root = reader.read_serializable(types.UInt256)
     self.timestamp = reader.read_uint64()
     self.index = reader.read_uint32()
     self.next_consensus = reader.read_serializable(types.UInt160)
예제 #2
0
파일: block.py 프로젝트: EdgeDLT/neo3-boa
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.

        Raises:
            ValueError: if the content count of the block is zero, or if there is a duplicate transaction in the list,
                or if the merkle root does not included the calculated root.
        """
        super(Block, self).deserialize(reader)
        content_count = reader.read_var_int(max=self.MAX_CONTENTS_PER_BLOCK)
        if content_count == 0:
            raise ValueError("Deserialization error - no contents")

        self.consensus_data = reader.read_serializable(payloads.ConsensusData)
        tx_count = content_count - 1
        for _ in range(tx_count):
            self.transactions.append(
                reader.read_serializable(payloads.Transaction))

        if len(set(self.transactions)) != tx_count:
            raise ValueError(
                "Deserialization error - block contains duplicate transaction")

        hashes = [t.hash() for t in self.transactions]
        if Block.calculate_merkle_root(self.consensus_data.hash(),
                                       hashes) != self.merkle_root:
            raise ValueError("Deserialization error - merkle root mismatch")
예제 #3
0
파일: block.py 프로젝트: EdgeDLT/neo3-boa
    def deserialize(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream.

        Args:
            reader: instance.
        """
        self.hash_start = reader.read_serializable(types.UInt256)
        self.count = reader.read_int16()
예제 #4
0
    def deserialize_unsigned(self, reader: serialization.BinaryReader) -> None:
        """
        Deserialize the object from a binary stream excluding the validation byte + witness.

        Args:
            reader: instance.
        """
        self.version = reader.read_uint32()
        self.prev_hash = reader.read_serializable(types.UInt256)
        self.block_index = reader.read_uint32()
        self.validator_index = reader.read_uint16()
        self.data = reader.read_var_bytes()
예제 #5
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")
예제 #6
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)
예제 #7
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)
예제 #8
0
파일: block.py 프로젝트: EdgeDLT/neo3-boa
    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)
예제 #9
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")
예제 #10
0
파일: block.py 프로젝트: EdgeDLT/neo3-boa
 def deserialize(self, reader: serialization.BinaryReader) -> None:
     super(TrimmedBlock, self).deserialize(reader)
     self.hashes = reader.read_serializable_list(types.UInt256)
     if len(self.hashes) > 0:
         self.consensus_data = reader.read_serializable(
             payloads.ConsensusData)
예제 #11
0
 def deserialize(self, reader: serialization.BinaryReader) -> None:
     self.contract = reader.read_serializable(types.UInt160)
     self.key = reader.read_bytes_with_grouping(group_size=16)
예제 #12
0
 def deserialize(self, reader: BinaryReader) -> None:
     self.script = reader.read_var_bytes()
     self.manifest = reader.read_serializable(manifest.ContractManifest)