Skip to content

Commit

Permalink
Namecoin / AuxPoW: Avoid some copy operations in transaction.deserial…
Browse files Browse the repository at this point in the history
…ize.
  • Loading branch information
JeremyRand committed Jul 2, 2018
1 parent a7b45ce commit 3b15937
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ def parse_output(vds, i):
return d


# if expect_trailing_data, returns (deserialized transaction, start position of
# trailing data)
def deserialize(raw: str, force_full_parse=False, expect_trailing_data=False, raw_bytes=None, expect_trailing_bytes=False) -> dict:
if raw_bytes is None:
raw_bytes = bfh(raw)
Expand Down Expand Up @@ -597,11 +599,13 @@ def deserialize(raw: str, force_full_parse=False, expect_trailing_data=False, ra
raise SerializationError('extra junk at the end')
if not expect_trailing_data:
return d
# The caller is expecting trailing data to be present; return that trailing data in bytes format
# The caller is expecting trailing data to be present; return starting
# position of trailing data in bytes format
if expect_trailing_bytes:
return d, raw_bytes[vds.read_cursor:]
# The caller is expecting trailing data to be present; return that trailing data in hex format
return d, bh2u(raw_bytes[vds.read_cursor:])
return d, vds.read_cursor
# The caller is expecting trailing data to be present; return starting
# position of trailing data in hex format
raise Exception("Unimplemented: starting position for trailing data in hex format")


# pay & redeem scripts
Expand Down Expand Up @@ -731,7 +735,11 @@ def deserialize(self, force_full_parse=False):
if self._inputs is not None:
return
if self.expect_trailing_data:
d, trailing_data = deserialize(self.raw, force_full_parse, expect_trailing_data=self.expect_trailing_data, raw_bytes=self.raw_bytes, expect_trailing_bytes=self.expect_trailing_bytes)
d, start_position = deserialize(self.raw, force_full_parse, expect_trailing_data=self.expect_trailing_data, raw_bytes=self.raw_bytes, expect_trailing_bytes=self.expect_trailing_bytes)
if self.expect_trailing_bytes:
trailing_data = self.raw_bytes[start_position:]
else:
raise Exception("Unimplemented: trailing data in hex")
else:
d = deserialize(self.raw, force_full_parse, raw_bytes=self.raw_bytes)
self._inputs = d['inputs']
Expand Down

0 comments on commit 3b15937

Please sign in to comment.