Skip to content

Commit

Permalink
Namecoin: Generate default label for name transfers.
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRand committed Oct 1, 2018
1 parent eb2f962 commit 0dac8a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 24 additions & 1 deletion electrum_nmc/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,18 @@ def format_name_op(name_op):
return "\tName Update\n\t\t" + formatted_name + "\n\t\t" + formatted_value


def get_default_name_tx_label(tx):
def get_default_name_tx_label(wallet, tx):
for addr, v, name_op in tx.get_outputs():
if name_op is not None:
# TODO: Handle multiple atomic name ops.
# TODO: Include "name" field.
name_input_is_mine, name_output_is_mine = get_wallet_name_delta(wallet, tx)
if not name_input_is_mine and not name_output_is_mine:
return None
if name_input_is_mine and not name_output_is_mine:
return "Name Transfer (Outgoing)"
if not name_input_is_mine and name_output_is_mine:
return "Name Transfer (Incoming)"
if name_op["op"] == OP_NAME_NEW:
return "Name Pre-Registration"
if name_op["op"] == OP_NAME_FIRSTUPDATE:
Expand All @@ -109,6 +116,22 @@ def get_default_name_tx_label(tx):
return None


def get_wallet_name_delta(wallet, tx):
name_input_is_mine = False
name_output_is_mine = False
for txin in tx.inputs():
addr = wallet.get_txin_address(txin)
if wallet.is_mine(addr):
prev_tx = wallet.transactions.get(txin['prevout_hash'])
if prev_tx.get_outputs()[txin['prevout_n']][2] is not None:
name_input_is_mine = True
for addr, value, name_op in tx.get_outputs():
if name_op is not None and wallet.is_mine(addr):
name_output_is_mine = True

return name_input_is_mine, name_output_is_mine


from .bitcoin import push_script
from .transaction import match_decoded, opcodes, script_GetOp
from .util import bh2u
Expand Down
2 changes: 1 addition & 1 deletion electrum_nmc/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def get_label(self, tx_hash):

def get_default_label(self, tx_hash):
# TODO: what happens if a name would have a non-empty default non-name label?
name_label = get_default_name_tx_label(self.transactions.get(tx_hash))
name_label = get_default_name_tx_label(self, self.transactions.get(tx_hash))
if name_label is not None:
return name_label

Expand Down

0 comments on commit 0dac8a1

Please sign in to comment.