def sync_cache(): #create a rotating logger logger = create_rotating_file(file_name, 10 * 1024 * 1024, 1) old_block = namecoind.blocks() - 10 new_block = namecoind.blocks() message = "starting sync from block: %s" % old_block log_to_file(logger, message) while (1): while (old_block == new_block): sleep(30) new_block = namecoind.blocks() message = 'current block: %s' % new_block log_to_file(logger, message) check_blocks = new_block - old_block message = 'checking last %s block(s)' % check_blocks log_to_file(logger, message) warmup_cache('u/', check_blocks) warmup_cache('i/', check_blocks) old_block = new_block
def sync_cache(): #create a rotating logger logger = create_rotating_file(file_name, 10 * 1024 * 1024, 1) old_block = namecoind.blocks() - 10 new_block = namecoind.blocks() message = "starting sync from block: %s" %old_block log_to_file(logger, message) while(1): while(old_block == new_block): sleep(30) new_block = namecoind.blocks() message = 'current block: %s' %new_block log_to_file(logger, message) check_blocks = new_block - old_block message = 'checking last %s block(s)' %check_blocks log_to_file(logger, message) warmup_cache('u/',check_blocks) warmup_cache('i/',check_blocks) old_block = new_block
def test_connectivity(self): """ Check if can connect to namecoind """ blocks = namecoind.blocks() self.assertIsNotNone(blocks, msg='Namecoind is not responding')
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
def test_connectivity(self): """ Check if can connect to namecoind """ blocks = namecoind.blocks() self.assertIsNotNone(blocks, msg="Namecoind is not responding")
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