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')
37 f = open('/etc/electrum.conf','r')
41 print "Could not read electrum.conf. I will use the default values."
44 f = open('/etc/electrum.banner','r')
45 config.set('server','banner', f.read())
50 password = config.get('server','password')
51 host = config.get('server','host')
52 use_libbitcoin = False
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')
56 # NativeServer cannot be used with libbitcoin
57 if use_libbitcoin: native_port = None
60 from processor import Dispatcher
61 from transports.stratum_http import HttpServer
62 from transports.stratum_tcp import TcpServer
63 from transports.native import NativeServer
65 from modules.irc import ServerProcessor
67 from modules.python_bitcoin import LibBitcoinProcessor as BlockchainProcessor
69 from modules.abe import AbeProcessor as BlockchainProcessor
71 if __name__ == '__main__':
75 server = jsonrpclib.Server('http://%s:8081'%host)
78 out = server.stop(password)
80 out = "Unknown command: '%s'" % cmd
85 dispatcher = Dispatcher()
86 shared = dispatcher.shared
88 # Create and register processors
89 abe = BlockchainProcessor(config)
90 dispatcher.register('blockchain', abe)
92 sb = ServerProcessor(config)
93 dispatcher.register('server', sb)
95 # Create various transports we need
97 if native_port: transports.append( NativeServer(shared, abe, sb, config.get('server','banner'), host, int(native_port)) )
98 if stratum_tcp_port: transports.append( TcpServer(dispatcher, host, int(stratum_tcp_port)) )
99 if stratum_http_port: transports.append( HttpServer(dispatcher, host, int(stratum_http_port), password) )
100 for server in transports:
103 print "starting Electrum server on", host
104 while not shared.stopped():
106 print "server stopped"