mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-10 20:49:52 +00:00
tx heights: replace magic numbers with named constants
This commit is contained in:
parent
2dca7bd39c
commit
704bdedea1
1 changed files with 15 additions and 11 deletions
|
@ -72,6 +72,9 @@ TX_STATUS = [
|
||||||
_('Local only'),
|
_('Local only'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
TX_HEIGHT_LOCAL = -2
|
||||||
|
TX_HEIGHT_UNCONF_PARENT = -1
|
||||||
|
TX_HEIGHT_UNCONFIRMED = 0
|
||||||
|
|
||||||
|
|
||||||
def relayfee(network):
|
def relayfee(network):
|
||||||
|
@ -371,7 +374,8 @@ class Abstract_Wallet(PrintError):
|
||||||
return self.get_pubkeys(*sequence)
|
return self.get_pubkeys(*sequence)
|
||||||
|
|
||||||
def add_unverified_tx(self, tx_hash, tx_height):
|
def add_unverified_tx(self, tx_hash, tx_height):
|
||||||
if tx_height == 0 and tx_hash in self.verified_tx:
|
if tx_height in (TX_HEIGHT_UNCONFIRMED, TX_HEIGHT_UNCONF_PARENT) \
|
||||||
|
and tx_hash in self.verified_tx:
|
||||||
self.verified_tx.pop(tx_hash)
|
self.verified_tx.pop(tx_hash)
|
||||||
self.verifier.merkle_roots.pop(tx_hash, None)
|
self.verifier.merkle_roots.pop(tx_hash, None)
|
||||||
|
|
||||||
|
@ -421,7 +425,7 @@ class Abstract_Wallet(PrintError):
|
||||||
return height, 0, False
|
return height, 0, False
|
||||||
else:
|
else:
|
||||||
# local transaction
|
# local transaction
|
||||||
return -2, 0, False
|
return TX_HEIGHT_LOCAL, 0, False
|
||||||
|
|
||||||
def get_txpos(self, tx_hash):
|
def get_txpos(self, tx_hash):
|
||||||
"return position, even if the tx is unverified"
|
"return position, even if the tx is unverified"
|
||||||
|
@ -528,7 +532,7 @@ class Abstract_Wallet(PrintError):
|
||||||
status = _("%d confirmations") % conf
|
status = _("%d confirmations") % conf
|
||||||
else:
|
else:
|
||||||
status = _('Not verified')
|
status = _('Not verified')
|
||||||
elif height in [-1,0]:
|
elif height in (TX_HEIGHT_UNCONF_PARENT, TX_HEIGHT_UNCONFIRMED):
|
||||||
status = _('Unconfirmed')
|
status = _('Unconfirmed')
|
||||||
if fee is None:
|
if fee is None:
|
||||||
fee = self.tx_fees.get(tx_hash)
|
fee = self.tx_fees.get(tx_hash)
|
||||||
|
@ -607,7 +611,7 @@ class Abstract_Wallet(PrintError):
|
||||||
x += v
|
x += v
|
||||||
elif tx_height > 0:
|
elif tx_height > 0:
|
||||||
c += v
|
c += v
|
||||||
elif tx_height != -2: # local tx
|
elif tx_height != TX_HEIGHT_LOCAL:
|
||||||
u += v
|
u += v
|
||||||
if txo in sent:
|
if txo in sent:
|
||||||
if sent[txo] > 0:
|
if sent[txo] > 0:
|
||||||
|
@ -824,7 +828,7 @@ class Abstract_Wallet(PrintError):
|
||||||
h2.append((tx_hash, height, conf, timestamp, delta, balance))
|
h2.append((tx_hash, height, conf, timestamp, delta, balance))
|
||||||
if balance is None or delta is None:
|
if balance is None or delta is None:
|
||||||
balance = None
|
balance = None
|
||||||
elif height != -2: # local tx
|
elif height != TX_HEIGHT_LOCAL:
|
||||||
balance -= delta
|
balance -= delta
|
||||||
h2.reverse()
|
h2.reverse()
|
||||||
|
|
||||||
|
@ -866,15 +870,15 @@ class Abstract_Wallet(PrintError):
|
||||||
is_lowfee = fee < low_fee * 0.5
|
is_lowfee = fee < low_fee * 0.5
|
||||||
else:
|
else:
|
||||||
is_lowfee = False
|
is_lowfee = False
|
||||||
if height == -2:
|
if height == TX_HEIGHT_LOCAL:
|
||||||
status = 5
|
status = 5
|
||||||
elif height == -1:
|
elif height == TX_HEIGHT_UNCONF_PARENT:
|
||||||
status = 1
|
status = 1
|
||||||
elif height==0 and not is_final:
|
elif height == TX_HEIGHT_UNCONFIRMED and not is_final:
|
||||||
status = 0
|
status = 0
|
||||||
elif height == 0 and is_lowfee:
|
elif height == TX_HEIGHT_UNCONFIRMED and is_lowfee:
|
||||||
status = 2
|
status = 2
|
||||||
elif height == 0:
|
elif height == TX_HEIGHT_UNCONFIRMED:
|
||||||
status = 3
|
status = 3
|
||||||
else:
|
else:
|
||||||
status = 4
|
status = 4
|
||||||
|
@ -1056,7 +1060,7 @@ class Abstract_Wallet(PrintError):
|
||||||
age = -1
|
age = -1
|
||||||
h = self.history.get(address, [])
|
h = self.history.get(address, [])
|
||||||
for tx_hash, tx_height in h:
|
for tx_hash, tx_height in h:
|
||||||
if tx_height == 0:
|
if tx_height <= 0:
|
||||||
tx_age = 0
|
tx_age = 0
|
||||||
else:
|
else:
|
||||||
tx_age = self.get_local_height() - tx_height + 1
|
tx_age = self.get_local_height() - tx_height + 1
|
||||||
|
|
Loading…
Add table
Reference in a new issue