MCPcopy
hub / github.com/jimmysong/programmingbitcoin / parse

Method parse

code-ch08/tx.py:268–281  ·  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

266
267 @classmethod
268 def parse(cls, s):
269 '''Takes a byte stream and parses the tx_input at the start
270 return a TxIn object
271 '''
272 # prev_tx is 32 bytes, little endian
273 prev_tx = s.read(32)[::-1]
274 # prev_index is an integer in 4 bytes, little endian
275 prev_index = little_endian_to_int(s.read(4))
276 # use Script.parse to get the ScriptSig
277 script_sig = Script.parse(s)
278 # sequence is an integer in 4 bytes, little-endian
279 sequence = little_endian_to_int(s.read(4))
280 # return an instance of the class (see __init__ for args)
281 return cls(prev_tx, prev_index, script_sig, sequence)
282
283 def serialize(self):
284 '''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