Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added attribute check in SegWitTransaction's __getattr__ #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GavinShox
Copy link

This allows SegWitTransaction to be pickled successfully. Before, when deserializing a SegWitTransaction object, pickle would throw a RecursionError as it would attempt to call getattr before self.transaction existed, which would cause it to infinitely recall getattr when it couldn't resolve self.transaction.

This allows SegWitTransaction to be pickled successfully. Before, when deserializing a SegWitTransaction object, pickle would throw a RecursionError as it would attempt to call getattr before self.transaction existed, which would cause it to infinitely recall getattr when it couldn't resolve self.transaction.
@SimoneBronzini
Copy link
Contributor

Hi, sorry for the delayed answer, can you provide a minimal working example of the problem? I am not sure in which cases it appears.

@GavinShox
Copy link
Author

When you serialize a SegWitTransaction object using python's pickle module, it works. But the problem is when you try to deserialize that pickled object, you get this exception:

Traceback (most recent call last):
  File "C:/Users/gavin/PycharmProjects/Bit-Store/main.py", line 46, in <module>
    tx = w.import_transaction(ex)
  File "C:\Users\gavin\PycharmProjects\Bit-Store\lib\core\wallet.py", line 366, in import_transaction
    txn = self.deserialize_transaction(txn_bytes)
  File "C:\Users\gavin\PycharmProjects\Bit-Store\lib\core\wallet.py", line 307, in deserialize_transaction
    obj = pickle.loads(txn_bytes)
  File "C:\Users\gavin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\btcpy\structs\transaction.py", line 744, in __getattr__
    return getattr(self.transaction, item)
  File "C:\Users\gavin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\btcpy\structs\transaction.py", line 744, in __getattr__
    return getattr(self.transaction, item)
  File "C:\Users\gavin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\btcpy\structs\transaction.py", line 744, in __getattr__
    return getattr(self.transaction, item)
  [Previous line repeated 328 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object

The issue is that pickle will actually attempt to get attributes from the SegWitTransaction object before self.transaction is actaully an attribute of the object. So in __getattr__, the function call getattr(self.transaction, item) will just recursivly re-call __getattr__ because self.transaction isn't defined yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants