1 from service import MiningService
2 from subscription import MiningSubscription
3 from twisted.internet import defer
8 '''Setup mining service internal environment.
9 You should not need to change this. If you
10 want to use another Worker manager or Share manager,
11 you should set proper reference to Interfaces class
12 *before* you call setup() in the launcher script.'''
14 from stratum import settings
15 from interfaces import Interfaces
17 # Let's wait until share manager and worker manager boot up
18 (yield Interfaces.share_manager.on_load)
19 (yield Interfaces.worker_manager.on_load)
21 from lib.block_updater import BlockUpdater
22 from lib.template_registry import TemplateRegistry
23 from lib.bitcoin_rpc import BitcoinRPC
24 from lib.block_template import BlockTemplate
25 from lib.coinbaser import SimpleCoinbaser
27 bitcoin_rpc = BitcoinRPC(settings.BITCOIN_TRUSTED_HOST,
28 settings.BITCOIN_TRUSTED_PORT,
29 settings.BITCOIN_TRUSTED_USER,
30 settings.BITCOIN_TRUSTED_PASSWORD)
33 log = stratum.logger.get_logger('mining')
35 log.info('Waiting for bitcoin RPC...')
39 result = (yield bitcoin_rpc.getblocktemplate())
40 if isinstance(result, dict):
41 log.info('Response from bitcoin RPC OK')
46 coinbaser = SimpleCoinbaser(bitcoin_rpc, settings.CENTRAL_WALLET)
47 (yield coinbaser.on_load)
49 registry = TemplateRegistry(BlockTemplate,
53 MiningSubscription.on_template,
54 Interfaces.share_manager.on_network_block)
56 # Template registry is the main interface between Stratum service
58 Interfaces.set_template_registry(registry)
60 # Set up polling mechanism for detecting new block on the network
61 # This is just failsafe solution when -blocknotify
62 # mechanism is not working properly
63 BlockUpdater(registry, bitcoin_rpc)
65 log.info("MINING SERVICE IS READY")
66 on_startup.callback(True)