Пример #1
0
    def stream_deserialize(cls, f):
        self = super(Block, cls).stream_deserialize(f)
        txs = VectorSerializer.stream_deserialize(Transaction, f)
        stxs = VectorSerializer.stream_deserialize(Transaction, f)

        self.txs = list(txs)
        self.stxs = list(stxs)
        return self
Пример #2
0
    def stream_deserialize(cls, f):
        self = super(Block, cls).stream_deserialize(f)
        txs = VectorSerializer.stream_deserialize(Transaction, f)
        stxs = VectorSerializer.stream_deserialize(Transaction, f)

        self.txs = list(txs)
        self.stxs = list(stxs)
        return self
Пример #3
0
 def deserialize_field(self, tx, kwargs, attr, fmt, num_bytes, f):
     if fmt not in ['inputs', 'outputs', 'bytes']:
         kwargs[attr] = struct.unpack(fmt, ser_read(f, num_bytes))[0]
     elif fmt == 'inputs':
         kwargs[attr] = VectorSerializer.stream_deserialize(CMutableTxIn, f)
     elif fmt == 'outputs':
         kwargs[attr] = VectorSerializer.stream_deserialize(CMutableTxOut, f)
     elif fmt == 'bytes':
         kwargs[attr] =  BytesSerializer.stream_deserialize(f)
Пример #4
0
 def stream_deserialize(cls, f):
     self = cls()
     for attr, fmt, num_bytes, _ in self.fields:
         if fmt not in ['inputs', 'outputs', 'bytes']:
             setattr(self, attr, struct.unpack(fmt, ser_read(f, num_bytes))[0])
         elif fmt == 'inputs':
             setattr(self, attr, VectorSerializer.stream_deserialize(CTxIn, f))
         elif fmt == 'outputs':
             setattr(self, attr, VectorSerializer.stream_deserialize(CTxOut, f))
         elif fmt == 'bytes':
             setattr(self, attr, BytesSerializer.stream_deserialize(f))
     return self
Пример #5
0
 def stream_deserialize(cls, f):
     self = super(Block, cls).stream_deserialize(f)
     vtx = VectorSerializer.stream_deserialize(Transaction, f)
     vMerkleTree = tuple(Block.build_merkle_tree_from_txs(vtx))
     setattr(self, 'vMerkleTree', vMerkleTree)
     setattr(self, 'vtx', tuple(vtx))
     return self
Пример #6
0
 def stream_deserialize(cls, f):
     self = super(Block, cls).stream_deserialize(f)
     vtx = VectorSerializer.stream_deserialize(Transaction, f)
     vMerkleTree = tuple(Block.build_merkle_tree_from_txs(vtx))
     setattr(self, 'vMerkleTree', vMerkleTree)
     setattr(self, 'vtx', tuple(vtx))
     return self
Пример #7
0
    def stream_deserialize(cls, f):
        self = super(CAltcoinBlock, cls).stream_deserialize(f)

        vtx = VectorSerializer.stream_deserialize(CTransaction, f)
        vMerkleTree = tuple(bitcoin.core.CBlock.build_merkle_tree_from_txs(vtx))
        object.__setattr__(self, 'vMerkleTree', vMerkleTree)
        object.__setattr__(self, 'vtx', tuple(vtx))

        return self
Пример #8
0
    def stream_deserialize(cls, f):
        self = super(CAltcoinBlock, cls).stream_deserialize(f)

        vtx = VectorSerializer.stream_deserialize(CTransaction, f)
        vMerkleTree = tuple(bitcoin.core.CBlock.build_merkle_tree_from_txs(vtx))
        object.__setattr__(self, 'vMerkleTree', vMerkleTree)
        object.__setattr__(self, 'vtx', tuple(vtx))

        return self
Пример #9
0
    def stream_deserialize(cls, f):
        self = super(Block, cls).stream_deserialize(f)
        for attr, fmt, num_bytes, _ in self.block_fields:
            if fmt not in ['bytes', 'vectortx']:
                setattr(self, attr, struct.unpack(fmt, ser_read(f, num_bytes))[0])
            elif fmt == 'bytes':
                setattr(self, attr, BytesSerializer.stream_deserialize(f))
            elif fmt == 'vectortx':
                setattr(self, attr, VectorSerializer.stream_deserialize(Transaction, f))

        setattr(self, 'vMerkleTree', tuple(Block.build_merkle_tree_from_txs(getattr(self, 'vtx'))))
        return self
Пример #10
0
    def deserialize_prefix(self, f):
        """Deserialize the transaction prefix."""
        txin_count = VarIntSerializer.stream_deserialize(f)
        txins = []
        for i in range(txin_count):
            txin = TxIn()
            txin.deserialize_prefix(f)
            txins.append(txin)

        txouts = VectorSerializer.stream_deserialize(TxOut, f)
        locktime = struct.unpack(b'<I', ser_read(f, 4))[0]
        expiry = struct.unpack(b'<I', ser_read(f, 4))[0]

        self.txins = list(txins)
        self.txouts = list(txouts)
        self.locktime = locktime
        self.expiry = expiry
Пример #11
0
 def stream_deserialize(cls, f):
     nVersion = struct.unpack(b"<i", ser_read(f, 4))[0]
     vInterested = VectorSerializer.stream_deserialize(CInterested, f)
     return cls(vInterested=vInterested, protover=nVersion)
Пример #12
0
    def stream_deserialize(cls, f, **kwargs):
        schema_obj = kwargs['schema_obj'] if 'schema_obj' in kwargs else None
        if not isinstance(schema_obj, Schema):
            raise ValueError(
                f'`schema_obj` parameter must be of Schema type; got `{schema_obj}` instead'
            )

        # Deserialize proof header
        # - version with flag
        (ver, flag) = FlagVarIntSerializer.stream_deserialize(f)
        # - fields common for root and upgrade proofs
        if flag:
            schema = Hash256Id.stream_deserialize(f)
            network = VarIntSerializer.stream_deserialize(f)
            if network is 0x00:
                format = ProofFormat.upgrade
            # - root-specific fields
            else:
                network = Network(network)
                format = ProofFormat.root
                root = OutPoint.stream_deserialize(f, short=False)
        else:
            format = ProofFormat.ordinary

        # Deserialize proof body
        # - reading proof type
        type_no = ser_read(f, 1)[0]

        # - reading `seal_sequence` structure
        seals = []
        seal_type_no = 0
        # -- we iterate over the seals until 0xFF (=FlagVarIntSerializer.Separator.EOF) byte is met
        while True:
            try:
                # -- reading seal with the current type number
                seal = Seal.stream_deserialize(f,
                                               type_no=seal_type_no,
                                               schema_obj=schema_obj)
            except BaseException as ex:
                # due to some strange bug, python 3 is unable to capture SeparatorByteSignal exception by its type,
                # and `isinstance(ex, SeparatorByteSignal)` returns False as well :(
                # so we have to capture generic exception and re-raise if it is not SeparatorByteSignal, which
                # can be determined only by the presence of its method
                if not callable(getattr(ex, "is_eol", None)):
                    raise
                if ex.is_eol():
                    # -- met 0xFE separator byte, increasing current type number
                    seal_type_no = seal_type_no + 1
                elif ex.is_eof():
                    # -- end of `seal_sequence` structure
                    break
            else:
                # -- otherwise append read seal to the list of seals
                seals.append(seal)

        # -- if we had zero seals implies proof of state destruction format
        if len(seals) is 0:
            format = ProofFormat.burn

        # - reading unparsed state and metadata bytes
        state = BytesSerializer.stream_deserialize(f)
        metadata = BytesSerializer.stream_deserialize(f)

        # Deserialize original public key
        pkcode = ser_read(f, 1)
        if pkcode is 0x00:
            pubkey = None
        else:
            buf = pkcode + ser_read(f, 32)
            pubkey = PubKey.deserialize(buf)

        # Deserialize prunable data
        try:
            pruned_flag = ser_read(f, 1)
        except:
            pruned_flag = 0x00

        txid, parents = None, None
        if pruned_flag & 0x01 > 0:
            txid = Hash256Id.stream_deserialize(f)
        if pruned_flag & 0x02 > 0:
            parents = VectorSerializer.stream_deserialize(Hash256Id, f)

        proof = Proof(schema_obj=schema_obj,
                      type_no=type_no,
                      ver=ver,
                      format=format,
                      schema=schema,
                      network=network,
                      root=root,
                      pubkey=pubkey,
                      fields=None,
                      seals=seals,
                      txid=txid,
                      parents=parents,
                      metadata=metadata,
                      state=state)

        # Parsing raw seals and metadata and resolving types against the provided Schema
        if 'schema_obj' in kwargs:
            schema_obj = kwargs['schema_obj']
        if isinstance(schema_obj, Schema):
            proof.resolve_schema(schema_obj)

        return proof
Пример #13
0
 def msg_deser(cls, f, protover=PROTO_VERSION):
     inv = VectorSerializer.stream_deserialize(CInv, f)
     return cls(inv)