def update_transfer_state(): counter = 0 for entry in registrar_state.find(): if 'needsTransfer' in entry and entry['needsTransfer'] is True: profile = entry['profile'] #print entry['username'] #print entry['server'] #print '-' * 5 #continue namecoind = NamecoindClient() try: resp = namecoind.name_show('u/' + entry['username']) except Exception as e: print e continue current_nmc_address = resp['address'] if current_nmc_address == entry['nmc_address']: print entry['username'] entry['needsTransfer'] = False registrar_state.save(entry) counter += 1 print counter
def build_nmc_state(): namecoind = NamecoindClient('named8') resp = namecoind.name_filter('u/') counter = 0 for entry in resp: counter += 1 print counter new_entry = {} new_entry['username'] = entry['name'].lstrip('u/') profile = entry['value'] new_entry['profile'] = profile if 'message' in profile: new_entry['reservedByOnename'] = True else: new_entry['reservedByOnename'] = False nmc_state.insert(new_entry) print counter
def prepare_diff_2(btc_state_file, btc_state_diff_file): fin = open(btc_state_file, 'r') first_import = json.loads(fin.read()) fin.close() fin = open(btc_state_diff_file, 'r') diff_1 = json.loads(fin.read()) fin.close() btc_namespace = first_import + diff_1 counter = 0 user_found = False for user in users.find(): username = user['username'] user_found = False if len(username) == 34 or len(username) == 33: continue if 'stormtrooper' in username or 'clone' in username: continue for check_user in btc_namespace: if username == check_user['username']: user_found = True break if user_found is True: continue namecoind = NamecoindClient() try: resp = namecoind.name_show('u/' + username) except Exception as e: print username print e continue if 'code' in resp: pass #print "not registered: %s" % username #print username #insert_btc_diff(username, user['profile'], str(user['namecoin_address'])) #counter += 1 else: print username print counter
def check_transfer_state(): from registrar.config import SERVER_FLEET, IGNORE_USERNAMES servers = SERVER_FLEET counter = 0 for entry in registrar_state.find(timeout=False): counter += 1 #print counter nmc_entry = nmc_state.find_one({"username": entry['username']}) if nmc_entry is None: continue if 'needsTransfer' in entry and entry['needsTransfer'] is True: continue if nmc_entry['nmc_address'] != entry['nmc_address']: server_counter = 0 while(server_counter != len(servers)): server = servers[server_counter] #print server namecoind = NamecoindClient(server) try: resp = namecoind.validateaddress(nmc_entry['nmc_address']) except Exception as e: print e print server server_counter += 1 sleep(3) continue if 'ismine' in resp and resp['ismine'] is True: entry['needsTransfer'] = True entry['server'] = server #print entry registrar_state.save(entry) break server_counter += 1 if server_counter == 8: print entry['username']
def transfer_key(username, transfer_address, live=False, server=None): """ transfer single key """ key = 'u/' + username if server == None: namecoind = get_namecoind(key) else: namecoind = NamecoindClient(server) if (live): try: print namecoind.name_transfer(key, transfer_address) except Exception as e: print e print username else: print "Will transfer %s to %s" % (key, transfer_address)
def calculate_diff(): ban_users = [] counter = 0 for check_user in old_users.find(): username = check_user["username"] check_new_user = users.find_one({"username": username}) check_btc = btc_state.find_one({"username": username}) check_btc_diff = btc_state_diff.find_one({"username": username}) if check_btc is None and check_btc_diff is None and check_new_user is None: if len(username) == 34 or len(username) == 33: continue if 'stormtrooper' in username or 'clone' in username: continue if username in ban_users: continue namecoind = NamecoindClient() try: resp = namecoind.name_show('u/' + username) except Exception as e: print username print e continue if 'code' in resp: print "not registered: %s" % username continue try: resp_value = resp['value'] if 'message' in resp_value: print "reserved: %s" % username continue except Exception as e: print e try: current_nmc_address = resp['address'] except Exception as e: print resp continue if current_nmc_address == check_user['namecoin_address']: print "transferred new user: %s" % username insert_btc_diff(username, check_user['profile'], str(check_user['namecoin_address'])) else: namecoind = get_namecoind('u/' + username) try: resp = namecoind.validateaddress(current_nmc_address) except Exception as e: print e continue if 'ismine' in resp and resp['ismine'] is True: profile = check_user['profile'] if type(profile) is not dict: profile = json.loads(profile) insert_btc_diff(username, profile, str(check_user['namecoin_address'])) else: print "problem: %s" % username print check_user['namecoin_address'] print '-' * 5 counter += 1 print counter
from registrar.config import MONGODB_URI, OLD_DB, AWSDB_URI, MONGOLAB_URI from registrar.config import FRONTEND_SECRET from tools.misc import process_manually from tools.sweep_btc import sweep_btc from tools.misc import import_update from tools.crypto_tools import aes_encrypt, aes_decrypt, get_addresses_from_privkey from tools.namespace_state import get_hash from tools.namespace_diff import insert_state_diff as insert_btc_diff from registrar.config import SERVER_FLEET from pybitcoin.rpc.namecoind_cluster import pending_transactions namecoind = NamecoindClient(NAMECOIND_SERVER, NAMECOIND_PORT, NAMECOIND_USER, NAMECOIND_PASSWD, NAMECOIND_WALLET_PASSPHRASE, NAMECOIND_USE_HTTPS) SECRET_KEY = os.environ['SECRET_KEY'] # ----------------------------------- remote_db = MongoClient(MONGODB_URI).get_default_database() users = remote_db.user registrations = remote_db.user_registration updates = remote_db.profile_update transfer = remote_db.name_transfer old_db = MongoClient(OLD_DB).get_default_database() old_users = old_db.user aws_db = MongoClient(AWSDB_URI)['blockdata']
# -*- coding: utf-8 -*- import os import sys # Hack around absolute paths current_dir = os.path.abspath(os.path.dirname(__file__)) parent_dir = os.path.abspath(current_dir + "/../") sys.path.insert(0, parent_dir) import unittest from pybitcoin.rpc import BitcoindClient, NamecoindClient bitcoind = BitcoindClient() namecoind = NamecoindClient() class NamecoindTestCase(unittest.TestCase): def test_connectivity(self): """ Check if can connect to namecoind """ blocks = namecoind.blocks() self.assertIsNotNone(blocks, msg='Namecoind is not responding') def test_full_profile(self): """ Check if can connect to namecoind """ key = 'u/muneeb'