Exemplo n.º 1
0
def check_pending_tx():

    counter_total = 0

    for server in SERVER_FLEET:
        print server
        try:
            count = int(pending_transactions(server))
            print count
            counter_total += count
        except Exception as e:
            print e

    return counter_total
Exemplo n.º 2
0
def load_balance():

    global current_server

    print "current server: %s" %load_servers[current_server]

    while(1):
        if pending_transactions(load_servers[current_server]) > MAX_PENDING_TX:

            if current_server == len(load_servers) - 1:
                current_server = 0
            else:
                current_server += 1

            print "load balancing: switching to %s" %load_servers[current_server]
            sleep(30)

        else:
            break
Exemplo n.º 3
0
def load_balance():

    global current_server

    print "current server: %s" % load_servers[current_server]

    while (1):
        if pending_transactions(load_servers[current_server]) > MAX_PENDING_TX:

            if current_server == len(load_servers) - 1:
                current_server = 0
            else:
                current_server += 1

            print "load balancing: switching to %s" % load_servers[
                current_server]
            sleep(30)

        else:
            break
Exemplo n.º 4
0
def do_name_firstupdate():

    log.debug("Checking for new activations")
    log.debug('-' * 5)

    ignore_servers = []
    counter = 0
    counter_pending = 0

    from coinrpc import namecoind
    blocks = namecoind.blocks()

    for entry in register_queue.find():

        counter += 1

        if counter % 10 == 0:
            for server in ignore_servers:
                if pending_transactions(server) > MAX_PENDING_TX:
                    pass
                else:
                    ignore_servers.remove(server)

        from coinrpc import namecoind
        if not namecoind.check_registration(entry['key']):

            counter_pending += 1

            key = entry['key']
            server = entry['server']
            namecoind = NamecoindServer(server, NAMECOIND_PORT, NAMECOIND_USER,
                                        NAMECOIND_PASSWD, NAMECOIND_USE_HTTPS,
                                        NAMECOIND_WALLET_PASSPHRASE)

            if 'tx_sent' in entry and entry['tx_sent'] is True:
                log.debug('Already sent name_firstupdate: %s' % entry['key'])
                continue

            if 'wait_till_block' not in entry:

                reply = namecoind.gettransaction(entry['txid'])

                if 'code' in reply:
                    register_queue.remove(entry)
                    continue

                if reply['confirmations'] > 1:
                    log.debug('Got confirmations on name_new: %s' % entry['key'])
                    entry['wait_till_block'] = namecoind.blocks() + (12 - reply['confirmations'])
                    register_queue.save(entry)
                else:
                    log.debug('No confirmations on name_new: %s' % entry['key'])
                    continue

            if entry['wait_till_block'] <= blocks:

                if server in ignore_servers:
                    continue

                if pending_transactions(server) > MAX_PENDING_TX:
                        log.debug("Pending tx on server, try again")
                        ignore_servers.append(server)
                        continue

                update_value = None
                if 'username' in entry:
                    update_value = get_string(refresh_value(entry))

                if update_value is None:
                    update_value = get_string(entry['value'])

                log.debug("Activating entry: '%s' to point to '%s'" % (key, update_value))

                output = namecoind.firstupdate(key,entry['rand'],update_value,entry['txid'])

                log.debug(output)

                if 'message' in output and output['message'] == "this name is already active":
                    register_queue.remove(entry)
                elif 'message' in output and output['message'] == "previous transaction is not in the wallet":
                    register_queue.remove(entry)
                elif 'code' in output:
                    log.debug("Not activated. Try again.")
                else:
                    entry['tx_sent'] = True
                    register_queue.save(entry)

                log.debug('-' * 5)

            else:
                log.debug("wait: %s blocks for: %s" % ((entry['wait_till_block'] - blocks), entry['key']))

        else:
            log.debug("key %s already active" % (entry['key']))
            register_queue.remove(entry)

    print "Pending activations: %s" % counter_pending
    current_block = namecoind.blocks()
    while(1):
        new_block = namecoind.blocks()

        if current_block == new_block:
            log.debug('No new block. Sleeping ... ')
            sleep(15)
        else:
            break
Exemplo n.º 5
0
def do_name_firstupdate():

    log.debug("Checking for new activations")
    log.debug('-' * 5)

    ignore_servers = []
    counter = 0
    counter_pending = 0

    from coinrpc import namecoind
    blocks = namecoind.blocks()

    for entry in register_queue.find():

        counter += 1

        if counter % 10 == 0:
            for server in ignore_servers:
                if pending_transactions(server) > MAX_PENDING_TX:
                    pass
                else:
                    ignore_servers.remove(server)

        from coinrpc import namecoind
        if not namecoind.check_registration(entry['key']):

            counter_pending += 1

            key = entry['key']
            server = entry['server']
            namecoind = NamecoindServer(server, NAMECOIND_PORT, NAMECOIND_USER,
                                        NAMECOIND_PASSWD, NAMECOIND_USE_HTTPS,
                                        NAMECOIND_WALLET_PASSPHRASE)

            if 'tx_sent' in entry and entry['tx_sent'] is True:
                log.debug('Already sent name_firstupdate: %s' % entry['key'])
                continue

            if 'wait_till_block' not in entry:

                reply = namecoind.gettransaction(entry['txid'])

                if 'code' in reply:
                    register_queue.remove(entry)
                    continue

                if reply['confirmations'] > 1:
                    log.debug('Got confirmations on name_new: %s' %
                              entry['key'])
                    entry['wait_till_block'] = namecoind.blocks() + (
                        12 - reply['confirmations'])
                    register_queue.save(entry)
                else:
                    log.debug('No confirmations on name_new: %s' %
                              entry['key'])
                    continue

            if entry['wait_till_block'] <= blocks:

                if server in ignore_servers:
                    continue

                if pending_transactions(server) > MAX_PENDING_TX:
                    log.debug("Pending tx on server, try again")
                    ignore_servers.append(server)
                    continue

                update_value = None
                if 'username' in entry:
                    update_value = get_string(refresh_value(entry))

                if update_value is None:
                    update_value = get_string(entry['value'])

                log.debug("Activating entry: '%s' to point to '%s'" %
                          (key, update_value))

                output = namecoind.firstupdate(key, entry['rand'],
                                               update_value, entry['txid'])

                log.debug(output)

                if 'message' in output and output[
                        'message'] == "this name is already active":
                    register_queue.remove(entry)
                elif 'message' in output and output[
                        'message'] == "previous transaction is not in the wallet":
                    register_queue.remove(entry)
                elif 'code' in output:
                    log.debug("Not activated. Try again.")
                else:
                    entry['tx_sent'] = True
                    register_queue.save(entry)

                log.debug('-' * 5)

            else:
                log.debug("wait: %s blocks for: %s" %
                          ((entry['wait_till_block'] - blocks), entry['key']))

        else:
            log.debug("key %s already active" % (entry['key']))
            register_queue.remove(entry)

    print "Pending activations: %s" % counter_pending
    current_block = namecoind.blocks()
    while (1):
        new_block = namecoind.blocks()

        if current_block == new_block:
            log.debug('No new block. Sleeping ... ')
            sleep(15)
        else:
            break