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', 'port', '50000')
27 config.set('server', 'password', '')
28 config.set('server', 'irc', 'yes')
29 config.set('server', 'ircname', 'Electrum server')
30 config.add_section('database')
31 config.set('database', 'type', 'psycopg2')
32 config.set('database', 'database', 'abe')
35 f = open('/etc/electrum.conf','r')
39 print "Could not read electrum.conf. I will use the default values."
42 f = open('/etc/electrum.banner','r')
43 config.set('server','banner', f.read())
48 password = config.get('server','password')
49 host = config.get('server','host')
50 use_libbitcoin = False
53 from processor import Dispatcher
54 from transports.stratum_http import HttpServer
55 from transports.stratum_tcp import TcpServer
56 from transports.native import NativeServer
58 from modules.irc import ServerProcessor
60 from modules.python_bitcoin import LibBitcoinProcessor as BlockchainProcessor
62 from modules.abe import AbeProcessor as BlockchainProcessor
64 if __name__ == '__main__':
68 server = jsonrpclib.Server('http://%s:8081'%host)
71 out = server.stop(password)
73 out = "Unknown command: '%s'" % cmd
78 dispatcher = Dispatcher()
79 shared = dispatcher.shared
81 # Create and register processors
82 abe = BlockchainProcessor(config)
83 dispatcher.register('blockchain', abe)
85 sb = ServerProcessor(config)
86 dispatcher.register('server', sb)
88 # Create various transports we need
90 TcpServer(dispatcher, host, 50001),
91 HttpServer(dispatcher, host, 8081),
94 # NativeServer cannot be used with libbitcoin
95 if not use_libbitcoin:
96 transports.append( NativeServer(shared, abe, sb, config.get('server','banner'), host, 50000) )
98 for server in transports:
101 print "starting Electrum server on", host
102 while not shared.stopped():
104 print "server stopped"