mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-05-27 08:31:53 +08:00
bulk register expired names with throttling (pause when x transactions are pending confirmations)
This commit is contained in:
93
blockstack_cli/blockstack_registrar/tools/re_register.py
Executable file
93
blockstack_cli/blockstack_registrar/tools/re_register.py
Executable file
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#-----------------------
|
||||
# Copyright 2014 Halfmoon Labs, Inc.
|
||||
# All Rights Reserved
|
||||
#-----------------------
|
||||
|
||||
import json
|
||||
|
||||
from blockdata.register import process_user
|
||||
|
||||
from time import sleep
|
||||
|
||||
from coinrpc import namecoind
|
||||
|
||||
from commontools import get_json
|
||||
|
||||
#-----------------------------------
|
||||
from pymongo import MongoClient
|
||||
from config import MONGODB_URI, OLD_DB
|
||||
|
||||
remote_db = MongoClient(MONGODB_URI).get_default_database()
|
||||
users = remote_db.user
|
||||
|
||||
old_db = MongoClient(OLD_DB).get_default_database()
|
||||
old_users = old_db.user
|
||||
|
||||
MAX_PENDING_TX = 50
|
||||
|
||||
#-----------------------------------
|
||||
def pending_transactions():
|
||||
|
||||
reply = namecoind.namecoind.listtransactions("",10000)
|
||||
|
||||
counter = 0
|
||||
|
||||
for i in reply:
|
||||
if i['confirmations'] == 0:
|
||||
counter += 1
|
||||
|
||||
|
||||
if counter == MAX_PENDING_TX:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
#-----------------------------------
|
||||
if __name__ == '__main__':
|
||||
|
||||
from blockdata.renew_names import get_expiring_names, get_expired_names
|
||||
expired_users = get_expired_names('u/')
|
||||
|
||||
#ignore_users = ['frm','rfd','meng','bjorn']
|
||||
ignore_users = []
|
||||
|
||||
counter = 0
|
||||
|
||||
tx_sent = MAX_PENDING_TX
|
||||
|
||||
for i in expired_users:
|
||||
|
||||
if tx_sent >= MAX_PENDING_TX:
|
||||
tx_sent = 0
|
||||
while pending_transactions():
|
||||
print "pending transactions, sleeping ..."
|
||||
sleep(60 * 5)
|
||||
|
||||
|
||||
username = i['name'].lstrip('u/')
|
||||
|
||||
if username in ignore_users:
|
||||
continue
|
||||
|
||||
new_user = users.find_one({'username':username})
|
||||
if new_user is not None:
|
||||
print username + " in new DB"
|
||||
process_user(username,profile)
|
||||
tx_sent += 1
|
||||
print '-' * 5
|
||||
continue
|
||||
|
||||
old_user = old_users.find_one({'username':username})
|
||||
if old_user is not None:
|
||||
print username + " in old DB"
|
||||
profile = get_json(old_user['profile'])
|
||||
if 'twitter' in profile:
|
||||
process_user(username,profile)
|
||||
tx_sent += 1
|
||||
print '-' * 5
|
||||
continue
|
||||
|
||||
print username + " not our user"
|
||||
print '-' * 5
|
||||
Reference in New Issue
Block a user