Пример #1
0
def stopAWallet(server):
    connect = ssh(server)
    if connect:
        print("Trying to stop daemon:" + server['name'] + "\n")
        send(connect, 'dapscoin-cli ' + s['serveroption'] + ' stop')
        sleep(2)  #wait 2 seconds
        disconnect(connect)
Пример #2
0
def masternodeScript(stakingserver, masterservers=s['masterservers']):
    genStakingNodeConfigFileScript(masterservers, stakingserver)
    connect = ssh(stakingserver)
    if connect:
        send(connect, 'dapscoind ' + s['serveroption'] + '-daemon')
        key = send(connect,
                   'dapscoin-cli ' + s['serveroption'] + 'masternode genkey')
        if ((key[0].lower().find('not') == -1)
                and (key[0].lower().find('error') == -1)):
            for server in masterservers:
                genMasternodeConfigFileScript(server, stakingserver, key)
        else:
            print('could not complete process')
def UpdateCarStopList():
    """
	Loop through the hall floor calls going up
	 Get the metric of the car Floor for the floor above
	 
	 Check the current floor of each car
	"""
    # Initialize identifiers as string
    # Start with initial metric and find lowest in search do  for
    #  for lowest car metric
    carMetric = 999
    carIP = ""
    bestFloor = 0

    for floor in range(1, len(config.hallCallsUP)):
        #loop through hallCallList
        if config.hallCallsUP[floor] == 1:
            # This Hall floor button has a call to go up

            #Loop through the cars that are registered in the dictionary
            for carIP, car in config.StopMetricsDictionary.items():
                carCurrentFloor = car[
                    0]  # index 0 has this car's floor and directiom
                if car[floor] < carMetric:
                    # this car's floor has a lower metric than the last test
                    carMetric = car[floor]
                    bestFloor = floor

    #loop through the DOWN hallCallList
    for floor in range(1, len(config.hallCallsDOWN)):
        if config.hallCallsDOWN[floor] == 1:
            # This hallway floor button has a call to go Down
            #Loop through the cars that are registered in the dictionary
            for carIP, car in config.StopMetricsDictionary.items():
                # car is actually a list of floor metrics
                carCurrentFloor = car[
                    floor]  # index 0 has this car's floor and directiom
                if car[floor] < carMetric:
                    # this car's floor has a lower metric than the last test
                    metcarMetricric = car[floor]
                    bestFloor = floor

    print('    metric: ', carMetric)
    print('Best Floor: ', bestFloor)
    print('     carIP: ', carIP)
    if carMetric != 999:
        config.send('stopAtThisFloor|' + str(bestFloor), carIP)
        print('message to stop sent to car: ', carIP)

    #print ('config.StopMetricsDictionary: ', config.StopMetricsDictionary)
    return
Пример #4
0
def genMasternodeConfigFileScript(masterserver, stakingserver, nodeprivkey):
    dapsConfData = open('boot/config/dapscoin.conf',
                        'r').read() + 'externalip=' + masterserver[
                            'address'] + '\nmasternodeprivkey=' + nodeprivkey
    connect = ssh(masterserver)
    if connect:
        send(connect, 'mkdir ~/.dapscoin')
        send(connect, 'touch ~/.dapscoin/dapscoin.conf')
        send(connect, 'echo "' + dapsConfData + '">~/.dapscoin/dapscoin.conf')
        send(
            connect, 'dapscoin-cli ' + s['serveroption'] +
            '-daemon -connect ' + stakingserver['address'])
        sleep(5)
        send(connect,
             'dapscoin-cli ' + s['serveroption'] + 'masternode genkey')
        disconnect(connect)
Пример #5
0
def startStakingWallet(
    server,
    hard=False
):  #Main server producing PoW blocks, hard=true meaning to erase block data and restart wallet
    if hard:
        removeBlockchainData(s['main'])
    genStakingnodeConfigs(s['servers'], s['main'])
    connect = ssh(server)
    if connect:
        send(connect,
             'dapscoind ' + s['serveroption'] + ' -daemon')  #Start daemon
        sleep(2)  #wait 2 seconds
        if server['address'] == s['main'][
                'address']:  #Start generating PoW blocks
            send(connect,
                 'dapscoin-cli ' + s['serveroption'] + ' setgenerate true 1')
        #if hard:
        #Need to reindex explorer database
        disconnect(connect)
Пример #6
0
def transferFromMainWallet(destination, amount=s['coinamount']):
    main = s['main']
    connect = ssh(main)
    if connect:
        response = send(
            connect, 'dapscoin-cli ' + s['serveroption'] + ' sendtoaddress ' +
            destination + ' ' + amount)
        if response:
            txhash = response[0]
            return txhash
        disconnect(connect)
Пример #7
0
def awaitWorkers(workers, amount=s['coinamount']):
    ready = False
    while (not ready):
        ready = True
        for worker in workers:
            connect = ssh(worker)
            balance = send(connect,
                           'dapscoin-cli ' + s['serveroption'] + 'getbalance')
            if (balance < amount):
                ready = False
            disconnect(connect)
        sleep(s['checkworkerinterval'])
Пример #8
0
def installbinaries(server, pathtobin):
    sendFile(server,
             pathtobin + 'dapscoind.bin ' + pathtobin + 'dapscoincli.bin',
             '/usr/bin/')
    connect = ssh(server)
    if connect:
        send(connect, 'cd /usr/bin/')
        send(connect, 'rm dapscoind dapscoin-cli')
        send(connect, 'mv dapscoind.bin dapscoind')
        send(connect, 'mv dapscoin-cli.bin dapscoin-cli')
        disconnect(connect)
        return 1
    else:
        return 0
Пример #9
0
def startStaking(server):
    connect = ssh(server)
    if connect:
        result = send(connect,
                      'dapscoin-cli ' + s['serveroption'] + 'getstakingstatus')
        print result
        if ((result.find('false') != -1) or (result.find("couldn't") != -1)):
            send(connect, 'dapscoind ' + s['serveroption'] + 'stop')
            print "Waiting for 30 seconds..."
            sleep(30)
            send(connect, 'dapscoind ' + s['serveroption'] + ' -daemon')
            send(connect, 'dapscoin-cli ' + s['serveroption'] + '')
            #unlock wallet
        disconnect(connect)
Пример #10
0
def status(servers=s['servers']):
    for server in servers:
        print '\033[94m' + server['name'] + '   -   ' + server[
            'address'] + '\033[0m'
        try:
            connect = ssh(server)
            if connect:
                print '\033[92m' + send(connect, 'uptime') + '\033[0m'
                if (s['main']['name'] == server['name']
                    ):  #status checks for main server
                    res = send(connect, "ps -e|grep mongo")
                    if (len(res) > 21):
                        print '\033[92m' + res + '\033[0m'
                    else:
                        print '\033[91m' + res + '\nNo mongo service detected\033[0m'
                    res = send(connect, "ps -e|grep node")
                    if (len(res) > 21):
                        print '\033[92m' + res + '\033[0m'
                        server['mongodown'] = True
                    else:
                        print '\033[91m' + res + '\nNo node service detected\033[0m'
                        server['nodedown'] = True
                    send(connect,
                         'dapscoin-cli ' + s['serveroption'] + 'status')
                    disconnect(connect)
                    call('ping -c 1 ' + server['address'], shell=True)
                else:
                    send(
                        connect, 'dapscoin-cli ' + s['serveroption'] +
                        ' masternode status')
                    send(connect,
                         'dapscoin-cli ' + s['serveroption'] + ' getbalance')
                    disconnect(connect)
                print("\n\n")
                sleep(2)
            else:
                server['down'] = True
        except pxssh.ExceptionPxssh, err:
            print str(err)
Пример #11
0
def reboot(servers=s['servers']):
    for server in servers:
        connect = ssh(server)
        if connect:
            send(connect, 'sudo reboot')
            send(connect, getpass())
            disconnect(connect)
    sleep(60)
    for server in servers:
        connect = ssh(server)
        if connect:
            send(connect, 'dapscoind')
Пример #12
0
def genStakingNodeConfigFileScript(stakingserver,
                                   masterservers=s['masternodes']):
    nodes = ''
    for server in masterservers:
        nodes += 'addnode=' + server['address'] + '\n'
    dapsConfData = open('boot/config/dapscoin.conf', 'r').read() + nodes
    connect = ssh(stakingserver)
    if connect:
        send(connect, 'mkdir ~/.dapscoin')
        send(connect, 'touch ~/.dapscoin/dapscoin.conf')
        send(connect, 'echo "' + dapsConfData + '">~/dapscoin/dapscoin.conf')
        disconnect(connect)
Пример #13
0
def myListener(t):
    UDP_IP = "0.0.0.0"  # Listen to all incoming datagrams.
    UDP_PORT = 5005  # To this port.
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # UDP Datagram.
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.bind((UDP_IP, UDP_PORT))

    oldmsg = ""

    while True:
        msg, addr = sock.recvfrom(
            1024)  # Waits for network message, buffer size is 1024 bytes.
        if addr == '127.0.0.1':
            print("got 127.0.0.1")
            pass
        else:
            msg = msg.decode(
                'utf-8'
            )  # Change from bytes to 16 bit unicode in utf-8 format.
            ip = addr[0]
            port = addr[1]
            print('Network Listener received: ', msg, ip)

            if msg.startswith('arrived@floor'):
                msg = msg.replace('arrived@floor|', '')  # Remove the handle.
                if oldmsg != msg + ip:
                    dh.DispatchHandler(ip, msg)
                    oldmsg = msg + ip

            elif msg.startswith('stopAtThisFloor|'):
                x = []
                x = msg.split('|')
                floor = int(
                    x[1])  # Imported numbers need to be converted to integers.
                config.CarFloorStopList[floor] = 1
                print()
                print('stopAtThisFloor: ', config.CarFloorStopList)
                print()
            elif msg == 'quit':
                print("   Network Listener - Received quit message")
                t.stop()

            elif msg == 'MasterIpDiscover':
                if config.Role == 'car':
                    time.sleep(2)
                else:
                    if config.MasterIpAddress == '0':
                        if ip in config.HallCarDictionary:
                            pass  # Already present.
                        else:
                            config.HallCarDictionary = {ip: [0, 0, 0, 0, 0, 0]}
                        print('  Network Listener - HallCarDictionary: ',
                              config.HallCarDictionary)
                        time.sleep(.2)
                        msg = "MasterIpOffer"
                        config.send(msg, ip, 5006)
                        print("   Network Listener - Discover reply sent to: ",
                              ip)

            elif msg == 'RequestStopInformation':
                # Enter code here to send floor list to car.
                pass
Пример #14
0
#!/usr/bin/python3
import requests, time
print("time:", time.strftime("%Y%m%d %H%M%S"))
from decimal import Decimal
pricedata = {
    i["symbol"]: Decimal(i["price"])
    for i in requests.get(
        "https://api.binance.com/api/v3/ticker/price").json()
}
from config import WATCHER_UP, WATCHER_DOWN, send

for flag, data in {1: WATCHER_UP, -1: WATCHER_DOWN}.items():
    for coin, price, note in data:
        nowprice = pricedata[coin.upper() + "USDT"]
        diff = flag * (price - nowprice) / nowprice
        print(coin,
              str(nowprice).rstrip("0"),
              price,
              "%.2f%%" % (diff * 100),
              note,
              sep="\t")
        if diff < 0.1:
            send(
                coin + " " + note + " 爆仓预警",
                str(nowprice).rstrip("0") + "->" + str(price) + " " +
                "%.2f%%" % (diff * 100))
Пример #15
0
def restartAllWallets(
    hard=False,
    masternode=s['masternodes'][0]
):  #hard restart = erase data and start blockchain from beginning
    stopAllWalletDaemons()
    if hard:
        for server in s['servers']:
            removeBlockchainData(server)
    startStakingWallet(s['main'])
    print('Wait 10s for a number of PoW blocks generated\n')
    sleep(10)

    #start control wallet that controls the first masternode, this assume the machine running
    #this script is running control wallet
    mn1ip = masternode['address']
    if hard:
        #1. Stop control wallet
        p = Popen('dapscoin-cli ' + s['serveroption'] + " stop",
                  shell=True,
                  stdout=PIPE,
                  stderr=STDOUT)
        for line in p.stdout.readlines():
            print line,
        sleep(2)
        #2. Start daemon
        Popen('dapscoind ' + s['serveroption'] + " -daemon",
              shell=True,
              stdout=PIPE,
              stderr=STDOUT)
        sleep(2)

        #3. generate masternodeprivatekey
        p = Popen('dapscoin-cli ' + s['serveroption'] + " masternode genkey",
                  shell=True,
                  stdout=PIPE,
                  stderr=STDOUT)
        lines = p.stdout.readlines()
        mnprivateKey = lines[0]
        mnalias = "masternode1"

        #4. generate account
        p = Popen('dapscoin-cli ' + s['serveroption'] + " getaccountaddress " +
                  mnalias,
                  shell=True,
                  stdout=PIPE,
                  stderr=STDOUT)
        lines = p.stdout.readlines()
        accountAddress = lines[0]

        #5. send 10 000 daps to accountaddress
        txhash = transferFromMainWallet(accountAddress)
        if txhash:
            #check whether the transaction is confirmed
            confirmed = False
            while not confirmed:
                print('Checking tx masternode send confirmation\n')
                p = Popen('dapscoin-cli ' + s['serveroption'] +
                          " masternode outputs",
                          shell=True,
                          stdout=PIPE,
                          stderr=STDOUT)
                lines = p.stdout.readlines()
                if txhash in str(lines):
                    confirmed = True
        else:
            print('cannot send daps to masternode')
            return 0

        #6. create masternode.conf file
        mn1port = '53572'
        mnconfPath = '~/.dapscoin/masternode.conf'
        if s['serveroption'] == '-testnet':
            mn1port = '53575'
            mnconfPath = '~/.dapscoin/testnet4/masternode.conf'
        mnconfContent = mnalias + ' ' + mn1ip + ':' + mn1port + ' ' + mnprivateKey + ' ' + txhash + ' 1'
        Popen('echo "' + mnconfContent + '" >' + mnconfPath,
              shell=True,
              stdout=PIPE,
              stderr=STDOUT)

        #7. Start masternode daemon
        startStakingWallet(masternode, hard)
        stopAWallet(masternode)
        nodes = ''
        for server in s['servers']:
            nodes += '\naddnode=' + server['address']
        dapsConfData = open('boot/config/dapscoin.conf', 'r').read() + nodes
        dapsConfData = dapsConfData + '\n' + 'masternode=1\n' + 'externalip=' + mn1ip + '\nmasternodeprivkey=' + mnprivateKey
        mn1Connect = ssh(masternode)
        if mn1Connect:
            send(mn1Connect,
                 'echo "' + dapsConfData + '">~/dapscoin/dapscoin.conf')
            send(mn1Connect,
                 'dapscoind ' + s['serveroption'] + ' -daemon')  #Start daemon
            disconnect(mn1Connect)

        #8. Start masternode from control wallet
        p = Popen('dapscoin-cli ' + s['serveroption'] +
                  ' startmasternode alias false ' + mnalias,
                  shell=True,
                  stdout=PIPE,
                  stderr=STDOUT)
        lines = p.stdout.readlines()
        if 'Successfully started 1' in str(lines):
            print('Sucessfully start control wallet masternode\n')
        else:
            print('Failed to start control wallet masternode\n')
            return 0

        #9. Start masternode in VPS
        res = send(mn1Connect, 'dapscoin-cli ' + s['serveroption'] +
                   ' startmasternode local false')  #Start daemon
        print(res + '\n')
Пример #16
0
def removeBlockchainData(server):
    connect = ssh(server)
    if connect:
        send(connect, 'rm -r * ~/.dapscoin/')
        disconnect(connect)