예제 #1
0
파일: block.py 프로젝트: CeON/pmpi
    def _from_raw_without_verifying(cls, raw):
        buffer = BytesIO(raw)

        if read_uint32(buffer) != cls.VERSION:
            raise RawFormatError("version number mismatch")

        previous_block_rev = BlockRev.from_id(read_bytes(buffer, 32))
        timestamp = read_uint32(buffer)
        operations_limit = read_uint32(buffer)

        operations_ids = [read_bytes(buffer, 32) for _ in range(read_uint32(buffer))]
        difficulty = read_uint32(buffer)
        padding = read_uint32(buffer)
        checksum = read_bytes(buffer, 32)
        public_key_der = read_sized_bytes(buffer)
        signature = read_sized_bytes(buffer)

        if len(buffer.read()) > 0:
            raise RawFormatError("raw input too long")

        if int.from_bytes(previous_block_rev.id, 'big') == 0:
            previous_block_rev = BlockRev()

        block = cls(previous_block_rev, timestamp, operations_ids)
        block.operations_limit = operations_limit
        block.difficulty = difficulty
        block.padding = padding
        block.__checksum = checksum
        block.sign(PublicKey(public_key_der), signature)

        return block
예제 #2
0
파일: block.py 프로젝트: CeON/pmpi
    def from_raw_with_operations(cls, raw):
        buffer = BytesIO(raw)
        operations = [pmpi.operation.Operation.from_raw(read_sized_bytes(buffer)) for _ in range(read_uint32(buffer))]

        return cls.__from_raw_and_operations(buffer.read(), operations)