Ejemplo 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)
Ejemplo 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)
Ejemplo 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
Ejemplo 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
Ejemplo n.º 5
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()
Ejemplo 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.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()
Ejemplo 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.'''

    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()
Ejemplo n.º 8
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)
Ejemplo 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.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()