You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.4 KiB

10 years ago
#!/usr/bin/env python
#
# Electrum - lightweight Bitcoin client
# Copyright (C) 2015 Thomas Voegtlin
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
10 years ago
jsonrpc interface for webservers.
may be called from your php script.
10 years ago
"""
import socket, os
from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer, SimpleJSONRPCRequestHandler
from electrum.wallet import WalletStorage, Wallet
from electrum.commands import known_commands, Commands
class RequestHandler(SimpleJSONRPCRequestHandler):
def do_OPTIONS(self):
self.send_response(200)
self.end_headers()
def end_headers(self):
self.send_header("Access-Control-Allow-Headers",
10 years ago
"Origin, X-Requested-With, Content-Type, Accept")
self.send_header("Access-Control-Allow-Origin", "*")
SimpleJSONRPCRequestHandler.end_headers(self)
class ElectrumGui:
def __init__(self, config, network, plugins):
10 years ago
self.network = network
self.config = config
10 years ago
storage = WalletStorage(self.config.get_wallet_path())
if not storage.file_exists:
raise BaseException("Wallet not found")
self.wallet = Wallet(storage)
self.cmd_runner = Commands(self.config, self.wallet, self.network)
10 years ago
host = config.get('rpchost', 'localhost')
port = config.get('rpcport', 7777)
self.server = SimpleJSONRPCServer((host, port), requestHandler=RequestHandler)
self.server.socket.settimeout(1)
10 years ago
for cmdname in known_commands:
self.server.register_function(getattr(self.cmd_runner, cmdname), cmdname)
10 years ago
def main(self):
10 years ago
self.wallet.start_threads(self.network)
10 years ago
while True:
try:
self.server.handle_request()
except socket.timeout:
continue
except:
break
10 years ago
self.wallet.stop_threads()