Esempio n. 1
0
def setup(on_startup):
    '''Setup mining service internal environment.
    You should not need to change this. If you
    want to use another Worker manager or Share manager,
    you should set proper reference to Interfaces class
    *before* you call setup() in the launcher script.'''

    import lib.settings as settings

    # Get logging online as soon as possible
    import lib.logger
    log = lib.logger.get_logger('mining')

    from interfaces import Interfaces

    from lib.block_updater import BlockUpdater
    from lib.template_registry import TemplateRegistry
    from lib.bitcoin_rpc_manager import BitcoinRPCManager
    from lib.block_template import BlockTemplate
    from lib.coinbaser import SimpleCoinbaser

    bitcoin_rpc = BitcoinRPCManager()

    # Check litecoind
    #         Check we can connect (sleep)
    # Check the results:
    #         - getblocktemplate is avalible        (Die if not)
    #         - we are not still downloading the blockchain        (Sleep)
    log.info("Connecting to litecoind...")
    while True:
        try:
            result = (yield bitcoin_rpc.getblocktemplate())
            if isinstance(result, dict):
                # litecoind implements version 1 of getblocktemplate
                if result['version'] >= 1:
                    break

        except ConnectionRefusedError, e:
            log.error(
                "Connection refused while trying to connect to litecoin (are your LITECOIN_TRUSTED_* settings correct?)"
            )
            reactor.stop()

        except Exception, e:
            if isinstance(e[2], str):
                if isinstance(json.loads(e[2])['error']['message'], str):
                    error = json.loads(e[2])['error']['message']
                    if error == "Method not found":
                        log.error(
                            "Litecoind does not support getblocktemplate!!! (time to upgrade.)"
                        )
                        reactor.stop()
                    elif error == "Litecoind is downloading blocks...":
                        log.error(
                            "Litecoind downloading blockchain... will check back in 30 sec"
                        )
                        time.sleep(29)
                    else:
                        log.error("Litecoind Error: %s", error)
Esempio n. 2
0
def setup(on_startup):
    '''Setup mining service internal environment.
    You should not need to change this. If you
    want to use another Worker manager or Share manager,
    you should set proper reference to Interfaces class
    *before* you call setup() in the launcher script.'''
    
    import lib.settings as settings
        
    # Get logging online as soon as possible
    import lib.logger
    log = lib.logger.get_logger('mining')

    from interfaces import Interfaces
    
    from lib.block_updater import BlockUpdater
    from lib.template_registry import TemplateRegistry
    from lib.bitcoin_rpc_manager import BitcoinRPCManager
    from lib.block_template import BlockTemplate
    from lib.coinbaser import SimpleCoinbaser
    
    bitcoin_rpc = BitcoinRPCManager()
    
    # Check litecoind
    #         Check we can connect (sleep)
    # Check the results:
    #         - getblocktemplate is avalible        (Die if not)
    #         - we are not still downloading the blockchain        (Sleep)
    log.info("Connecting to litecoind...")
    while True:
        try:
            result = (yield bitcoin_rpc.getblocktemplate())
            if isinstance(result, dict):
                # litecoind implements version 1 of getblocktemplate
                if result['version'] >= 1:
                    break
                else:
                    log.error("Block Version mismatch: %s" % result['version'])


        except ConnectionRefusedError, e:
            log.error("Connection refused while trying to connect to litecoin (are your COIND_* settings correct?)")
            reactor.stop()
            break

        except Exception, e:
            if isinstance(e[2], str):
                if isinstance(json.loads(e[2])['error']['message'], str):
                    error = json.loads(e[2])['error']['message']
                    if error == "Method not found":
                        log.error("Litecoind does not support getblocktemplate!!! (time to upgrade.)")
                        reactor.stop()
                    elif error == "Litecoind is downloading blocks...":
                        log.error("Litecoind downloading blockchain... will check back in 30 sec")
                        time.sleep(29)
                    else:
                        log.error("Litecoind Error: %s", error)
Esempio n. 3
0
def setup(on_startup):
    '''Setup mining service internal environment.
    You should not need to change this. If you
    want to use another Worker manager or Share manager,
    you should set proper reference to Interfaces class
    *before* you call setup() in the launcher script.'''

    from stratum import settings

    # Get logging online as soon as possible
    import stratum.logger
    log = stratum.logger.get_logger('mining')

    from interfaces import Interfaces
    # Let's wait until share manager and worker manager boot up
    (yield Interfaces.share_manager.on_load)
    (yield Interfaces.worker_manager.on_load)

    from lib.block_updater import BlockUpdater
    from lib.template_registry import TemplateRegistry
    from lib.bitcoin_rpc_manager import BitcoinRPCManager
    from lib.block_template import BlockTemplate
    from lib.coinbaser import SimpleCoinbaser

    bitcoin_rpc = BitcoinRPCManager()

    # Check bitcoind
    # 	Check we can connect (sleep)
    # Check the results:
    #	- getblocktemplate is avalible	(Die if not)
    #	- we are not still downloading the blockchain	(Sleep)
    log.info("Connecting to bitcoind...")
    while True:
        try:
            result = (yield bitcoin_rpc.getblocktemplate())
            if isinstance(result, dict):
                if result['version'] == 2:
                    break
        except Exception, e:
            if isinstance(e[2], str):
                if isinstance(json.loads(e[2])['error']['message'], str):
                    error = json.loads(e[2])['error']['message']
                    if error == "Method not found":
                        log.error(
                            "Bitcoind does not support getblocktemplate!!! (time to upgrade.)"
                        )
                        reactor.stop()
                    elif error == "Bitcoin is downloading blocks...":
                        log.error(
                            "Bitcoind downloading blockchain... will check back in 30 sec"
                        )
                        time.sleep(29)
                    else:
                        log.error("Bitcoind Error: %s", error)
        time.sleep(1)  # If we didn't get a result or the connect failed
Esempio n. 4
0
def setup(on_startup):
    '''Setup mining service internal environment.
    You should not need to change this. If you
    want to use another Worker manager or Share manager,
    you should set proper reference to Interfaces class
    *before* you call setup() in the launcher script.'''

    from stratum import settings

    # Get logging online as soon as possible
    import stratum.logger
    log = stratum.logger.get_logger('mining')

    from interfaces import Interfaces    
    # Let's wait until share manager and worker manager boot up
    (yield Interfaces.share_manager.on_load)
    (yield Interfaces.worker_manager.on_load)
    
    from lib.block_updater import BlockUpdater
    from lib.template_registry import TemplateRegistry
    from lib.bitcoin_rpc_manager import BitcoinRPCManager
    from lib.block_template import BlockTemplate
    from lib.coinbaser import SimpleCoinbaser
    
    bitcoin_rpc = BitcoinRPCManager()
    
    # Check bitcoind
    # 	Check we can connect (sleep)
    # Check the results:
    #	- getblocktemplate is avalible	(Die if not)
    #	- we are not still downloading the blockchain	(Sleep)
    log.info("Connecting to bitcoind...")
    while True:
	try:
	    result = (yield bitcoin_rpc.getblocktemplate())
	    if isinstance(result, dict):
		if result['version'] == 1:
		    break
	except Exception, e:
	    if isinstance(e[2], str):
		if isinstance(json.loads(e[2])['error']['message'],str):
		    error = json.loads(e[2])['error']['message']
		    if error == "Method not found":
			log.error("Bitcoind does not support getblocktemplate!!! (time to upgrade.)")
			reactor.stop()
		    elif error == "Bitcoin is downloading blocks...":
			log.error("Bitcoind downloading blockchain... will check back in 30 sec")
			time.sleep(29)
		    else:
			log.error("Bitcoind Error: %s", error)
	time.sleep(1)		# If we didn't get a result or the connect failed
def setup(on_startup):
    '''Setup mining service internal environment.
    You should not need to change this. If you
    want to use another Worker manager or Share manager,
    you should set proper reference to Interfaces class
    *before* you call setup() in the launcher script.'''

    import lib.settings as settings

    # Get logging online as soon as possible
    import lib.logger
    log = lib.logger.get_logger('mining')
    if settings.CONFIG_VERSION == None:
        settings.CONFIG_VERSION = 0
    else:
        pass
    from interfaces import Interfaces

    from lib.block_updater import BlockUpdater
    from lib.template_registry import TemplateRegistry
    from lib.bitcoin_rpc_manager import BitcoinRPCManager
    from lib.block_template import BlockTemplate
    from lib.coinbaser import SimpleCoinbaser

    bitcoin_rpc = BitcoinRPCManager()
    # Check litecoind
    #         Check we can connect (sleep)
    # Check the results:
    #         - getblocktemplate is avalible        (Die if not)
    #         - we are not still downloading the blockchain        (Sleep)
    log.info("Connecting to litecoind...")
    while True:
        try:
            result = (yield bitcoin_rpc.check_submitblock())
            if result == True:
                log.info("Found submitblock")
            elif result == False:
                log.info("Did not find submitblock")
            else:
                log.info("unknown submitblock result")
        except ConnectionRefusedError, e:
            log.error(
                "Connection refused while trying to connect to the coind (are your COIND_* settings correct?)"
            )
            reactor.stop()
            break

        except Exception, e:
            log.debug(str(e))
Esempio n. 6
0
def setup(on_startup):
    '''Setup mining service internal environment.
    You should not need to change this. If you
    want to use another Worker manager or Share manager,
    you should set proper reference to Interfaces class
    *before* you call setup() in the launcher script.'''
    
    import lib.settings as settings
        
    # Get logging online as soon as possible
    import lib.logger
    log = lib.logger.get_logger('mining')

    from interfaces import Interfaces
    
    from lib.block_updater import BlockUpdater
    from lib.template_registry import TemplateRegistry
    from lib.bitcoin_rpc_manager import BitcoinRPCManager
    from lib.block_template import BlockTemplate
    from lib.coinbaser import SimpleCoinbaser
    
    bitcoin_rpc = BitcoinRPCManager()
    mm_rpc = BitcoinRPCManager(settings.MM_HOST,
                               settings.MM_PORT,
                               settings.MM_USER,
                               settings.MM_PASSWORD)
    
    # Check litecoind
    #         Check we can connect (sleep)
    # Check the results:
    #         - getblocktemplate is avalible        (Die if not)
    #         - we are not still downloading the blockchain        (Sleep)
    log.info("Connecting to master coind...")
    while True:
        try:
            result = (yield bitcoin_rpc.check_submitblock())
            if result == True:
                log.info("Found submitblock")
            elif result == False:
                log.info("Did not find submitblock")
            else:
                log.info("unknown submitblock result")
        except ConnectionRefusedError, e:
            log.error("Connection refused while trying to connect to the coind (are your COIND_* settings correct?)")
            reactor.stop()
            break

        except Exception, e:
            log.debug(str(e))
Esempio n. 7
0
def setup(on_startup):
    '''Setup mining service internal environment.
    You should not need to change this. If you
    want to use another Worker manager or Share manager,
    you should set proper reference to Interfaces class
    *before* you call setup() in the launcher script.'''

    from interfaces import Interfaces

    from lib.bitcoin_rpc_manager import BitcoinRPCManager

    bitcoin_rpc = BitcoinRPCManager()

    # Check litecoind
    #         Check we can connect (sleep)
    # Check the results:
    #         - getblocktemplate is avalible        (Die if not)
    #         - we are not still downloading the blockchain        (Sleep)
    log.info("Connecting to all litecoind...")
    for (wallet, connSettings) in settings.COINDAEMON_WALLETS.items():
        wallet_connect(wallet, bitcoin_rpc)

    yield 1
    on_startup.callback(True)
    log.info("MINING SERVICE IS READY")
Esempio n. 8
0
def setup(on_startup):
    '''Setup mining service internal environment.
    You should not need to change this. If you
    want to use another Worker manager or Share manager,
    you should set proper reference to Interfaces class
    *before* you call setup() in the launcher script.'''
    
    import lib.settings as settings
        
    # Get logging online as soon as possible
    import lib.logger
    log = lib.logger.get_logger('mining')

    from interfaces import Interfaces
    
    from lib.block_updater import BlockUpdater
    from lib.aux_updater import AuxUpdater
    from lib.template_registry import TemplateRegistry
    from lib.bitcoin_rpc_manager import BitcoinRPCManager
    from lib.merged_rpc_manager import MergedRPCManager
    from lib.block_template import BlockTemplate
    from lib.coinbaser import SimpleCoinbaser
    
    bitcoin_rpc = BitcoinRPCManager()
    aux_rpc = MergedRPCManager()

    log.info("Connecting to master coin daemon...")
    while True:
        try:
            result = (yield bitcoin_rpc.getblocktemplate())
            if isinstance(result, dict):
                # litecoind implements version 1 of getblocktemplate
                if result['version'] >= 1:
                    result = (yield bitcoin_rpc.getdifficulty())
                    if isinstance(result,dict):
                        if 'proof-of-stake' in result: 
                            settings.DAEMON_REWARD = 'POS'
                            log.info("Coin detected as POS")
                            break
                    else:
                        settings.DAEMON_REWARD = 'POW'
                        log.info("Coin detected as POW")
                        break
                else:
                    log.error("Block Version mismatch: %s" % result['version'])


        except ConnectionRefusedError, e:
            log.error("Connection refused while trying to connect to the coind (are your COIN settings correct?)")
            reactor.stop()
            break

        except Exception, e:
            if isinstance(e[2], str):
                try:
                    if isinstance(json.loads(e[2])['error']['message'], str):
                        error = json.loads(e[2])['error']['message']
                    if error == "Method not found":
                        log.error("Coin does not support getblocktemplate!!! (time to upgrade.)")
                        reactor.stop()
                    elif "downloading blocks" in error:
                        log.error("Coin downloading blockchain... will check back in 30 sec")
                        time.sleep(29)
                    else:
                        log.error("Coin Error: %s", error)
                except ValueError:
                    log.error("Failed Connect(HTTP 500 or Invalid JSON), Check Username and Password!")
                    reactor.stop()
Esempio n. 9
0
def setup(on_startup):
    '''Setup mining service internal environment.
    You should not need to change this. If you
    want to use another Worker manager or Share manager,
    you should set proper reference to Interfaces class
    *before* you call setup() in the launcher script.'''

    import lib.settings as settings

    # Get logging online as soon as possible
    import lib.logger
    log = lib.logger.get_logger('mining')

    from interfaces import Interfaces

    from lib.block_updater import BlockUpdater
    from lib.aux_updater import AuxUpdater
    from lib.template_registry import TemplateRegistry
    from lib.bitcoin_rpc_manager import BitcoinRPCManager
    from lib.merged_rpc_manager import MergedRPCManager
    from lib.block_template import BlockTemplate
    from lib.coinbaser import SimpleCoinbaser

    bitcoin_rpc = BitcoinRPCManager()
    aux_rpc = MergedRPCManager()

    log.info("Connecting to master coin daemon...")
    while True:
        try:
            result = (yield bitcoin_rpc.getblocktemplate())
            if isinstance(result, dict):
                # litecoind implements version 1 of getblocktemplate
                if result['version'] >= 1:
                    result = (yield bitcoin_rpc.getdifficulty())
                    if isinstance(result, dict):
                        if 'proof-of-stake' in result:
                            settings.DAEMON_REWARD = 'POS'
                            log.info("Coin detected as POS")
                            break
                    else:
                        settings.DAEMON_REWARD = 'POW'
                        log.info("Coin detected as POW")
                        break
                else:
                    log.error("Block Version mismatch: %s" % result['version'])

        except ConnectionRefusedError, e:
            log.error(
                "Connection refused while trying to connect to the coind (are your COIN settings correct?)"
            )
            reactor.stop()
            break

        except Exception, e:
            if isinstance(e[2], str):
                try:
                    if isinstance(json.loads(e[2])['error']['message'], str):
                        error = json.loads(e[2])['error']['message']
                    if error == "Method not found":
                        log.error(
                            "Coin does not support getblocktemplate!!! (time to upgrade.)"
                        )
                        reactor.stop()
                    elif "downloading blocks" in error:
                        log.error(
                            "Coin downloading blockchain... will check back in 30 sec"
                        )
                        time.sleep(29)
                    else:
                        log.error("Coin Error: %s", error)
                except ValueError:
                    log.error(
                        "Failed Connect(HTTP 500 or Invalid JSON), Check Username and Password!"
                    )
                    reactor.stop()
Esempio n. 10
0
def setup(on_startup):
	'''Setup mining service internal environment.
	You should not need to change this. If you
	want to use another Worker manager or Share manager,
	you should set proper reference to Interfaces class
	*before* you call setup() in the launcher script.'''

	import lib.settings as settings

	# Get logging online as soon as possible
	import lib.logger
	log = lib.logger.get_logger('mining')

	from interfaces import Interfaces

	from lib.block_updater import BlockUpdater
	from lib.template_registry import TemplateRegistry
	from lib.bitcoin_rpc_manager import BitcoinRPCManager
	from lib.template_generator import BlockTemplateGenerator
	from lib.coinbaser import Coinbaser
	from lib.factories import ConstructionYard
	from lib.Factory import Factory

	bitcoin_rpc = BitcoinRPCManager()

	# Check coind
	#		 Check we can connect (sleep)
	# Check the results:
	#		 - getblocktemplate is avalible		(Die if not)
	#		 - we are not still downloading the blockchain		(Sleep)
	log.debug("Connecting to upstream blockchain network daemon...")
	upstream_connection_ready = False
	while True:
		try:
			# Check for 'submitblock' RPC function
			# Wait for this to complete
			log.debug("Starting check_submitblock")
			yield bitcoin_rpc.check_submitblock()
			log.debug("Finished check_submitblock")

			# Check for 'getblocktemplate' RPC function
			# Wait for this to complete
			log.debug("Starting check_getblocktemplate")
			yield bitcoin_rpc.check_getblocktemplate()
			log.debug("Completed check_getblocktemplate")

			# Check for 'getinfo' RPC function
			# Wait for this to complete
			log.debug("Starting check_getinfo")
			yield bitcoin_rpc.check_getinfo()
			log.debug("Completed check_getinfo")

			# All is good
			upstream_connection_ready = True
			break
		except ConnectionRefusedError, e:
			# No sense in continuing execution
			log.error("Upstream network daemon refused connection: %s" % (str(e)))
			break
		except Exception, e:
			# Possible race condition
			(critical, waitTime, message) = startup_exception_handler(e)
			if critical:
				# Unrecoverable error prevents us from starting up
				log.error(message)
				break
			else:
				# Wait before trying again
				log.warning(message)
				time.sleep(waitTime)
Esempio n. 11
0
def setup(on_startup):
    '''Setup mining service internal environment.
	You should not need to change this. If you
	want to use another Worker manager or Share manager,
	you should set proper reference to Interfaces class
	*before* you call setup() in the launcher script.'''

    import lib.settings as settings

    # Get logging online as soon as possible
    import lib.logger
    log = lib.logger.get_logger('mining')

    from interfaces import Interfaces

    from lib.block_updater import BlockUpdater
    from lib.template_registry import TemplateRegistry
    from lib.bitcoin_rpc_manager import BitcoinRPCManager
    from lib.template_generator import BlockTemplateGenerator
    from lib.coinbaser import Coinbaser
    from lib.factories import ConstructionYard
    from lib.Factory import Factory

    bitcoin_rpc = BitcoinRPCManager()

    # Check coind
    #		 Check we can connect (sleep)
    # Check the results:
    #		 - getblocktemplate is avalible		(Die if not)
    #		 - we are not still downloading the blockchain		(Sleep)
    log.debug("Connecting to upstream blockchain network daemon...")
    upstream_connection_ready = False
    while True:
        try:
            # Check for 'submitblock' RPC function
            # Wait for this to complete
            log.debug("Starting check_submitblock")
            yield bitcoin_rpc.check_submitblock()
            log.debug("Finished check_submitblock")

            # Check for 'getblocktemplate' RPC function
            # Wait for this to complete
            log.debug("Starting check_getblocktemplate")
            yield bitcoin_rpc.check_getblocktemplate()
            log.debug("Completed check_getblocktemplate")

            # Check for 'getinfo' RPC function
            # Wait for this to complete
            log.debug("Starting check_getinfo")
            yield bitcoin_rpc.check_getinfo()
            log.debug("Completed check_getinfo")

            # All is good
            upstream_connection_ready = True
            break
        except ConnectionRefusedError, e:
            # No sense in continuing execution
            log.error("Upstream network daemon refused connection: %s" %
                      (str(e)))
            break
        except Exception, e:
            # Possible race condition
            (critical, waitTime, message) = startup_exception_handler(e)
            if critical:
                # Unrecoverable error prevents us from starting up
                log.error(message)
                break
            else:
                # Wait before trying again
                log.warning(message)
                time.sleep(waitTime)
Esempio n. 12
0
def setup(on_startup):
    '''Setup mining service internal environment.
    You should not need to change this. If you
    want to use another Worker manager or Share manager,
    you should set proper reference to Interfaces class
    *before* you call setup() in the launcher script.'''

    import lib.settings as settings

    # Get logging online as soon as possible
    import lib.logger
    log = lib.logger.get_logger('mining')

    from interfaces import Interfaces

    from lib.block_updater import BlockUpdater
    from lib.template_registry import TemplateRegistry
    from lib.bitcoin_rpc_manager import BitcoinRPCManager
    from lib.block_template import BlockTemplate
    from lib.coinbaser import SimpleCoinbaser

    bitcoin_rpc = BitcoinRPCManager()

    # Check litecoind
    #         Check we can connect (sleep)
    # Check the results:
    #         - getblocktemplate is avalible        (Die if not)
    #         - we are not still downloading the blockchain        (Sleep)
    log.info("Connecting to mediterraneancoind...")
    while True:
        try:
            result = (yield bitcoin_rpc.getblocktemplate())
            if isinstance(result, dict):
                # litecoind implements version 1 of getblocktemplate
                if result['version'] >= 1:
                    result = (yield bitcoin_rpc.getinfo())
                    if isinstance(result, dict):
                        if 'stake' in result and settings.COINDAEMON_Reward == 'POS':
                            log.info(
                                "CoinD looks to be a POS Coin, Config for POS looks correct"
                            )
                            break
                        elif 'stake' not in result and settings.COINDAEMON_Reward == 'POW':
                            log.info(
                                "CoinD looks to be a POW Coin, Config looks to be correct"
                            )
                            break
                        else:
                            log.error(
                                "Wrong Algo Selected, Switch to appropriate POS/POW in config.py!"
                            )
                            reactor.stop()
                else:
                    log.error("Block Version mismatch: %s" % result['version'])

        except ConnectionRefusedError, e:
            log.error(
                "Connection refused while trying to connect to the coind (are your COIND_* settings correct?)"
            )
            reactor.stop()
            break

        except Exception, e:
            if isinstance(e[2], str):
                try:
                    if isinstance(json.loads(e[2])['error']['message'], str):
                        error = json.loads(e[2])['error']['message']
                    if error == "Method not found":
                        log.error(
                            "CoinD does not support getblocktemplate!!! (time to upgrade.)"
                        )
                        reactor.stop()
                    elif "downloading blocks" in error:
                        log.error(
                            "CoinD downloading blockchain... will check back in 30 sec"
                        )
                        time.sleep(29)
                    else:
                        log.error("Coind Error: %s", error)
                except ValueError:
                    log.error(
                        "Failed Connect(HTTP 500 or Invalid JSON), Check Username and Password!"
                    )
                    reactor.stop()
Esempio n. 13
0
    def changeCoin(cls, res, host, port, user, password, address, powpos, txcomments):

        cls.template_registry.update_in_progress = True

        settings.COINDAEMON_TRUSTED_HOST = str(host)
        settings.COINDAEMON_TRUSTED_PORT = port
        settings.COINDAEMON_TRUSTED_USER = str(user)
        settings.COINDAEMON_TRUSTED_PASSWORD = str(password)
        settings.CENTRAL_WALLET = str(address)
        settings.COINDAEMON_TX = 'yes' if txcomments else 'no'

        # TODO add coin name option so username doesn't have to be the same as coin name
        settings.COINDAEMON_NAME = str(user)

        log.info("CHANGING COIN # "+str(user)+" txcomments: "+settings.COINDAEMON_TX)
        
        ''' Function to add a litecoind instance live '''
        from lib.coinbaser import SimpleCoinbaser
        from lib.bitcoin_rpc_manager import BitcoinRPCManager
        from lib.block_template import BlockTemplate
        from subscription import MiningSubscription
        
        #(host, port, user, password) = args
        bitcoin_rpc = BitcoinRPCManager()

        result = (yield bitcoin_rpc.check_submitblock())
        if result == True:
            log.info("Found submitblock")
        elif result == False:
            log.info("Did not find submitblock")
        else:
            log.info("unknown submitblock result")

        data = (yield bitcoin_rpc.getblocktemplate())
        if isinstance(data, dict):
            # litecoind implements version 1 of getblocktemplate
            if data['version'] >= 1:
                result = (yield bitcoin_rpc.getdifficulty())
                if isinstance(result,dict):
                    if 'proof-of-stake' in result:
                        settings.COINDAEMON_Reward = 'POS'
                        log.info("Coin detected as POS")
                else:
                    settings.COINDAEMON_Reward = 'POW'
                    log.info("Coin detected as POW")
            else:
                    log.error("Block Version mismatch: %s" % result['version'])

        coinbaser = SimpleCoinbaser(bitcoin_rpc, getattr(settings, 'CENTRAL_WALLET'))
        (yield coinbaser.on_load)

        cls.template_registry.update(BlockTemplate,
                                     coinbaser,
                                     bitcoin_rpc,
                                     31,
                                     MiningSubscription.on_template,
                                     cls.share_manager.on_network_block,
                                     data)
        
        log.info("New litecoind connection changed %s:%s" % (host, port))

        defer.returnValue(True)
Esempio n. 14
0
def setup(on_startup):
    '''Setup mining service internal environment.
    You should not need to change this. If you
    want to use another Worker manager or Share manager,
    you should set proper reference to Interfaces class
    *before* you call setup() in the launcher script.'''
    
    import lib.settings as settings
        
    # Get logging online as soon as possible
    import lib.logger
    log = lib.logger.get_logger('mining')

    from interfaces import Interfaces
    
    from lib.block_updater import BlockUpdater
    from lib.template_registry import TemplateRegistry
    from lib.bitcoin_rpc_manager import BitcoinRPCManager
    from lib.block_template import BlockTemplate
    from lib.coinbaser import SimpleCoinbaser
    
    bitcoin_rpc = BitcoinRPCManager()
    
    # Check litecoind
    #         Check we can connect (sleep)
    # Check the results:
    #         - getblocktemplate is avalible        (Die if not)
    #         - we are not still downloading the blockchain        (Sleep)
    log.info("Connecting to mediterraneancoind...")
    while True:
        try:
            result = (yield bitcoin_rpc.getblocktemplate())
            if isinstance(result, dict):
                # litecoind implements version 1 of getblocktemplate
                if result['version'] >= 1:
		   result = (yield bitcoin_rpc.getinfo())
                   if isinstance(result,dict):
                      if 'stake' in result and settings.COINDAEMON_Reward == 'POS':
			 log.info("CoinD looks to be a POS Coin, Config for POS looks correct")
                         break
                      elif 'stake' not in result and settings.COINDAEMON_Reward == 'POW':
			 log.info("CoinD looks to be a POW Coin, Config looks to be correct")
			 break
                      else:
                          log.error("Wrong Algo Selected, Switch to appropriate POS/POW in config.py!")
                          reactor.stop()
                else:
                    log.error("Block Version mismatch: %s" % result['version'])


        except ConnectionRefusedError, e:
            log.error("Connection refused while trying to connect to the coind (are your COIND_* settings correct?)")
            reactor.stop()
            break

        except Exception, e:
            if isinstance(e[2], str):
		try:
                   if isinstance(json.loads(e[2])['error']['message'], str):
	              error = json.loads(e[2])['error']['message']
                   if error == "Method not found":
                      log.error("CoinD does not support getblocktemplate!!! (time to upgrade.)")
                      reactor.stop()
                   elif "downloading blocks" in error:
                       log.error("CoinD downloading blockchain... will check back in 30 sec")
                       time.sleep(29)
                   else:
                       log.error("Coind Error: %s", error)
	        except ValueError:
		        log.error("Failed Connect(HTTP 500 or Invalid JSON), Check Username and Password!")
		        reactor.stop()