def reorganize(self, ec, fork_point, arrivals, replaced):
latest = fork_point + len(arrivals)
self.latest.set(latest)
- self.processor.push_response({"method":"numblocks.subscribe", "result": latest})
+ response = {"method": "numblocks.subscribe", "result": latest}
+ self.processor.push_response(response)
self.backend.blockchain.subscribe_reorganize(self.reorganize)
bitcoin.bind(self.respond, request, bitcoin._1))
def respond(self, request, result):
- self.processor.push_response({"id": request["id"], "method":request["method"], "params":request["params"], "result": result})
+ response = {"id": request["id"], "method": request["method"],
+ "params": request["params"], "result": result}
+ self.processor.push_response(response)
class BlockchainProcessor(Processor):
self.backend.stop()
def process(self, request):
-
print "New request (lib)", request
if request["method"] == "numblocks.subscribe":
self.numblocks_subscribe.subscribe(session, request)
elif request["method"] == "address.get_history":
self.address_get_history.get(request)
elif request["method"] == "server.banner":
- self.push_response({"id": request["id"], "method": request["method"], "params":request["params"],
+ self.push_response({"id": request["id"],
+ "method": request["method"], "params": request["params"],
"result": "libbitcoin using python-bitcoin bindings"})
elif request["method"] == "transaction.broadcast":
self.broadcast_transaction(request)
- # Execute and when ready, you call
- # self.push_response(response)
def broadcast_transaction(self, request):
raw_tx = bitcoin.data_chunk(str(request["params"]))
try:
tx = exporter.load_transaction(raw_tx)
except RuntimeError:
- response = {"id": request["id"], "method": request["method"], "params":request["params"], "result": None,
- "error": {"message":
- "Exception while parsing the transaction data.",
- "code": -4}}
+ response = {"id": request["id"], "method": request["method"],
+ "params": request["params"], "result": None,
+ "error": {"message":
+ "Exception while parsing the transaction data.",
+ "code": -4}}
else:
self.backend.protocol.broadcast_transaction(tx)
tx_hash = str(bitcoin.hash_transaction(tx))
- response = {"id": request["id"], "method": request["method"], "params":request["params"], "result": tx_hash}
+ response = {"id": request["id"], "method": request["method"],
+ "params": request["params"], "result": tx_hash}
self.push_response(response)
def run(self):
- # this class is a thread. it does nothing in this example.
print "Warning: pre-alpha prototype. Full of bugs."
while not self.shared.stopped():
time.sleep(1)
config = ConfigParser.ConfigParser()
# set some defaults, which will be overwritten by the config file
config.add_section('server')
- config.set('server','banner', 'Welcome to Electrum!')
+ config.set('server', 'banner', 'Welcome to Electrum!')
config.set('server', 'host', 'localhost')
config.set('server', 'native_port', '50000')
config.set('server', 'stratum_tcp_port', '50001')
from transports.stratum_tcp import TcpServer
from transports.native import NativeServer
- from modules.irc import ServerProcessor
+ from backends.irc import ServerProcessor
backend_name = config.get('server', 'backend')
if backend_name == "libbitcoin":
# NativeServer cannot be used with libbitcoin
native_port = None
config.set('server', 'native_port', '')
try:
- backend = __import__("modules." + backend_name,
+ backend = __import__("backends." + backend_name,
fromlist=["BlockchainProcessor"])
except ImportError:
sys.stderr.write('Unknown backend specified\n')