From c7527c51cb2dfa4f27a886e3dc5801b7903b4b95 Mon Sep 17 00:00:00 2001 From: Highflyer108 <30984300+Highflyer108@users.noreply.github.com> Date: Sun, 16 Sep 2018 19:10:00 +0100 Subject: [PATCH] added attribute check in SegWitTransaction's __getattr__ 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. --- btcpy/structs/transaction.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/btcpy/structs/transaction.py b/btcpy/structs/transaction.py index 16fa6ac..013c7f3 100644 --- a/btcpy/structs/transaction.py +++ b/btcpy/structs/transaction.py @@ -741,7 +741,11 @@ def __init__(self, version, ins, outs, locktime, txid=None): object.__setattr__(self, 'transaction', Transaction(version, ins, outs, locktime, txid)) def __getattr__(self, item): - return getattr(self.transaction, item) + if 'transaction' not in vars(self): + raise AttributeError("'{}' object has no attribute '{}'".format(type(self).__name__, + item)) + else: + return getattr(self.transaction, item) @cached def serialize(self):