diff --git a/bitcoinlib/db.py b/bitcoinlib/db.py index 9e1b8cc7..821d0df0 100644 --- a/bitcoinlib/db.py +++ b/bitcoinlib/db.py @@ -413,6 +413,7 @@ class DbTransaction(Base): raw = Column(LargeBinary, doc="Raw transaction hexadecimal string. Transaction is included in raw format on the blockchain") verified = Column(Boolean, default=False, doc="Is transaction verified. Default is False") + order_n = Column(Integer, doc="Order of transaction in block") __table_args__ = ( UniqueConstraint('wallet_id', 'txid', name='constraint_wallet_transaction_hash_unique'), diff --git a/bitcoinlib/services/services.py b/bitcoinlib/services/services.py index db2c4c32..2219e29c 100644 --- a/bitcoinlib/services/services.py +++ b/bitcoinlib/services/services.py @@ -716,7 +716,8 @@ def commit(self): def _parse_db_transaction(db_tx): t = Transaction(locktime=db_tx.locktime, version=db_tx.version, network=db_tx.network_name, fee=db_tx.fee, txid=db_tx.txid.hex(), date=db_tx.date, confirmations=db_tx.confirmations, - block_height=db_tx.block_height, status='confirmed', witness_type=db_tx.witness_type.value) + block_height=db_tx.block_height, status='confirmed', witness_type=db_tx.witness_type.value, + order_n=db_tx.order_n) for n in db_tx.nodes: if n.is_input: if n.ref_txid == b'\00' * 32: diff --git a/bitcoinlib/transactions.py b/bitcoinlib/transactions.py index 3ae0b055..a4b703e6 100644 --- a/bitcoinlib/transactions.py +++ b/bitcoinlib/transactions.py @@ -1065,7 +1065,8 @@ def load(txid=None, filename=None): def __init__(self, inputs=None, outputs=None, locktime=0, version=None, network=DEFAULT_NETWORK, fee=None, fee_per_kb=None, size=None, txid='', txhash='', date=None, confirmations=None, block_height=None, block_hash=None, input_total=0, output_total=0, rawtx=b'', - status='new', coinbase=False, verified=False, witness_type='segwit', flag=None, replace_by_fee=False): + status='new', coinbase=False, verified=False, witness_type='segwit', flag=None, replace_by_fee=False, + order_n=None): """ Create a new transaction class with provided inputs and outputs. @@ -1118,6 +1119,8 @@ def __init__(self, inputs=None, outputs=None, locktime=0, version=None, :type witness_type: str :param flag: Transaction flag to indicate version, for example for SegWit :type flag: bytes, str + :param order_n: Order of transaction in block. Used when parsing blocks + :type order_n: int """ @@ -1178,6 +1181,7 @@ def __init__(self, inputs=None, outputs=None, locktime=0, version=None, self.witness_type = witness_type self.replace_by_fee = replace_by_fee self.change = 0 + self.order_n = order_n self.calc_weight_units() if self.witness_type not in ['legacy', 'segwit']: raise TransactionError("Please specify a valid witness type: legacy or segwit")