Initial commit
[stratum-mining.git] / mining / __init__.py
1 from service import MiningService
2 from subscription import MiningSubscription
3
4 def setup():
5     '''Setup mining service internal environment.
6     You should not need to change this. If you
7     want to use another Worker manager or Share manager,
8     you should set proper reference to Interfaces class
9     *before* you call setup() in the launcher script.'''
10         
11     from stratum import settings
12     from interfaces import Interfaces
13     
14     from lib.block_updater import BlockUpdater
15     from lib.template_registry import TemplateRegistry
16     from lib.bitcoin_rpc import BitcoinRPC
17     from lib.block_template import BlockTemplate
18     from lib.coinbaser import SimpleCoinbaser
19     
20     bitcoin_rpc = BitcoinRPC(settings.BITCOIN_TRUSTED_HOST,
21                              settings.BITCOIN_TRUSTED_PORT,
22                              settings.BITCOIN_TRUSTED_USER,
23                              settings.BITCOIN_TRUSTED_PASSWORD)
24     
25     registry = TemplateRegistry(BlockTemplate,
26                                 SimpleCoinbaser(bitcoin_rpc, settings.CENTRAL_WALLET),
27                                 bitcoin_rpc,
28                                 settings.INSTANCE_ID,
29                                 MiningSubscription.on_block)
30
31     # Template registry is the main interface between Stratum service
32     # and pool core logic
33     Interfaces.set_template_registry(registry)
34     
35     # Set up polling mechanism for detecting new block on the network
36     # This is just failsafe solution when -blocknotify
37     # mechanism is not working properly    
38     BlockUpdater(registry, bitcoin_rpc)