mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-05-07 00:12:30 +08:00
70 lines
1.5 KiB
Python
Executable File
70 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
#-----------------------
|
|
# Copyright 2014 Halfmoon Labs, Inc.
|
|
# All Rights Reserved
|
|
#-----------------------
|
|
|
|
import os
|
|
import json
|
|
|
|
from coinrpc.namecoin.namecoind_server import NamecoindServer
|
|
|
|
from config import NAMECOIND_PORT, NAMECOIND_USER, NAMECOIND_PASSWD
|
|
from config_local import MAIN_SERVER, LOAD_SERVERS
|
|
|
|
from multiprocessing.pool import ThreadPool
|
|
|
|
#-----------------------------------
|
|
def check_address(address):
|
|
|
|
reply = {}
|
|
reply["server"] = None
|
|
reply["ismine"] = False
|
|
reply['registered'] = True
|
|
|
|
#--------------------------
|
|
def check_address_inner(server):
|
|
|
|
try:
|
|
namecoind = NamecoindServer(server, NAMECOIND_PORT, NAMECOIND_USER, NAMECOIND_PASSWD)
|
|
|
|
info = json.loads(namecoind.validate_address(address))
|
|
except:
|
|
return
|
|
|
|
if info['ismine'] is True:
|
|
reply['server'] = server
|
|
reply['ismine'] = True
|
|
|
|
#first check the main server
|
|
check_address_inner(MAIN_SERVER)
|
|
|
|
if reply['ismine'] is True:
|
|
return reply
|
|
|
|
#if not main server, check others
|
|
pool = ThreadPool(len(LOAD_SERVERS))
|
|
|
|
pool.map(check_address_inner, LOAD_SERVERS)
|
|
pool.close()
|
|
pool.join()
|
|
|
|
return reply
|
|
|
|
#-----------------------------------
|
|
def get_server(key):
|
|
|
|
namecoind = NamecoindServer(MAIN_SERVER, NAMECOIND_PORT, NAMECOIND_USER, NAMECOIND_PASSWD)
|
|
|
|
info = namecoind.name_show(key)
|
|
|
|
if 'namecoin_address' in info:
|
|
return check_address(info['namecoin_address'])
|
|
|
|
response = {}
|
|
response["registered"] = False
|
|
response["server"] = None
|
|
response["ismine"] = False
|
|
return resposne
|