def rpc_remove_connection(client, source, dest, rpc_user=BTC_RPC_USER, rpc_password=BTC_RPC_PASSWD, rpc_port=BTC_RPC_PORT): """ Creates a connection between two bitcoind nodes (from source to dest). Both ends must be running a bitcoind instance. :param client: docker client :param source: container IP (with bitcoind running) :param dest: container IP (with bitcoind running) :param rpc_user: bitcoind rpc user :param rpc_password: bitcoind rpc password :param rpc_port: bitcoind rpc port :return: boolean, whether the connection was successful """ try: rpc_server = get_ip_by_unknown(client, source) dest = get_ip_by_unknown(client, dest) rpc_connection = AuthServiceProxy( "http://%s:%s@%s:%s" % (rpc_user, rpc_password, rpc_server, rpc_port)) rpc_connection.addnode(dest, "remove") return True except JSONRPCException as err: print(err) return False
def rpc_create_connection(client, source, dest,crypto="btc", rpc_user=BTC_RPC_USER, rpc_password=BTC_RPC_PASSWD, rpc_port=BTC_RPC_PORT): """ Creates a connection between two bitcoind nodes (from source to dest). Both ends must be running a bitcoind instance. :param client: docker client :param source: container IP (with bitcoind running) :param dest: container IP (with bitcoind running) :param rpc_user: bitcoind rpc user :param rpc_password: bitcoind rpc password :param rpc_port: bitcoind rpc port :return: boolean, whether the connection was successful """ try: if(crypto=="btc"): rpc_server = get_ip_by_unknown(client, source) dest = get_ip_by_unknown(client, dest) rpc_port=BTC_RPC_PORT #print rpc_user+" "+rpc_password+" "+rpc_server+ " "+str(rpc_port)+ " "+dest rpc_connection = AuthServiceProxy("http://%s:%s@%s:%s" % (rpc_user, rpc_password, rpc_server, rpc_port)) r=rpc_connection.addnode(dest, "add") #print rpc_user+" "+rpc_password+" "+rpc_server+ " "+str(rpc_port)+ " "+dest elif(crypto=="zch"): rpc_server_list = get_ip_by_container_name_with_multiple_interface(client, source,DOCK_NETWORK_NAME_ZCH) dest_list = get_ip_by_container_name_with_multiple_interface(client, dest,DOCK_NETWORK_NAME_ZCH) rpc_port=ZCH_RPC_PORT if(len(rpc_server_list)>1): rpc_server=rpc_server_list[1] else: rpc_server=rpc_server_list[0] if(len(dest_list)>1): dest=dest_list[1] else: dest=dest_list[0] rpc_connection = AuthServiceProxy("http://%s:%s@%s:%s" % (rpc_user, rpc_password, rpc_server, rpc_port)) r=rpc_connection.addnode(dest, "add") #rpc_connection = AuthServiceProxy("http://%s:%s@%s:%s" % (rpc_user, rpc_password, rpc_server, rpc_port)) #r=rpc_connection.addnode(dest, "onetry") #print rpc_user+" "+rpc_password+" "+rpc_server+ " "+str(rpc_port)+ " "+dest return True except JSONRPCException as err: print(err) return False
if b'rpcuser' not in contents.keys(): print('''RPC user is not found in the %s file.''' % (conf_path)) sys.exit() rpcuser = contents[b'rpcuser'].decode() rpcpassword = contents[b'rpcpassword'].decode() rpcport = 8464 rpclisten = '127.0.0.1' if b'rpcport' in contents.keys(): rpcport = contents[b'rpcport'].decode() if b'rpclisten' in contents.keys(): rpclisten = contents[b'rpclisten'].decode() access = AuthServiceProxy('http://%s:%s@%s:%d/' % (rpcuser, rpcpassword, rpclisten, int(rpcport))) for node in json.loads(data.decode()): print ('Adding', node) try: access.addnode(node, 'add') except socket_error as e: if e.errno == errno.ECONNREFUSED: print ('Unable to communicate with goldpressedlatinum RPC') break except JSONRPCException as e: if e.code == -23: print ('Already added') continue break
except: print "\n---An error occurred---\n" elif cmd == "gethashespersec": try: print access.gethashespersec() except: print "\n---An error occurred---\n" elif cmd == "getinfo": print access.getinfo() elif cmd == "getpeerinfo": print access.getpeerinfo() elif cmd == "addnode": cmd = raw_input("node addr:port to add?: ") print access.addnode(cmd, "add") elif cmd == "getnewaddress": try: acct = raw_input("Enter an account name: ") try: print access.getnewaddress(acct) except: print access.getnewaddress() except: print "\n---An error occurred---\n" elif cmd == "getreceivedbyaccount": try: acct = raw_input("Enter an account (optional): ") mc = raw_input("Minimum confirmations (optional): ") try:
if b"rpcuser" not in contents.keys(): print("""RPC user is not found in the %s file.""" % (conf_path)) sys.exit() rpcuser = contents[b"rpcuser"].decode() rpcpassword = contents[b"rpcpassword"].decode() rpcport = 8344 rpclisten = "127.0.0.1" if b"rpcport" in contents.keys(): rpcport = contents[b"rpcport"].decode() if b"rpclisten" in contents.keys(): rpclisten = contents[b"rpclisten"].decode() access = AuthServiceProxy("http://%s:%s@%s:%d/" % (rpcuser, rpcpassword, rpclisten, int(rpcport))) for node in json.loads(data.decode()): print("Adding", node) try: access.addnode(node, "add") except socket_error as e: if e.errno == errno.ECONNREFUSED: print("Unable to communicate with Novacoin RPC") break except JSONRPCException as e: if e.code == -23: print("Already added") continue break
from subprocess import call from bitcoinrpc.authproxy import AuthServiceProxy import docker import time #Deploit les images dockers et connecte les noeuds Bitcoin entre eux print("************************DEPLOY************************") client = docker.from_env() for x in range(1, 4): client.containers.run("bitcoin-template", "bitcoind -regtest -zmqpubrawblock=tcp://0.0.0.0:2833"+str(x)+" -zmqpubrawtx=tcp://0.0.0.0:2833"+str(x), detach=True, name="bit"+str(x), mem_limit="256m", ports={'2833'+str(x)+'/tcp': ('0.0.0.0', 28330+x)}) time.sleep(5) accessip = AuthServiceProxy("http://*****:*****@172.17.0.4:18332") for y in range(1, 4): accessip.addnode("172.17.0."+str(y+1), "onetry") print 1 accessip = AuthServiceProxy("http://*****:*****@172.17.0.3:18332") for y in range(1, 4): accessip.addnode("172.17.0."+str(y+1), "onetry") print 2 accessip = AuthServiceProxy("http://*****:*****@172.17.0.2:18332") for y in range(1, 4): accessip.addnode("172.17.0."+str(y+1), "onetry") print 3 print("*************************DONE************************")
if b'rpcuser' not in contents.keys(): print('''RPC user is not found in the %s file.''' % (conf_path)) sys.exit() rpcuser = contents[b'rpcuser'].decode() rpcpassword = contents[b'rpcpassword'].decode() rpcport = 8344 rpclisten = '127.0.0.1' if b'rpcport' in contents.keys(): rpcport = contents[b'rpcport'].decode() if b'rpclisten' in contents.keys(): rpclisten = contents[b'rpclisten'].decode() access = AuthServiceProxy("http://"+rpcuser+":"+rpcpassword+"@"+rpclisten+":"+rpcport+"/") for node in json.loads(data.decode()): print ('Adding', node) try: access.addnode(node, 'add') except socket_error as e: if e.errno == errno.ECONNREFUSED: print ('Unable to communicate with Novacoin RPC') break except JSONRPCException as e: if e.code == -23: print ('Already added') continue break
#Deploit les images dockers et connecte les noeuds Bitcoin entre eux print("************************DEPLOY************************") client = docker.from_env() for x in range(1, 4): client.containers.run( "bitcoin-template", "bitcoind -regtest -zmqpubrawblock=tcp://0.0.0.0:2833" + str(x) + " -zmqpubrawtx=tcp://0.0.0.0:2833" + str(x), detach=True, name="bit" + str(x), mem_limit="256m", ports={'2833' + str(x) + '/tcp': ('0.0.0.0', 28330 + x)}) time.sleep(5) accessip = AuthServiceProxy("http://*****:*****@172.17.0.4:18332") for y in range(1, 4): accessip.addnode("172.17.0." + str(y + 1), "onetry") print 1 accessip = AuthServiceProxy("http://*****:*****@172.17.0.3:18332") for y in range(1, 4): accessip.addnode("172.17.0." + str(y + 1), "onetry") print 2 accessip = AuthServiceProxy("http://*****:*****@172.17.0.2:18332") for y in range(1, 4): accessip.addnode("172.17.0." + str(y + 1), "onetry") print 3 print("*************************DONE************************")