Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Transaction class instances retain old attributes #901

Closed
jseagrave21 opened this issue Feb 26, 2019 · 1 comment
Closed

Transaction class instances retain old attributes #901

jseagrave21 opened this issue Feb 26, 2019 · 1 comment
Assignees

Comments

@jseagrave21
Copy link
Contributor

jseagrave21 commented Feb 26, 2019

Current behavior

This issue was first discovered by @lock9 and then further investigated by @jseagrave21 and @ixje.

Whenever an instance of a transaction is created the creator defines attributes in this manner:

def __init__(self, inputs=[], outputs=[], attributes=[], scripts=[]):

From @ixje "The problem with this is that you should not put mutable objects (e.g. a list) as the default values. because they are created only once and then reused for all instances ever created."

This caused the issue discovered by @lock9. When creating new instances of RawTransaction, the previous attributes were retained and the new ones appended until the max (16) was reached.

Expected behavior

A new transaction class should not retain old attributes.

How to reproduce

Create a new transaction and append an attribute in a loop.

Your environment

neo-python v0.8.4
Also references https://github.com/CityOfZion/neo-python/blob/9588aed21a58cf8f9e862679fd8a8cfa778fac5e/neo/Core/TX/RawTransaction.py

@ixje ixje self-assigned this Feb 26, 2019
@lock9
Copy link

lock9 commented Feb 27, 2019

The fix provided by @ixje solves the problem (fix Transaction class constructor):

def __init__(self, inputs=None, outputs=None, attributes=None, scripts=None):
        """
        Create an instance.
        Args:
            inputs (list): of neo.Core.CoinReference.CoinReference.
            outputs (list): of neo.Core.TX.Transaction.TransactionOutput items.
            attributes (list): of neo.Core.TX.TransactionAttribute.
            scripts:
        """
        super(Transaction, self).__init__()
        self.inputs = [] if inputs is None else inputs
        self.outputs = [] if outputs is None else outputs
        self.Attributes = [] if attributes is None else attributes
        self.scripts = [] if scripts is None else scripts
        self.InventoryType = 0x01  # InventoryType TX 0x01
        self.__references = None

Thank you for the very quick fix!

@ixje ixje mentioned this issue Feb 27, 2019
5 tasks
@ixje ixje closed this as completed Aug 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants