|
@ -278,7 +278,9 @@ class Wallet: |
|
|
|
|
|
|
|
|
def is_valid(self,addr): |
|
|
def is_valid(self,addr): |
|
|
ADDRESS_RE = re.compile('[1-9A-HJ-NP-Za-km-z]{26,}\\Z') |
|
|
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): |
|
|
def create_new_address(self, for_change, password): |
|
|
seed = self.pw_decode( self.seed, password) |
|
|
seed = self.pw_decode( self.seed, password) |
|
@ -600,6 +602,8 @@ class Wallet: |
|
|
tx['default_label'] = default_label |
|
|
tx['default_label'] = default_label |
|
|
|
|
|
|
|
|
def mktx(self, to_address, amount, label, password, fee=None): |
|
|
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 |
|
|
if fee is None: fee = self.fee |
|
|
try: |
|
|
try: |
|
|
inputs, outputs = wallet.choose_inputs_outputs( to_address, amount, fee, password ) |
|
|
inputs, outputs = wallet.choose_inputs_outputs( to_address, amount, fee, password ) |
|
@ -626,13 +630,10 @@ class Wallet: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from optparse import OptionParser |
|
|
from optparse import OptionParser |
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
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)) |
|
|
usage = "usage: %prog [options] command args\nCommands: "+ (', '.join(known_commands)) |
|
|
|
|
|
|
|
@ -723,7 +724,7 @@ if __name__ == '__main__': |
|
|
cmd = 'help' |
|
|
cmd = 'help' |
|
|
|
|
|
|
|
|
# open session |
|
|
# 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.new_session() |
|
|
wallet.update() |
|
|
wallet.update() |
|
|
wallet.save() |
|
|
wallet.save() |
|
@ -770,6 +771,10 @@ if __name__ == '__main__': |
|
|
import mnemonic |
|
|
import mnemonic |
|
|
print wallet.seed, '"'+' '.join(mnemonic.mn_encode(wallet.seed))+'"' |
|
|
print wallet.seed, '"'+' '.join(mnemonic.mn_encode(wallet.seed))+'"' |
|
|
|
|
|
|
|
|
|
|
|
elif cmd == 'validateaddress': |
|
|
|
|
|
addr = args[1] |
|
|
|
|
|
print wallet.is_valid(addr) |
|
|
|
|
|
|
|
|
elif cmd == 'balance': |
|
|
elif cmd == 'balance': |
|
|
c, u = wallet.get_balance() |
|
|
c, u = wallet.get_balance() |
|
|
if u: |
|
|
if u: |
|
@ -832,8 +837,8 @@ if __name__ == '__main__': |
|
|
for k, v in wallet.labels.items(): |
|
|
for k, v in wallet.labels.items(): |
|
|
if v == to_address: |
|
|
if v == to_address: |
|
|
to_address = k |
|
|
to_address = k |
|
|
break |
|
|
|
|
|
print "alias", to_address |
|
|
print "alias", to_address |
|
|
|
|
|
break |
|
|
r, h = wallet.mktx( to_address, amount, label, password, fee = options.tx_fee ) |
|
|
r, h = wallet.mktx( to_address, amount, label, password, fee = options.tx_fee ) |
|
|
if r and cmd=='payto': |
|
|
if r and cmd=='payto': |
|
|
r, h = wallet.sendtx( tx ) |
|
|
r, h = wallet.sendtx( tx ) |
|
|