Browse Source

getalias: no check

283
ThomasV 10 years ago
parent
commit
ba78093e2e
  1. 24
      lib/commands.py
  2. 6
      lib/util.py

24
lib/commands.py

@ -333,13 +333,21 @@ class Commands:
out = "Error: Keypair import failed: " + str(e) out = "Error: Keypair import failed: " + str(e)
return out return out
def _resolver(self, x):
if x is None:
return None
out = self.contacts.resolve(x)
if out.get('type') == 'openalias' and self.nocheck is False and out.get('validated') is False:
raise BaseException('cannot verify alias', x)
return out['address']
@command('n') @command('n')
def sweep(self, privkey, destination, tx_fee=None, nocheck=False): def sweep(self, privkey, destination, tx_fee=None, nocheck=False):
"""Sweep private key. Returns a transaction that spends UTXOs from """Sweep private key. Returns a transaction that spends UTXOs from
privkey to a destination address. The transaction is not privkey to a destination address. The transaction is not
broadcasted.""" broadcasted."""
resolver = lambda x: self.contacts.resolve(x, nocheck)['address'] self.nocheck = nocheck
dest = resolver(destination) dest = self._resolver(destination)
if tx_fee is None: if tx_fee is None:
tx_fee = 0.0001 tx_fee = 0.0001
fee = int(Decimal(tx_fee)*COIN) fee = int(Decimal(tx_fee)*COIN)
@ -357,13 +365,13 @@ class Commands:
return bitcoin.verify_message(address, signature, message) return bitcoin.verify_message(address, signature, message)
def _mktx(self, outputs, fee, change_addr, domain, nocheck, unsigned): def _mktx(self, outputs, fee, change_addr, domain, nocheck, unsigned):
resolver = lambda x: None if x is None else self.contacts.resolve(x, nocheck)['address'] self.nocheck = nocheck
change_addr = resolver(change_addr) change_addr = self._resolver(change_addr)
domain = None if domain is None else map(resolver, domain) domain = None if domain is None else map(self._resolver, domain)
fee = None if fee is None else int(COIN*Decimal(fee)) fee = None if fee is None else int(COIN*Decimal(fee))
final_outputs = [] final_outputs = []
for address, amount in outputs: for address, amount in outputs:
address = resolver(address) address = self._resolver(address)
#assert self.wallet.is_mine(address) #assert self.wallet.is_mine(address)
if amount == '!': if amount == '!':
assert len(outputs) == 1 assert len(outputs) == 1
@ -451,9 +459,9 @@ class Commands:
return self.contacts return self.contacts
@command('') @command('')
def getalias(self, key, nocheck=False): def getalias(self, key):
"""Retrieve alias. Lookup in your list of contacts, and for an OpenAlias DNS record.""" """Retrieve alias. Lookup in your list of contacts, and for an OpenAlias DNS record."""
return self.contacts.resolve(key, nocheck) return self.contacts.resolve(key)
@command('') @command('')
def searchcontacts(self, query): def searchcontacts(self, query):

6
lib/util.py

@ -471,7 +471,7 @@ class Contacts(StoreDict):
def __init__(self, config): def __init__(self, config):
StoreDict.__init__(self, config, 'contacts') StoreDict.__init__(self, config, 'contacts')
def resolve(self, k, nocheck=False): def resolve(self, k):
if bitcoin.is_address(k): if bitcoin.is_address(k):
return {'address':k, 'type':'address'} return {'address':k, 'type':'address'}
if k in self.keys(): if k in self.keys():
@ -480,7 +480,5 @@ class Contacts(StoreDict):
return {'address':addr, 'type':'contact'} return {'address':addr, 'type':'contact'}
out = run_hook('resolve_address', k) out = run_hook('resolve_address', k)
if out: if out:
if not nocheck and out.get('validated') is False:
raise Exception("cannot validate alias")
return out return out
raise Exception("invalid Bitcoin address", k) raise Exception("Invalid Bitcoin address or alias", k)

Loading…
Cancel
Save