MCPcopy
hub / github.com/petertodd/python-bitcoinlib / stream_deserialize

Method stream_deserialize

bitcoin/core/__init__.py:366–395  ·  view source on GitHub ↗

Deserialize transaction This implementation corresponds to Bitcoin's SerializeTransaction() and consensus behavior. Note that Bitcoin's DecodeHexTx() also has the option to attempt deserializing as a non-witness transaction first, falling back to the consensus behavi

(cls, f)

Source from the content-addressed store, hash-verified

364
365 @classmethod
366 def stream_deserialize(cls, f):
367 """Deserialize transaction
368
369 This implementation corresponds to Bitcoin's SerializeTransaction() and
370 consensus behavior. Note that Bitcoin's DecodeHexTx() also has the
371 option to attempt deserializing as a non-witness transaction first,
372 falling back to the consensus behavior if it fails. The difference lies
373 in transactions which have zero inputs: they are invalid but may be
374 (de)serialized anyway for the purpose of signing them and adding
375 inputs. If the behavior of DecodeHexTx() is needed it could be added,
376 but not here.
377 """
378 # FIXME can't assume f is seekable
379 nVersion = struct.unpack(b"<i", ser_read(f,4))[0]
380 pos = f.tell()
381 markerbyte = struct.unpack(b'B', ser_read(f, 1))[0]
382 flagbyte = struct.unpack(b'B', ser_read(f, 1))[0]
383 if markerbyte == 0 and flagbyte == 1:
384 vin = VectorSerializer.stream_deserialize(CTxIn, f)
385 vout = VectorSerializer.stream_deserialize(CTxOut, f)
386 wit = CTxWitness(tuple(0 for dummy in range(len(vin))))
387 wit = wit.stream_deserialize(f)
388 nLockTime = struct.unpack(b"<I", ser_read(f,4))[0]
389 return cls(vin, vout, nLockTime, nVersion, wit)
390 else:
391 f.seek(pos) # put marker byte back, since we don't have peek
392 vin = VectorSerializer.stream_deserialize(CTxIn, f)
393 vout = VectorSerializer.stream_deserialize(CTxOut, f)
394 nLockTime = struct.unpack(b"<I", ser_read(f,4))[0]
395 return cls(vin, vout, nLockTime, nVersion)
396
397
398 def stream_serialize(self, f, include_witness=True):

Callers

nothing calls this directly

Calls 4

stream_deserializeMethod · 0.95
ser_readFunction · 0.85
CTxWitnessClass · 0.85
stream_deserializeMethod · 0.45

Tested by

no test coverage detected