2011-11-04 18:00:37 +01:00
#!/usr/bin/env python
#
# Electrum - lightweight Bitcoin client
# Copyright (C) 2011 thomasv@gitorious
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2012-08-23 17:05:07 -07:00
import re
2013-03-02 16:29:14 +01:00
import pkgutil
2013-02-27 18:11:45 +01:00
import sys , os , time , json
2012-08-25 14:11:50 -07:00
import optparse
2013-02-18 23:29:19 +01:00
import platform
2013-03-02 10:22:45 +01:00
from decimal import Decimal
2012-08-23 17:05:07 -07:00
2012-05-14 14:09:50 +02:00
try :
import ecdsa
2012-08-19 15:10:17 -07:00
except ImportError :
sys . exit ( " Error: python-ecdsa does not seem to be installed. Try ' sudo pip install ecdsa ' " )
2012-05-14 14:09:50 +02:00
try :
import aes
2012-08-19 15:10:17 -07:00
except ImportError :
sys . exit ( " Error: AES does not seem to be installed. Try ' sudo pip install slowaes ' " )
2012-05-14 14:09:50 +02:00
2012-08-30 00:03:38 +02:00
2013-03-15 13:00:59 +01:00
is_local = os . path . dirname ( os . path . realpath ( __file__ ) ) == os . getcwd ( )
2013-03-12 13:48:16 +01:00
is_android = ' ANDROID_DATA ' in os . environ
2013-03-15 13:00:59 +01:00
import __builtin__
__builtin__ . use_local_modules = is_local or is_android
2013-03-02 10:22:45 +01:00
# load local module as electrum
2013-03-15 13:00:59 +01:00
if __builtin__ . use_local_modules :
2013-03-02 10:22:45 +01:00
import imp
2013-03-15 10:49:08 +01:00
imp . load_module ( ' electrum ' , * imp . find_module ( ' lib ' ) )
imp . load_module ( ' electrum_gui ' , * imp . find_module ( ' gui ' ) )
2012-02-03 08:02:12 +01:00
2013-03-02 10:22:45 +01:00
from electrum import *
2012-06-06 19:26:05 +02:00
2012-10-12 01:50:54 +02:00
# get password routine
def prompt_password ( prompt , confirm = True ) :
import getpass
if sys . stdin . isatty ( ) :
password = getpass . getpass ( prompt )
if password and confirm :
password2 = getpass . getpass ( " Confirm: " )
if password != password2 :
sys . exit ( " Error: Passwords do not match. " )
else :
password = raw_input ( prompt )
if not password :
password = None
return password
2012-11-23 14:31:25 +01:00
def arg_parser ( ) :
2012-05-14 17:35:38 +02:00
usage = " usage: % prog [options] command \n Commands: " + ( ' , ' . join ( known_commands ) )
2012-08-25 14:16:21 -07:00
parser = optparse . OptionParser ( prog = usage )
2012-10-17 15:33:59 +02:00
parser . add_option ( " -g " , " --gui " , dest = " gui " , help = " User interface: qt, lite, gtk or text " )
2011-11-29 11:23:49 +01:00
parser . add_option ( " -w " , " --wallet " , dest = " wallet_path " , help = " wallet path (default: electrum.dat) " )
2012-05-13 10:19:28 +02:00
parser . add_option ( " -o " , " --offline " , action = " store_true " , dest = " offline " , default = False , help = " remain offline " )
2011-11-14 20:35:54 +01:00
parser . add_option ( " -a " , " --all " , action = " store_true " , dest = " show_all " , default = False , help = " show all addresses " )
2013-03-01 11:33:51 +01:00
parser . add_option ( " -b " , " --balance " , action = " store_true " , dest = " show_balance " , default = False , help = " show the balance of listed addresses " )
2013-03-01 11:21:10 +01:00
parser . add_option ( " -l " , " --labels " , action = " store_true " , dest = " show_labels " , default = False , help = " show the labels of listed addresses " )
2013-03-23 09:23:57 +01:00
parser . add_option ( " -f " , " --fee " , dest = " tx_fee " , default = None , help = " set tx fee " )
2012-10-11 20:10:12 +02:00
parser . add_option ( " -F " , " --fromaddr " , dest = " from_addr " , default = None , help = " set source address for payto/mktx. if it isn ' t in the wallet, it will ask for the private key unless supplied in the format public_key:private_key. It ' s not saved in the wallet. " )
2012-02-08 09:36:19 +01:00
parser . add_option ( " -c " , " --changeaddr " , dest = " change_addr " , default = None , help = " set the change address for payto/mktx. default is a spare address, or the source address if it ' s not in the wallet " )
2012-10-11 20:10:12 +02:00
parser . add_option ( " -s " , " --server " , dest = " server " , default = None , help = " set server host:port:protocol, where protocol is t or h " )
2012-10-01 18:14:50 +02:00
parser . add_option ( " -p " , " --proxy " , dest = " proxy " , default = None , help = " set proxy [type:]host[:port], where type is socks4,socks5 or http " )
2012-11-04 12:27:01 +01:00
parser . add_option ( " -v " , " --verbose " , action = " store_true " , dest = " verbose " , default = False , help = " show debugging information " )
2012-12-17 15:08:34 +01:00
parser . add_option ( " -P " , " --portable " , action = " store_true " , dest = " portable " , default = False , help = " portable wallet " )
2013-01-02 16:03:54 +01:00
parser . add_option ( " -L " , " --lang " , dest = " language " , default = None , help = " defaut language used in GUI " )
2013-01-07 16:03:03 +00:00
parser . add_option ( " -u " , " --usb " , dest = " bitkey " , action = " store_true " , help = " Turn on support for hardware wallets (EXPERIMENTAL) " )
2012-11-23 14:31:25 +01:00
return parser
2012-11-18 11:34:52 +01:00
2011-11-04 18:00:37 +01:00
2012-11-18 11:34:52 +01:00
if __name__ == ' __main__ ' :
2012-11-23 14:31:25 +01:00
parser = arg_parser ( )
options , args = parser . parse_args ( )
2013-04-11 22:06:55 +02:00
if options . portable and options . wallet_path is None :
options . wallet_path = os . path . dirname ( os . path . realpath ( __file__ ) ) + ' /electrum.dat '
2012-11-04 12:27:01 +01:00
set_verbosity ( options . verbose )
2012-10-29 16:22:53 +01:00
2012-10-11 20:10:12 +02:00
# config is an object passed to the various constructors (wallet, interface, gui)
2013-03-12 13:48:16 +01:00
if is_android :
2013-03-12 14:12:27 +01:00
config_options = { ' wallet_path ' : " /sdcard/electrum.dat " , ' portable ' : True , ' verbose ' : True , ' gui ' : ' android ' , ' auto_cycle ' : True }
2012-11-18 11:34:52 +01:00
else :
2012-11-19 14:05:42 +01:00
config_options = eval ( str ( options ) )
for k , v in config_options . items ( ) :
if v is None : config_options . pop ( k )
2012-11-18 11:34:52 +01:00
2013-02-18 23:29:19 +01:00
# Wallet migration on Electrum 1.7
# Todo: In time we could remove this again
if platform . system ( ) == " Windows " :
util . check_windows_wallet_migration ( )
2012-11-19 14:05:42 +01:00
config = SimpleConfig ( config_options )
2012-10-11 20:10:12 +02:00
wallet = Wallet ( config )
2013-03-02 16:29:14 +01:00
2012-03-12 17:55:33 +01:00
2012-02-14 12:45:39 +01:00
if len ( args ) == 0 :
url = None
cmd = ' gui '
elif len ( args ) == 1 and re . match ( ' ^bitcoin: ' , args [ 0 ] ) :
url = args [ 0 ]
cmd = ' gui '
else :
cmd = args [ 0 ]
2012-08-22 11:36:04 -07:00
2012-02-11 13:14:12 +01:00
2013-03-02 18:03:29 +01:00
if cmd == ' gui ' :
gui_name = config . get ( ' gui ' , ' classic ' )
try :
2013-03-02 18:10:22 +01:00
gui = __import__ ( ' electrum_gui.gui_ ' + gui_name , fromlist = [ ' electrum_gui ' ] )
2013-03-02 18:03:29 +01:00
except ImportError :
sys . exit ( " Error: Unknown GUI: " + gui_name )
2012-11-20 15:30:46 +01:00
2012-10-22 11:34:21 +02:00
interface = Interface ( config , True )
2012-11-20 15:30:46 +01:00
wallet . interface = interface
2012-10-26 09:08:06 +02:00
2012-11-20 17:21:57 +01:00
gui = gui . ElectrumGui ( wallet , config )
2012-11-20 15:30:46 +01:00
found = config . wallet_file_exists
if not found :
a = gui . restore_or_create ( )
if not a : exit ( )
if a == ' create ' :
2013-02-03 15:08:26 +01:00
wallet . init_seed ( None )
2013-04-09 18:08:14 +02:00
gui . show_seed ( )
2013-04-10 12:56:07 +02:00
if gui . verify_seed ( ) :
wallet . save_seed ( )
else :
2013-04-09 18:08:14 +02:00
exit ( )
2012-11-20 15:30:46 +01:00
else :
# ask for seed and gap.
2013-01-08 14:29:42 +01:00
sg = gui . seed_dialog ( )
if not sg : exit ( )
seed , gap = sg
if not seed : exit ( )
wallet . gap_limit = gap
if len ( seed ) == 128 :
2013-02-03 15:08:26 +01:00
wallet . seed = ' '
2013-03-07 16:41:43 +01:00
wallet . init_sequence ( str ( seed ) )
2013-01-08 14:29:42 +01:00
else :
2013-02-03 15:08:26 +01:00
wallet . init_seed ( str ( seed ) )
2013-04-10 11:53:13 +02:00
wallet . save_seed ( )
2013-01-08 14:29:42 +01:00
2013-04-09 18:08:14 +02:00
# select a server.
s = gui . network_dialog ( )
interface . start ( wait = False )
interface . send ( [ ( ' server.peers.subscribe ' , [ ] ) ] )
2012-11-20 15:30:46 +01:00
2013-04-09 18:08:14 +02:00
# generate the first addresses, in case we are offline
if not found and ( s is None or a == ' create ' ) :
wallet . synchronize ( )
2012-11-20 15:30:46 +01:00
2012-11-04 20:53:27 +01:00
verifier = WalletVerifier ( interface , config )
2013-03-12 23:53:56 +01:00
verifier . start ( )
2012-11-04 20:53:27 +01:00
wallet . set_verifier ( verifier )
2012-11-24 20:31:07 +01:00
synchronizer = WalletSynchronizer ( wallet , config )
synchronizer . start ( )
2012-02-14 09:52:03 +01:00
2012-11-20 15:30:46 +01:00
if not found and a == ' restore ' and s is not None :
try :
2012-11-20 21:36:06 +01:00
keep_it = gui . restore_wallet ( )
wallet . fill_addressbook ( )
2012-11-20 15:30:46 +01:00
except :
import traceback
traceback . print_exc ( file = sys . stdout )
exit ( )
2012-10-26 09:08:06 +02:00
2012-11-20 21:36:06 +01:00
if not keep_it : exit ( )
2012-10-26 09:08:06 +02:00
2012-11-20 21:46:45 +01:00
if not found :
gui . password_dialog ( )
2012-11-20 21:36:06 +01:00
wallet . save ( )
2012-02-14 12:45:39 +01:00
gui . main ( url )
2011-11-09 23:21:27 +01:00
wallet . save ( )
2012-11-24 20:31:07 +01:00
2012-11-05 23:10:38 +01:00
verifier . stop ( )
synchronizer . stop ( )
2012-11-24 20:31:07 +01:00
interface . stop ( )
2012-12-05 10:24:30 +01:00
# we use daemon threads, their termination is enforced.
# this sleep command gives them time to terminate cleanly.
time . sleep ( 0.1 )
2011-11-10 09:34:27 +01:00
sys . exit ( 0 )
2011-11-04 18:00:37 +01:00
2012-01-15 18:45:30 +01:00
if cmd not in known_commands :
cmd = ' help '
2012-10-11 20:10:12 +02:00
if not config . wallet_file_exists and cmd not in [ ' help ' , ' create ' , ' restore ' ] :
2012-11-23 18:48:56 +01:00
print_msg ( " Error: Wallet file not found. " )
print_msg ( " Type ' electrum create ' to create a new wallet, or provide a path to a wallet with the -w option " )
2011-11-16 18:26:06 +03:00
sys . exit ( 0 )
2012-02-21 14:36:45 +01:00
if cmd in [ ' create ' , ' restore ' ] :
2012-10-11 20:10:12 +02:00
if config . wallet_file_exists :
2012-08-19 17:16:35 -07:00
sys . exit ( " Error: Remove the existing wallet first! " )
2012-07-06 21:45:57 -07:00
password = prompt_password ( " Password (hit return if you do not wish to encrypt your wallet): " )
2011-11-04 18:00:37 +01:00
2012-10-11 20:10:12 +02:00
server = config . get ( ' server ' )
if not server : server = pick_random_server ( )
w_host , w_port , w_protocol = server . split ( ' : ' )
2012-03-31 06:39:23 +02:00
host = raw_input ( " server (default: %s ): " % w_host )
port = raw_input ( " port (default: %s ): " % w_port )
protocol = raw_input ( " protocol [t=tcp;h=http;n=native] (default: %s ): " % w_protocol )
2012-02-06 07:48:52 +01:00
fee = raw_input ( " fee (default: %s ): " % ( str ( Decimal ( wallet . fee ) / 100000000 ) ) )
2012-02-19 14:31:21 +02:00
gap = raw_input ( " gap limit (default 5): " )
2012-03-31 06:39:23 +02:00
if host : w_host = host
if port : w_port = port
if protocol : w_protocol = protocol
2012-10-11 20:10:12 +02:00
wallet . config . set_key ( ' server ' , w_host + ' : ' + w_port + ' : ' + w_protocol )
2012-02-21 14:36:45 +01:00
if fee : wallet . fee = float ( fee )
2012-02-19 14:31:21 +02:00
if gap : wallet . gap_limit = int ( gap )
2012-02-21 14:36:45 +01:00
if cmd == ' restore ' :
seed = raw_input ( " seed: " )
try :
seed . decode ( ' hex ' )
except :
2012-07-07 09:24:52 -07:00
print_error ( " Warning: Not hex, trying decode. " )
2012-11-04 19:40:17 +01:00
seed = mnemonic_decode ( seed . split ( ' ' ) )
2012-02-21 14:36:45 +01:00
if not seed :
2012-08-19 17:17:47 -07:00
sys . exit ( " Error: No seed " )
2012-02-21 14:36:45 +01:00
2013-01-08 21:30:03 +01:00
if len ( seed ) == 128 :
wallet . seed = None
2013-03-07 16:45:55 +01:00
wallet . init_sequence ( str ( seed ) )
2013-01-08 21:30:03 +01:00
else :
2013-03-13 15:31:24 +01:00
wallet . init_seed ( str ( seed ) )
2013-04-14 19:32:25 +02:00
wallet . save_seed ( )
2012-11-04 21:12:08 +01:00
2013-04-16 15:17:32 +02:00
interface = Interface ( config )
2013-01-08 21:30:03 +01:00
if not options . offline :
2013-03-13 15:26:29 +01:00
if not interface . start ( wait = True ) :
2013-04-16 15:19:41 +02:00
print_msg ( " Not connected, aborting. Try option -o if you want to restore offline. " )
2013-03-13 15:26:29 +01:00
sys . exit ( 1 )
2012-11-04 21:12:08 +01:00
wallet . interface = interface
verifier = WalletVerifier ( interface , config )
2013-03-12 23:53:56 +01:00
verifier . start ( )
2012-11-04 21:12:08 +01:00
wallet . set_verifier ( verifier )
2012-11-23 18:48:56 +01:00
print_msg ( " Recovering wallet... " )
2012-11-05 13:12:22 +01:00
WalletSynchronizer ( wallet , config ) . start ( )
2012-05-13 10:19:28 +02:00
wallet . update ( )
if wallet . is_found ( ) :
2012-11-23 18:48:56 +01:00
print_msg ( " Recovery successful " )
2012-05-13 10:19:28 +02:00
else :
2012-11-23 18:48:56 +01:00
print_msg ( " Warning: Found no history for this wallet " )
2012-09-20 16:46:11 +07:00
else :
2013-04-16 15:17:32 +02:00
interface . start ( wait = False )
2012-09-20 16:46:11 +07:00
wallet . synchronize ( )
2012-05-13 10:19:28 +02:00
wallet . fill_addressbook ( )
wallet . save ( )
2012-11-23 18:48:56 +01:00
print_msg ( " Wallet saved in ' %s ' " % wallet . config . path )
2011-11-06 11:13:58 +01:00
else :
2013-02-03 15:08:26 +01:00
wallet . init_seed ( None )
2013-04-14 19:32:25 +02:00
wallet . save_seed ( )
2012-03-23 20:58:54 +01:00
wallet . synchronize ( ) # there is no wallet thread
2012-02-21 17:13:34 +01:00
wallet . save ( )
2012-11-23 18:48:56 +01:00
print_msg ( " Your wallet generation seed is: " + wallet . seed )
print_msg ( " Please keep it in a safe place; if you lose it, you will not be able to restore your wallet. " )
print_msg ( " Equivalently, your wallet seed can be stored and recovered with the following mnemonic code: " )
print_msg ( " \" " + ' ' . join ( mnemonic_encode ( wallet . seed ) ) + " \" " )
print_msg ( " Wallet saved in ' %s ' " % wallet . config . path )
2012-05-17 08:49:30 +02:00
if password :
wallet . update_password ( wallet . seed , None , password )
2011-11-04 18:00:37 +01:00
2013-02-28 17:21:30 +01:00
# terminate
sys . exit ( 0 )
2011-11-12 00:07:41 +01:00
2013-02-27 09:04:22 +01:00
2012-10-02 13:15:10 +02:00
# important warning
2013-02-26 16:03:04 +01:00
if cmd in [ ' dumpprivkey ' , ' dumpprivkeys ' ] :
2012-11-23 18:48:56 +01:00
print_msg ( " WARNING: ALL your private keys are secret. " )
print_msg ( " Exposing a single private key can compromise your entire wallet! " )
print_msg ( " In particular, DO NOT use ' redeem private key ' services proposed by third parties. " )
2012-10-02 13:15:10 +02:00
2011-11-14 20:35:54 +01:00
# commands needing password
2013-02-26 16:03:04 +01:00
if cmd in protected_commands :
2013-02-26 13:56:48 +01:00
if wallet . use_encryption :
2013-01-02 13:39:50 +01:00
password = prompt_password ( ' Password: ' , False )
if not password :
print_msg ( " Error: Password required " )
exit ( 1 )
# check password
try :
2013-01-06 09:41:06 +01:00
seed = wallet . decode_seed ( password )
2013-01-02 13:39:50 +01:00
except :
print_msg ( " Error: This password does not decode this wallet. " )
exit ( 1 )
else :
password = None
2013-01-06 15:57:01 +01:00
seed = wallet . seed
2013-02-26 13:56:48 +01:00
else :
password = None
2011-12-20 14:22:31 +01:00
2013-03-01 14:08:51 +01:00
# add missing arguments, do type conversions
2013-01-05 21:28:12 +01:00
if cmd == ' importprivkey ' :
2012-08-01 21:52:52 +02:00
# See if they specificed a key on the cmd line, if not prompt
2013-02-26 13:56:48 +01:00
if len ( args ) == 1 :
args [ 1 ] = prompt_password ( ' Enter PrivateKey (will not echo): ' , False )
elif cmd == ' signrawtransaction ' :
2013-02-27 18:11:45 +01:00
args = [ cmd , args [ 1 ] , json . loads ( args [ 2 ] ) if len ( args ) > 2 else [ ] , json . loads ( args [ 3 ] ) if len ( args ) > 3 else [ ] ]
2011-12-20 12:37:48 +01:00
2013-02-26 13:56:48 +01:00
elif cmd == ' createmultisig ' :
2013-02-27 18:11:45 +01:00
args = [ cmd , int ( args [ 1 ] ) , json . loads ( args [ 2 ] ) ]
2013-02-26 13:56:48 +01:00
elif cmd == ' createrawtransaction ' :
2013-02-27 18:11:45 +01:00
args = [ cmd , json . loads ( args [ 1 ] ) , json . loads ( args [ 2 ] ) ]
2013-02-26 16:03:04 +01:00
2013-03-04 17:36:49 +01:00
elif cmd == ' listaddresses ' :
2013-03-01 11:21:10 +01:00
args = [ cmd , options . show_all , options . show_balance , options . show_labels ]
2013-02-26 13:56:48 +01:00
elif cmd in [ ' payto ' , ' mktx ' ] :
2013-04-05 16:00:34 +02:00
domain = [ options . from_addr ] if options . from_addr else None
args = [ ' mktx ' , args [ 1 ] , Decimal ( args [ 2 ] ) , Decimal ( options . tx_fee ) if options . tx_fee else None , options . change_addr , domain ]
2013-02-26 13:56:48 +01:00
2013-03-04 17:36:49 +01:00
elif cmd == ' help ' :
if len ( args ) < 2 :
parser . print_help ( )
print_msg ( " Type ' electrum help <command> ' to see the help for a specific command " )
print_msg ( " Type ' electrum --help ' to see the list of options " )
2013-02-26 13:56:48 +01:00
2013-03-01 13:33:11 +01:00
# check the number of arguments
min_args , max_args , description , syntax , options_syntax = known_commands [ cmd ]
if len ( args ) - 1 < min_args :
print_msg ( " Not enough arguments " )
print_msg ( " Syntax: " , syntax )
sys . exit ( 1 )
if max_args > = 0 and len ( args ) - 1 > max_args :
print_msg ( " too many arguments " , args )
print_msg ( " Syntax: " , syntax )
sys . exit ( 1 )
if max_args < 0 :
2013-03-13 17:52:54 +01:00
if len ( args ) > min_args + 1 :
2013-03-01 13:33:11 +01:00
message = ' ' . join ( args [ min_args : ] )
print_msg ( " Warning: Final argument was reconstructed from several arguments: " , repr ( message ) )
args = args [ 0 : min_args ] + [ message ]
# open session
if cmd not in offline_commands and not options . offline :
interface = Interface ( config )
interface . register_callback ( ' connected ' , lambda : sys . stderr . write ( " Connected to " + interface . connection_msg + " \n " ) )
2013-03-13 15:26:29 +01:00
if not interface . start ( wait = True ) :
print_msg ( " Not connected, aborting. " )
sys . exit ( 1 )
2013-03-01 13:33:11 +01:00
wallet . interface = interface
verifier = WalletVerifier ( interface , config )
2013-03-12 23:53:56 +01:00
verifier . start ( )
2013-03-01 13:33:11 +01:00
wallet . set_verifier ( verifier )
synchronizer = WalletSynchronizer ( wallet , config )
synchronizer . start ( )
wallet . update ( )
wallet . save ( )
2013-02-26 13:56:48 +01:00
# run the command
2011-11-16 18:12:13 +03:00
2013-03-04 17:36:49 +01:00
if cmd == ' deseed ' :
2012-05-13 01:32:28 +02:00
if not wallet . seed :
2012-11-27 23:32:39 +01:00
print_msg ( " Error: This wallet has no seed " )
2012-05-13 00:43:22 +02:00
else :
2013-02-25 10:49:31 +01:00
ns = wallet . config . path + ' .seedless '
print_msg ( " Warning: you are going to create a seedless wallet ' \n It will be saved in ' %s ' " % ns )
2012-05-13 01:32:28 +02:00
if raw_input ( " Are you sure you want to continue? (y/n) " ) in [ ' y ' , ' Y ' , ' yes ' ] :
2013-02-25 10:49:31 +01:00
wallet . config . path = ns
2012-05-13 01:32:28 +02:00
wallet . seed = ' '
2013-02-27 18:01:58 +01:00
wallet . use_encryption = False
2013-02-24 21:31:11 +01:00
wallet . config . set_key ( ' seed ' , ' ' , True )
2012-05-17 18:10:36 +02:00
for k in wallet . imported_keys . keys ( ) : wallet . imported_keys [ k ] = ' '
2012-05-13 01:32:28 +02:00
wallet . save ( )
2012-11-23 18:48:56 +01:00
print_msg ( " Done. " )
2012-05-13 01:32:28 +02:00
else :
2012-11-27 23:32:39 +01:00
print_msg ( " Action canceled. " )
2012-05-13 01:32:28 +02:00
2012-02-06 18:13:33 +01:00
elif cmd == ' eval ' :
2012-11-23 18:48:56 +01:00
print_msg ( eval ( args [ 1 ] ) )
2012-02-06 18:55:25 +01:00
wallet . save ( )
2012-02-03 17:38:43 +01:00
2013-03-01 13:40:04 +01:00
elif cmd == ' getconfig ' :
2012-10-26 17:35:35 +02:00
key = args [ 1 ]
2012-11-23 18:48:56 +01:00
print_msg ( wallet . config . get ( key ) )
2012-10-26 17:35:35 +02:00
2013-03-01 13:40:04 +01:00
elif cmd == ' setconfig ' :
2012-10-20 10:23:34 +02:00
key , value = args [ 1 : 3 ]
2012-10-28 09:19:07 +01:00
if key not in [ ' seed ' , ' seed_version ' , ' master_public_key ' , ' use_encryption ' ] :
2012-10-20 10:23:34 +02:00
wallet . config . set_key ( key , value , True )
2012-11-23 18:48:56 +01:00
print_msg ( True )
2012-10-20 10:23:34 +02:00
else :
2012-11-23 18:48:56 +01:00
print_msg ( False )
2012-10-20 10:23:34 +02:00
2011-11-04 18:00:37 +01:00
elif cmd == ' password ' :
2012-07-06 21:45:57 -07:00
new_password = prompt_password ( ' New password: ' )
wallet . update_password ( seed , password , new_password )
2011-11-04 18:00:37 +01:00
2013-02-26 13:56:48 +01:00
else :
cmd_runner = Commands ( wallet , interface )
func = eval ( ' cmd_runner. ' + cmd )
2013-02-27 10:24:53 +01:00
cmd_runner . password = password
2013-03-01 14:27:56 +01:00
try :
result = func ( * args [ 1 : ] )
except BaseException , e :
print_msg ( " Error: " + str ( e ) )
sys . exit ( 1 )
2013-02-27 10:24:53 +01:00
if type ( result ) == str :
util . print_msg ( result )
2013-03-04 17:36:49 +01:00
elif result is not None :
2013-02-27 10:24:53 +01:00
util . print_json ( result )
2013-02-26 17:57:48 +01:00
2013-02-20 13:10:32 +01:00
2012-11-05 23:10:38 +01:00
if cmd not in offline_commands and not options . offline :
2013-02-25 22:21:07 +01:00
verifier . stop ( )
2012-11-05 23:10:38 +01:00
synchronizer . stop ( )
2013-02-25 22:21:07 +01:00
interface . stop ( )
time . sleep ( 0.1 )
sys . exit ( 0 )