Skip to content

Commit

Permalink
Namecoin: add name_list console command
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRand committed Oct 4, 2018
1 parent 040cef4 commit dd0fedc
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions electrum_nmc/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,57 @@ def listunspent(self):
i["value"] = str(Decimal(v)/COIN) if v is not None else None
return l

@command('wn')
def name_list(self, identifier=None):
"""List unspent name outputs. Returns the list of unspent name_anyupdate
outputs in your wallet."""
l = copy.deepcopy(self.wallet.get_utxos())

result = []

for i in l:
txid = i["prevout_hash"]
tx = self.wallet.transactions[txid]

vout = i["prevout_n"]
o = tx.outputs()[vout]

if o.name_op is None:
continue
name_op = o.name_op

if "name" not in name_op:
continue

# TODO: handle non-ASCII name/value encoding
name = name_op["name"].decode("ascii")
value = name_op["value"].decode("ascii")

# Skip this item if it doesn't match the requested identifier
if identifier is not None:
if identifier != name:
continue

chain_height = self.network.blockchain().height()

address = i["address"]
height = i["height"]
expires_in = height - chain_height + 36000
expired = expires_in <= 0

result_item = {
"name": name,
"value": value,
"txid": txid,
"vout": vout,
"address": address,
"height": height,
"expires_in": expires_in,
"expired": expired,
}
result.append(result_item)
return result

@command('n')
def getaddressunspent(self, address):
"""Returns the UTXO list of any address. Note: This
Expand Down Expand Up @@ -895,6 +946,7 @@ def help(self):
'amount': (None, "Amount to be sent (in NMC). Type \'!\' to send the maximum available."),
'allow_existing': (None, "Allow pre-registering a name that already is registered. Your registration fee will be forfeited until you can register the name after it expires."),
'allow_early': (None, "Allow submitting a name registration while its pre-registration is still pending. This increases the risk of an attacker stealing your name registration."),
'identifier': (None, "The requested name identifier"),
}


Expand Down

0 comments on commit dd0fedc

Please sign in to comment.