def connect_json(config): """connect to a moorecoin json-rpc server""" testnet = config.get('testnet', '0') testnet = (int(testnet) > 0) # 0/1 in config file, convert to true/false if not 'rpcport' in config: config['rpcport'] = 18332 if testnet else 8332 connect = "http://%s:%[email protected]:%s"%(config['rpcuser'], config['rpcpassword'], config['rpcport']) try: result = serviceproxy(connect) # serviceproxy is lazy-connect, so send an rpc command mostly to catch connection errors, # but also make sure the moorecoind we're talking to is/isn't testnet: if result.getmininginfo()['testnet'] != testnet: sys.stderr.write("rpc server at "+connect+" testnet setting mismatch\n") sys.exit(1) return result except: sys.stderr.write("error connecting to rpc server at "+connect+"\n") sys.exit(1)
from jsonrpc import serviceproxy import sys import string import getpass # ===== begin user settings ===== # if you do not set these you will be prompted for a password for every command rpcuser = "" rpcpass = "" # ====== end user settings ====== if rpcpass == "": access = serviceproxy("http://127.0.0.1:8332") else: access = serviceproxy("http://"+rpcuser+":"+rpcpass+"@127.0.0.1:8332") cmd = sys.argv[1].lower() if cmd == "backupwallet": try: path = raw_input("enter destination path/filename: ") print access.backupwallet(path) except exception as inst: print inst elif cmd == "encryptwallet": try: pwd = getpass.getpass(prompt="enter passphrase: ") pwd2 = getpass.getpass(prompt="repeat passphrase: ") if pwd == pwd2: access.encryptwallet(pwd)