MCPcopy Index your code
hub / github.com/jimmysong/programmingbitcoin / parse

Method parse

code-ch13/tx.py:421–434  ·  view source on GitHub ↗

Takes a byte stream and parses the tx_input at the start return a TxIn object

(cls, s)

Source from the content-addressed store, hash-verified

419
420 @classmethod
421 def parse(cls, s):
422 '''Takes a byte stream and parses the tx_input at the start
423 return a TxIn object
424 '''
425 # prev_tx is 32 bytes, little endian
426 prev_tx = s.read(32)[::-1]
427 # prev_index is an integer in 4 bytes, little endian
428 prev_index = little_endian_to_int(s.read(4))
429 # use Script.parse to get the ScriptSig
430 script_sig = Script.parse(s)
431 # sequence is an integer in 4 bytes, little-endian
432 sequence = little_endian_to_int(s.read(4))
433 # return an instance of the class (see __init__ for args)
434 return cls(prev_tx, prev_index, script_sig, sequence)
435
436 def serialize(self):
437 '''Returns the byte serialization of the transaction input'''

Callers

nothing calls this directly

Calls 3

little_endian_to_intFunction · 0.90
readMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected