<s> from decimal import Decimal <EOL> import json <EOL> import optparse <EOL> import os <EOL> import re <EOL> import ast <EOL> import sys <EOL> import time <EOL> import traceback <EOL> try : <EOL> import ecdsa <EOL> except ImportError : <EOL> sys . exit ( "<STR_LIT>" ) <EOL> try : <EOL> import aes <EOL> except ImportError : <EOL> sys . exit ( "<STR_LIT>" ) <EOL> is_local = os . path . dirname ( os . path . realpath ( __file__ ) ) == os . getcwd ( ) <EOL> is_android = '<STR_LIT>' in os . environ <EOL> import __builtin__ <EOL> __builtin__ . use_local_modules = is_local or is_android <EOL> if __builtin__ . use_local_modules : <EOL> import imp <EOL> from electrum import * <EOL> def prompt_password ( prompt , confirm = True ) : <EOL> import getpass <EOL> if sys . stdin . isatty ( ) : <EOL> password = getpass . getpass ( prompt ) <EOL> if password and confirm : <EOL> password2 = getpass . getpass ( "<STR_LIT>" ) <EOL> if password != password2 : <EOL> sys . exit ( "<STR_LIT>" ) <EOL> else : <EOL> password = raw_input ( prompt ) <EOL> if not password : <EOL> password = None <EOL> return password <EOL> def arg_parser ( ) : <EOL> usage = "<STR_LIT>" <EOL> parser = optparse . OptionParser ( prog = usage , add_help_option = False ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT>" , callback = print_help_cb , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , default = None , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , default = None , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT:-c>" , "<STR_LIT>" , dest = "<STR_LIT>" , default = None , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , default = None , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , default = None , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , default = None , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , default = None , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT:password>" , default = None , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , default = False , help = "<STR_LIT>" ) <EOL> return parser <EOL> def print_help ( parser ) : <EOL> parser . print_help ( ) <EOL> print_msg ( "<STR_LIT>" ) <EOL> print_msg ( "<STR_LIT>" ) <EOL> run_command ( known_commands [ '<STR_LIT>' ] ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def print_help_cb ( self , opt , value , parser ) : <EOL> print_help ( parser ) <EOL> def run_command ( cmd , password = None , args = [ ] ) : <EOL> import socket <EOL> if cmd . requires_network and not options . offline : <EOL> network = NetworkProxy ( config ) <EOL> if not network . start ( start_daemon = ( True if cmd . name != '<STR_LIT>' else False ) ) : <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if wallet : <EOL> wallet . start_threads ( network ) <EOL> wallet . update ( ) <EOL> else : <EOL> network = None <EOL> cmd_runner = Commands ( wallet , network ) <EOL> func = getattr ( cmd_runner , cmd . name ) <EOL> cmd_runner . password = password <EOL> try : <EOL> result = func ( * args [ <NUM_LIT:1> : ] ) <EOL> except Exception : <EOL> traceback . print_exc ( file = sys . stdout ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if cmd . requires_network and not options . offline : <EOL> if wallet : <EOL> wallet . stop_threads ( ) <EOL> if type ( result ) == str : <EOL> util . print_msg ( result ) <EOL> elif result is not None : <EOL> util . print_json ( result ) <EOL> guiWindow = None <EOL> def main ( ) : <EOL> global guiWindow <EOL> parser = arg_parser ( ) <EOL> options , args = parser . parse_args ( ) <EOL> if options . portable and options . wallet_path is None : <EOL> options . electrum_path = os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , '<STR_LIT>' ) <EOL> if is_android : <EOL> config_options = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> else : <EOL> config_options = eval ( str ( options ) ) <EOL> for k , v in config_options . items ( ) : <EOL> if v is None : <EOL> config_options . pop ( k ) <EOL> set_verbosity ( config_options . get ( '<STR_LIT>' ) ) <EOL> config = SimpleConfig ( config_options ) <EOL> cmd = '<STR_LIT>' <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> url = None <EOL> cmd = '<STR_LIT>' <EOL> elif len ( args ) == <NUM_LIT:1> and re . match ( '<STR_LIT>' , args [ <NUM_LIT:0> ] ) : <EOL> url = args [ <NUM_LIT:0> ] <EOL> cmd = '<STR_LIT>' <EOL> else : <EOL> pass <EOL> cmd = args [ <NUM_LIT:0> ] <EOL> if cmd == '<STR_LIT>' : <EOL> gui_name = '<STR_LIT>' <EOL> if gui_name in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> gui_name = '<STR_LIT>' <EOL> try : <EOL> gui = __import__ ( '<STR_LIT>' + gui_name , fromlist = [ '<STR_LIT>' ] ) <EOL> except ImportError : <EOL> traceback . print_exc ( file = sys . stdout ) <EOL> sys . exit ( ) <EOL> if not options . offline : <EOL> network = Network ( config ) <EOL> network . start ( ) <EOL> else : <EOL> network = None <EOL> guiWindow = gui = gui . ElectrumGui ( config , network ) <EOL> gui . main ( url ) <EOL> if network : <EOL> network . stop ( ) <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if cmd not in known_commands : <EOL> cmd = '<STR_LIT>' <EOL> cmd = known_commands [ cmd ] <EOL> storage = WalletStorage ( config ) <EOL> if cmd . name in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if storage . file_exists : <EOL> sys . exit ( "<STR_LIT>" ) <EOL> if options . password is not None : <EOL> password = options . password <EOL> elif cmd . name == '<STR_LIT>' and options . mpk : <EOL> password = None <EOL> else : <EOL> password = prompt_password ( "<STR_LIT>" ) <EOL> if not config . get ( '<STR_LIT>' ) : <EOL> config . set_key ( '<STR_LIT>' , pick_random_server ( ) ) <EOL> if cmd . name == '<STR_LIT>' : <EOL> if options . mpk : <EOL> wallet = Wallet . from_mpk ( options . mpk , storage ) <EOL> else : <EOL> import getpass <EOL> seed = getpass . getpass ( prompt = "<STR_LIT>" , stream = None ) if options . concealed else raw_input ( "<STR_LIT>" ) <EOL> wallet = Wallet . from_seed ( str ( seed ) , storage ) <EOL> if not wallet : <EOL> sys . exit ( "<STR_LIT>" ) <EOL> wallet . save_seed ( password ) <EOL> if not options . offline : <EOL> network = Network ( config ) <EOL> network . start ( ) <EOL> wallet . start_threads ( network ) <EOL> print_msg ( "<STR_LIT>" ) <EOL> wallet . restore ( lambda x : x ) <EOL> if wallet . is_found ( ) : <EOL> print_msg ( "<STR_LIT>" ) <EOL> else : <EOL> print_msg ( "<STR_LIT>" ) <EOL> else : <EOL> wallet . synchronize ( ) <EOL> print_msg ( "<STR_LIT>" ) <EOL> else : <EOL> wallet = Wallet ( storage ) <EOL> wallet . init_seed ( None ) <EOL> wallet . save_seed ( password ) <EOL> wallet . synchronize ( ) <EOL> print_msg ( "<STR_LIT>" % wallet . get_mnemonic ( password ) ) <EOL> print_msg ( "<STR_LIT>" ) <EOL> print_msg ( "<STR_LIT>" % wallet . storage . path ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if cmd . name not in [ '<STR_LIT>' , '<STR_LIT>' ] and cmd . requires_wallet and not storage . file_exists : <EOL> print_msg ( "<STR_LIT>" ) <EOL> print_msg ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> if cmd . requires_wallet : <EOL> wallet = Wallet ( storage ) <EOL> else : <EOL> wallet = None <EOL> if cmd . name in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> print_msg ( "<STR_LIT>" ) <EOL> print_msg ( "<STR_LIT>" ) <EOL> print_msg ( "<STR_LIT>" ) <EOL> if cmd . requires_password : <EOL> if wallet . seed == '<STR_LIT>' : <EOL> seed = '<STR_LIT>' <EOL> password = None <EOL> elif wallet . use_encryption : <EOL> password = prompt_password ( '<STR_LIT>' , False ) <EOL> if not password : <EOL> print_msg ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> try : <EOL> seed = wallet . get_seed ( password ) <EOL> except Exception : <EOL> print_msg ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> password = None <EOL> seed = wallet . get_seed ( None ) <EOL> else : <EOL> password = None <EOL> if cmd . name == '<STR_LIT>' : <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> args [ <NUM_LIT:1> ] = prompt_password ( '<STR_LIT>' , False ) <EOL> elif cmd . name == '<STR_LIT>' : <EOL> args = [ cmd , args [ <NUM_LIT:1> ] , json . loads ( args [ <NUM_LIT:2> ] ) if len ( args ) > <NUM_LIT:2> else [ ] , json . loads ( args [ <NUM_LIT:3> ] ) if len ( args ) > <NUM_LIT:3> else [ ] ] <EOL> elif cmd . name == '<STR_LIT>' : <EOL> args = [ cmd , int ( args [ <NUM_LIT:1> ] ) , json . loads ( args [ <NUM_LIT:2> ] ) ] <EOL> elif cmd . name == '<STR_LIT>' : <EOL> args = [ cmd , json . loads ( args [ <NUM_LIT:1> ] ) , json . loads ( args [ <NUM_LIT:2> ] ) ] <EOL> elif cmd . name == '<STR_LIT>' : <EOL> args = [ cmd , options . show_all , options . show_labels ] <EOL> elif cmd . name in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> domain = [ options . from_addr ] if options . from_addr else None <EOL> args = [ '<STR_LIT>' , args [ <NUM_LIT:1> ] , Decimal ( args [ <NUM_LIT:2> ] ) , Decimal ( options . tx_fee ) if options . tx_fee else None , options . change_addr , domain ] <EOL> elif cmd . name in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> domain = [ options . from_addr ] if options . from_addr else None <EOL> outputs = [ ] <EOL> for i in range ( <NUM_LIT:1> , len ( args ) , <NUM_LIT:2> ) : <EOL> if len ( args ) < i + <NUM_LIT:2> : <EOL> print_msg ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> outputs . append ( ( args [ i ] , Decimal ( args [ i + <NUM_LIT:1> ] ) ) ) <EOL> args = [ '<STR_LIT>' , outputs , Decimal ( options . tx_fee ) if options . tx_fee else None , options . change_addr , domain ] <EOL> elif cmd . name == '<STR_LIT>' : <EOL> if len ( args ) < <NUM_LIT:2> : <EOL> print_help ( parser ) <EOL> if len ( args ) - <NUM_LIT:1> < cmd . min_args : <EOL> print_msg ( "<STR_LIT>" ) <EOL> print_msg ( "<STR_LIT>" , cmd . syntax ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if cmd . max_args >= <NUM_LIT:0> and len ( args ) - <NUM_LIT:1> > cmd . max_args : <EOL> print_msg ( "<STR_LIT>" , args ) <EOL> print_msg ( "<STR_LIT>" , cmd . syntax ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if cmd . max_args < <NUM_LIT:0> : <EOL> if len ( args ) > cmd . min_args + <NUM_LIT:1> : <EOL> message = '<STR_LIT:U+0020>' . join ( args [ cmd . min_args : ] ) <EOL> print_msg ( "<STR_LIT>" , repr ( message ) ) <EOL> args = args [ <NUM_LIT:0> : cmd . min_args ] + [ message ] <EOL> if cmd . name == '<STR_LIT>' : <EOL> if not wallet . seed : <EOL> print_msg ( "<STR_LIT>" ) <EOL> else : <EOL> ns = wallet . storage . path + '<STR_LIT>' <EOL> print_msg ( "<STR_LIT>" % ns ) <EOL> if raw_input ( "<STR_LIT>" ) in [ '<STR_LIT:y>' , '<STR_LIT:Y>' , '<STR_LIT:yes>' ] : <EOL> wallet . storage . path = ns <EOL> wallet . seed = '<STR_LIT>' <EOL> wallet . storage . put ( '<STR_LIT>' , '<STR_LIT>' , True ) <EOL> wallet . use_encryption = False <EOL> wallet . storage . put ( '<STR_LIT>' , wallet . use_encryption , True ) <EOL> for k in wallet . imported_keys . keys ( ) : <EOL> wallet . imported_keys [ k ] = '<STR_LIT>' <EOL> wallet . storage . put ( '<STR_LIT>' , wallet . imported_keys , True ) <EOL> print_msg ( "<STR_LIT>" ) <EOL> else : <EOL> print_msg ( "<STR_LIT>" ) <EOL> elif cmd . name == '<STR_LIT>' : <EOL> key = args [ <NUM_LIT:1> ] <EOL> out = config . get ( key ) <EOL> print_msg ( out ) <EOL> elif cmd . name == '<STR_LIT>' : <EOL> key , value = args [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> try : <EOL> value = ast . literal_eval ( value ) <EOL> except : <EOL> pass <EOL> config . set_key ( key , value , True ) <EOL> print_msg ( True ) <EOL> elif cmd . name == '<STR_LIT:password>' : <EOL> new_password = prompt_password ( '<STR_LIT>' ) <EOL> wallet . update_password ( password , new_password ) <EOL> else : <EOL> run_command ( cmd , password , args ) <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> sys . exit ( <NUM_LIT:0> ) </s>
