Merge branch 'master' of gitorious.org:electrum/electrum

This commit is contained in:
ThomasV 2011-11-17 03:56:28 +03:00
commit d497a37370
1 changed files with 12 additions and 7 deletions

View File

@ -278,7 +278,9 @@ class Wallet:
def is_valid(self,addr):
ADDRESS_RE = re.compile('[1-9A-HJ-NP-Za-km-z]{26,}\\Z')
return ADDRESS_RE.match(addr)
if not ADDRESS_RE.match(addr): return False
h = bc_address_to_hash_160(addr)
return addr == hash_160_to_bc_address(h)
def create_new_address(self, for_change, password):
seed = self.pw_decode( self.seed, password)
@ -596,6 +598,8 @@ class Wallet:
tx['default_label'] = default_label
def mktx(self, to_address, amount, label, password, fee=None):
if not self.is_valid(to_address):
return False, "Invalid address"
if fee is None: fee = self.fee
try:
inputs, outputs = wallet.choose_inputs_outputs( to_address, amount, fee, password )
@ -622,13 +626,10 @@ class Wallet:
from optparse import OptionParser
if __name__ == '__main__':
known_commands = ['help', 'balance', 'contacts', 'create', 'payto', 'sendtx', 'password', 'newaddress', 'addresses', 'history', 'label', 'gui', 'mktx','seed']
known_commands = ['help', 'validateaddress', 'balance', 'contacts', 'create', 'payto', 'sendtx', 'password', 'newaddress', 'addresses', 'history', 'label', 'gui', 'mktx','seed']
usage = "usage: %prog [options] command args\nCommands: "+ (', '.join(known_commands))
@ -719,7 +720,7 @@ if __name__ == '__main__':
cmd = 'help'
# open session
if cmd not in ['password', 'mktx', 'history', 'label','contacts','help']:
if cmd not in ['password', 'mktx', 'history', 'label','contacts','help','validateaddress']:
wallet.new_session()
wallet.update()
wallet.save()
@ -766,6 +767,10 @@ if __name__ == '__main__':
import mnemonic
print wallet.seed, '"'+' '.join(mnemonic.mn_encode(wallet.seed))+'"'
elif cmd == 'validateaddress':
addr = args[1]
print wallet.is_valid(addr)
elif cmd == 'balance':
c, u = wallet.get_balance()
if u:
@ -828,8 +833,8 @@ if __name__ == '__main__':
for k, v in wallet.labels.items():
if v == to_address:
to_address = k
break
print "alias", to_address
break
r, h = wallet.mktx( to_address, amount, label, password, fee = options.tx_fee )
if r and cmd=='payto':
r, h = wallet.sendtx( tx )