add height to TXRef
This commit is contained in:
parent
64a626cbb5
commit
b23481bd21
3 changed files with 22 additions and 8 deletions
|
@ -402,17 +402,17 @@ class BaseDatabase(SQLiteMixin):
|
||||||
if isinstance(my_account, BaseAccount):
|
if isinstance(my_account, BaseAccount):
|
||||||
my_account = my_account.public_key.address
|
my_account = my_account.public_key.address
|
||||||
rows = yield self.select_txos(
|
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
|
output_class = self.ledger.transaction_class.output_class
|
||||||
return [
|
return [
|
||||||
output_class(
|
output_class(
|
||||||
amount=row[0],
|
amount=row[0],
|
||||||
script=output_class.script_class(row[1]),
|
script=output_class.script_class(row[1]),
|
||||||
tx_ref=TXRefImmutable.from_id(row[2]),
|
tx_ref=TXRefImmutable.from_id(row[2], row[3]),
|
||||||
position=row[3],
|
position=row[4],
|
||||||
is_change=row[4] == 1,
|
is_change=row[5] == 1,
|
||||||
is_my_account=row[5] == my_account
|
is_my_account=row[6] == my_account
|
||||||
) for row in rows
|
) for row in rows
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,10 @@ class TXRefMutable(TXRef):
|
||||||
self._hash = sha256(sha256(self.tx.raw))
|
self._hash = sha256(sha256(self.tx.raw))
|
||||||
return self._hash
|
return self._hash
|
||||||
|
|
||||||
|
@property
|
||||||
|
def height(self):
|
||||||
|
return self.tx.height
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self._id = None
|
self._id = None
|
||||||
self._hash = None
|
self._hash = None
|
||||||
|
|
|
@ -38,6 +38,10 @@ class TXRef:
|
||||||
def hash(self):
|
def hash(self):
|
||||||
return self._hash
|
return self._hash
|
||||||
|
|
||||||
|
@property
|
||||||
|
def height(self):
|
||||||
|
return -1
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_null(self):
|
def is_null(self):
|
||||||
return self.hash == NULL_HASH32
|
return self.hash == NULL_HASH32
|
||||||
|
@ -45,22 +49,28 @@ class TXRef:
|
||||||
|
|
||||||
class TXRefImmutable(TXRef):
|
class TXRefImmutable(TXRef):
|
||||||
|
|
||||||
__slots__ = ()
|
__slots__ = '_height',
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_hash(cls, tx_hash): # type: (bytes) -> TXRefImmutable
|
def from_hash(cls, tx_hash: bytes, height: int) -> 'TXRefImmutable':
|
||||||
ref = cls()
|
ref = cls()
|
||||||
ref._hash = tx_hash
|
ref._hash = tx_hash
|
||||||
ref._id = hexlify(tx_hash[::-1]).decode()
|
ref._id = hexlify(tx_hash[::-1]).decode()
|
||||||
|
ref._height = height
|
||||||
return ref
|
return ref
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_id(cls, tx_id): # type: (str) -> TXRefImmutable
|
def from_id(cls, tx_id: str, height: int) -> 'TXRefImmutable':
|
||||||
ref = cls()
|
ref = cls()
|
||||||
ref._id = tx_id
|
ref._id = tx_id
|
||||||
ref._hash = unhexlify(tx_id)[::-1]
|
ref._hash = unhexlify(tx_id)[::-1]
|
||||||
|
ref._height = height
|
||||||
return ref
|
return ref
|
||||||
|
|
||||||
|
@property
|
||||||
|
def height(self):
|
||||||
|
return self._height
|
||||||
|
|
||||||
|
|
||||||
def sha256(x):
|
def sha256(x):
|
||||||
""" Simple wrapper of hashlib sha256. """
|
""" Simple wrapper of hashlib sha256. """
|
||||||
|
|
Loading…
Reference in a new issue