Skip to content

Commit

Permalink
Namecoin: Abstract the name expiration logic
Browse files Browse the repository at this point in the history
Also fix expiration time for unconfirmed transactions.
  • Loading branch information
JeremyRand committed Oct 4, 2018
1 parent 5ecac39 commit 9b2c77f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
8 changes: 4 additions & 4 deletions electrum_nmc/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from . import bitcoin
from .bitcoin import is_address, hash_160, COIN, TYPE_ADDRESS
from .i18n import _
from .names import build_name_new, name_identifier_to_scripthash, OP_NAME_FIRSTUPDATE, OP_NAME_UPDATE
from .names import build_name_new, name_expires_in, name_identifier_to_scripthash, OP_NAME_FIRSTUPDATE, OP_NAME_UPDATE
from .transaction import Transaction, multisig_script, TxOutput
from .paymentrequest import PR_PAID, PR_UNPAID, PR_UNKNOWN, PR_EXPIRED
from .plugin import run_hook
Expand Down Expand Up @@ -238,8 +238,8 @@ def name_list(self, identifier=None):

address = i["address"]
height = i["height"]
expires_in = height - chain_height + 36000
expired = expires_in <= 0
expires_in = name_expires_in(height, chain_height)
expired = expires_in <= 0 if expires_in is not None else None

result_item = {
"name": name,
Expand Down Expand Up @@ -890,7 +890,7 @@ def name_show(self, identifier):
"vout": idx,
"address": o.address,
"height": height,
"expires_in": height - chain_height + 36000,
"expires_in": name_expires_in(height, chain_height),
"expired": False,
"ismine": self.wallet.is_mine(o.address),
}
Expand Down
9 changes: 5 additions & 4 deletions electrum_nmc/gui/qt/uno_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# SOFTWARE.

from electrum_nmc.i18n import _
from electrum_nmc.names import format_name_identifier, format_name_value
from electrum_nmc.names import format_name_identifier, format_name_value, name_expires_in

from .util import *
from .utxo_list import UTXOList
Expand Down Expand Up @@ -63,11 +63,12 @@ def on_update(self):

height = x.get('height')
chain_height = self.network.blockchain().height()
expires_in = height - chain_height + 36000
expires_in = name_expires_in(height, chain_height)
formatted_expires_in = '%d'%expires_in if expires_in is not None else ''

status = ''
status = '' if expires_in is not None else 'Update Pending'

utxo_item = SortableTreeWidgetItem([name, value, '%d'%expires_in, status])
utxo_item = SortableTreeWidgetItem([name, value, formatted_expires_in, status])
utxo_item.setFont(0, QFont(MONOSPACE_FONT))
utxo_item.setFont(1, QFont(MONOSPACE_FONT))
utxo_item.setData(0, Qt.UserRole, self.get_name(x))
Expand Down
7 changes: 7 additions & 0 deletions electrum_nmc/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ def get_wallet_name_delta(wallet, tx):
return name_input_is_mine, name_output_is_mine


def name_expires_in(name_height, chain_height):
if name_height <= 0:
return None

return name_height - chain_height + 36000


import binascii
import os
import re
Expand Down

0 comments on commit 9b2c77f

Please sign in to comment.