Skip to content

Commit

Permalink
tx heights: replace magic numbers with named constants
Browse files Browse the repository at this point in the history
  • Loading branch information
SomberNight committed Jan 29, 2018
1 parent 2dca7bd commit 704bded
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/wallet.py
Expand Up @@ -72,6 +72,9 @@
_('Local only'),
]

TX_HEIGHT_LOCAL = -2
TX_HEIGHT_UNCONF_PARENT = -1
TX_HEIGHT_UNCONFIRMED = 0


def relayfee(network):
Expand Down Expand Up @@ -371,7 +374,8 @@ def get_public_keys(self, address):
return self.get_pubkeys(*sequence)

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.verifier.merkle_roots.pop(tx_hash, None)

Expand Down Expand Up @@ -421,7 +425,7 @@ def get_tx_height(self, tx_hash):
return height, 0, False
else:
# local transaction
return -2, 0, False
return TX_HEIGHT_LOCAL, 0, False

def get_txpos(self, tx_hash):
"return position, even if the tx is unverified"
Expand Down Expand Up @@ -528,7 +532,7 @@ def get_tx_info(self, tx):
status = _("%d confirmations") % conf
else:
status = _('Not verified')
elif height in [-1,0]:
elif height in (TX_HEIGHT_UNCONF_PARENT, TX_HEIGHT_UNCONFIRMED):
status = _('Unconfirmed')
if fee is None:
fee = self.tx_fees.get(tx_hash)
Expand Down Expand Up @@ -607,7 +611,7 @@ def get_addr_balance(self, address):
x += v
elif tx_height > 0:
c += v
elif tx_height != -2: # local tx
elif tx_height != TX_HEIGHT_LOCAL:
u += v
if txo in sent:
if sent[txo] > 0:
Expand Down Expand Up @@ -824,7 +828,7 @@ def get_history(self, domain=None):
h2.append((tx_hash, height, conf, timestamp, delta, balance))
if balance is None or delta is None:
balance = None
elif height != -2: # local tx
elif height != TX_HEIGHT_LOCAL:
balance -= delta
h2.reverse()

Expand Down Expand Up @@ -866,15 +870,15 @@ def get_tx_status(self, tx_hash, height, conf, timestamp):
is_lowfee = fee < low_fee * 0.5
else:
is_lowfee = False
if height == -2:
if height == TX_HEIGHT_LOCAL:
status = 5
elif height == -1:
elif height == TX_HEIGHT_UNCONF_PARENT:
status = 1
elif height==0 and not is_final:
elif height == TX_HEIGHT_UNCONFIRMED and not is_final:
status = 0
elif height == 0 and is_lowfee:
elif height == TX_HEIGHT_UNCONFIRMED and is_lowfee:
status = 2
elif height == 0:
elif height == TX_HEIGHT_UNCONFIRMED:
status = 3
else:
status = 4
Expand Down Expand Up @@ -1056,7 +1060,7 @@ def address_is_old(self, address, age_limit=2):
age = -1
h = self.history.get(address, [])
for tx_hash, tx_height in h:
if tx_height == 0:
if tx_height <= 0:
tx_age = 0
else:
tx_age = self.get_local_height() - tx_height + 1
Expand Down

0 comments on commit 704bded

Please sign in to comment.