def process_user(username, profile, server=NAMECOIND_SERVER, new_address=None): master_key = 'u/' + username if namecoind.check_registration(master_key): keys, values = slice_profile_update(username, profile) else: keys, values = slice_profile(username, profile) index = 0 key1 = keys[index] value1 = values[index] if namecoind.check_registration(key1): # if name is registered log.debug("name update: %s", key1) log.debug("size: %s", utf8len(json.dumps(value1))) update_name(key1, value1, new_address) else: # if not registered log.debug("name new: %s", key1) log.debug("size: %s", utf8len(json.dumps(value1))) register_name(key1, value1, server, username) process_additional_keys(keys, values, server, username, new_address)
def main_loop(key, name=None): key, value = format_key_value(key, name) reply = queue.find_one({'key': key}) if namecoind.check_registration(key): profile = namecoind.name_show(key) try: profile = profile['value'] except: pass if 'status' in profile and profile['status'] == 'reserved': print "already reserved: " + key #update_name(key,value) else: print "registered but not reserved: " + key #update_name(key,value) elif reply is not None: # currently being processed pass else: #not in DB and not registered print "not registered: " + key register_name(key, value) print '-' * 5
def main_loop(key, name=None): key, value = format_key_value(key, name) reply = queue.find_one({"key": key}) if namecoind.check_registration(key): profile = namecoind.name_show(key) try: profile = profile["value"] except: pass if "status" in profile and profile["status"] == "reserved": print "already reserved: " + key # update_name(key,value) else: print "registered but not reserved: " + key # update_name(key,value) elif reply is not None: # currently being processed pass else: # not in DB and not registered print "not registered: " + key register_name(key, value) print "-" * 5
def process_additional_keys(keys, values, server, username, new_address): # register/update remaining keys size = len(keys) index = 1 while index < size: next_key = keys[index] next_value = values[index] log.debug(utf8len(json.dumps(next_value))) if namecoind.check_registration(next_key): log.debug("name update: " + next_key) update_name(next_key, next_value, new_address) else: log.debug("name new: " + next_key) register_name(next_key, next_value, server, username) index += 1
def process_profile_updates(): print "Profile update pending: " for user in users.find(): if 'name_transferred' in user and user['name_transferred'] is True: #print "name already transferred: " + user['username'] continue if 'profile_update_pending' in user and user['profile_update_pending']: if not namecoind.check_registration('u/' + user['username']): print "Not registered yet: " + user['username'] continue else: print "Updating user: " + user['username'] print user['backend_server'] update_profile_from_private_key(user['username']) print '-' * 5
def slice_profile(username, profile): '''if a next key is already registered, returns next one ''' keys = [] values = [] key = 'u/' + username.lower() keys.append(key) split, remaining = _splitter(profile, username) values.append(split) key_counter = 000000 counter = 0 while(remaining is not None): key_counter += 1 key = _get_key(key_counter, username) while(1): if namecoind.check_registration(key): key_counter += 1 key = _get_key(key_counter, username) else: break split, remaining = _splitter(remaining, username) keys.append(key) values.append(split) values[counter]['next'] = key counter += 1 return keys, values
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 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