2 # Copyright(C) 2012 thomasv@gitorious
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as
6 # published by the Free Software Foundation, either version 3 of the
7 # License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public
15 # License along with this program. If not, see
16 # <http://www.gnu.org/licenses/agpl.html>.
18 import time, sys, traceback
21 config = ConfigParser.ConfigParser()
22 # set some defaults, which will be overwritten by the config file
23 config.add_section('server')
24 config.set('server','banner', 'Welcome to Electrum!')
25 config.set('server', 'host', 'localhost')
26 config.set('server', 'native_port', '50000')
27 config.set('server', 'stratum_tcp_port', '50001')
28 config.set('server', 'stratum_http_port', '8081')
29 config.set('server', 'password', '')
30 config.set('server', 'irc', 'yes')
31 config.set('server', 'irc_nick', '')
32 config.add_section('database')
33 config.set('database', 'type', 'psycopg2')
34 config.set('database', 'database', 'abe')
35 config.set('server', 'backend', 'abe')
37 for path in ('', '/etc/'):
38 filename = path + 'electrum.conf'
40 with open(filename, 'r') as f:
43 print "Could not read %s. Falling back." % filename
46 with open('/etc/electrum.banner', 'r') as f:
47 config.set('server','banner', f.read())
51 password = config.get('server','password')
52 host = config.get('server','host')
53 native_port = config.get('server','native_port')
54 stratum_tcp_port = config.get('server','stratum_tcp_port')
55 stratum_http_port = config.get('server','stratum_http_port')
57 from processor import Dispatcher
58 from transports.stratum_http import HttpServer
59 from transports.stratum_tcp import TcpServer
60 from transports.native import NativeServer
62 from modules.irc import ServerProcessor
63 backend_name = config.get('server', 'backend')
64 if backend_name == "libbitcoin":
65 # NativeServer cannot be used with libbitcoin
67 from modules.python_bitcoin import BlockchainProcessor
68 elif backend_name == "abe":
69 from modules.abe import AbeProcessor as BlockchainProcessor
71 raise Exception('Unknown backend specified')
73 if __name__ == '__main__':
77 server = jsonrpclib.Server('http://%s:%s'%(host,stratum_http_port))
80 out = server.server.stop(password)
82 out = "Unknown command: '%s'" % cmd
87 dispatcher = Dispatcher()
88 shared = dispatcher.shared
90 # Create and register processors
91 abe = BlockchainProcessor(config)
92 dispatcher.register('blockchain', abe)
94 sb = ServerProcessor(config)
95 dispatcher.register('server', sb)
97 # Create various transports we need
99 if native_port: transports.append( NativeServer(shared, abe, sb, config.get('server','banner'), host, int(native_port)) )
100 if stratum_tcp_port: transports.append( TcpServer(dispatcher, host, int(stratum_tcp_port)) )
101 if stratum_http_port: transports.append( HttpServer(dispatcher, host, int(stratum_http_port)) )
102 for server in transports:
105 print "starting Electrum server on", host
106 while not shared.stopped():
108 print "server stopped"