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

Method parse

code-ch08/tx.py:329–338  ·  view source on GitHub ↗

Takes a byte stream and parses the tx_output at the start return a TxOut object

(cls, s)

Source from the content-addressed store, hash-verified

327
328 @classmethod
329 def parse(cls, s):
330 '''Takes a byte stream and parses the tx_output at the start
331 return a TxOut object
332 '''
333 # amount is an integer in 8 bytes, little endian
334 amount = little_endian_to_int(s.read(8))
335 # use Script.parse to get the ScriptPubKey
336 script_pubkey = Script.parse(s)
337 # return an instance of the class (see __init__ for args)
338 return cls(amount, script_pubkey)
339
340 def serialize(self):
341 '''Returns the byte serialization of the transaction output'''

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