diff --git a/torba/basedatabase.py b/torba/basedatabase.py index cdbfe08ce..4a9422a04 100644 --- a/torba/basedatabase.py +++ b/torba/basedatabase.py @@ -402,17 +402,17 @@ class BaseDatabase(SQLiteMixin): if isinstance(my_account, BaseAccount): my_account = my_account.public_key.address rows = yield self.select_txos( - "amount, script, txid, txo.position, chain, account", **constraints + "amount, script, txid, tx.height, txo.position, chain, account", **constraints ) output_class = self.ledger.transaction_class.output_class return [ output_class( amount=row[0], script=output_class.script_class(row[1]), - tx_ref=TXRefImmutable.from_id(row[2]), - position=row[3], - is_change=row[4] == 1, - is_my_account=row[5] == my_account + tx_ref=TXRefImmutable.from_id(row[2], row[3]), + position=row[4], + is_change=row[5] == 1, + is_my_account=row[6] == my_account ) for row in rows ] diff --git a/torba/basetransaction.py b/torba/basetransaction.py index 745e0c2f4..0a4609d73 100644 --- a/torba/basetransaction.py +++ b/torba/basetransaction.py @@ -39,6 +39,10 @@ class TXRefMutable(TXRef): self._hash = sha256(sha256(self.tx.raw)) return self._hash + @property + def height(self): + return self.tx.height + def reset(self): self._id = None self._hash = None diff --git a/torba/hash.py b/torba/hash.py index 656dec2a6..bd641b03f 100644 --- a/torba/hash.py +++ b/torba/hash.py @@ -38,6 +38,10 @@ class TXRef: def hash(self): return self._hash + @property + def height(self): + return -1 + @property def is_null(self): return self.hash == NULL_HASH32 @@ -45,22 +49,28 @@ class TXRef: class TXRefImmutable(TXRef): - __slots__ = () + __slots__ = '_height', @classmethod - def from_hash(cls, tx_hash): # type: (bytes) -> TXRefImmutable + def from_hash(cls, tx_hash: bytes, height: int) -> 'TXRefImmutable': ref = cls() ref._hash = tx_hash ref._id = hexlify(tx_hash[::-1]).decode() + ref._height = height return ref @classmethod - def from_id(cls, tx_id): # type: (str) -> TXRefImmutable + def from_id(cls, tx_id: str, height: int) -> 'TXRefImmutable': ref = cls() ref._id = tx_id ref._hash = unhexlify(tx_id)[::-1] + ref._height = height return ref + @property + def height(self): + return self._height + def sha256(x): """ Simple wrapper of hashlib sha256. """