The server interface

The server interface is created using a Python web server framework called Sanic, which helps to code the web server logic in an asynchronous way:

Background: Sanic is a lightweight web server framework that can be used to build a high-speed web server. It supports asynchronous programming by supporting Shiny async request handlers. It makes use of an event loop called uvloop to achieve better performance.
class Server(object): def __init__(self): self.app = Sanic() self.blockchain = Blockchain() self.sockets = [] self.app.add_route(self.blocks, '/blocks', methods=['GET']) self.app.add_route(self.mine_block, '/mineBlock', methods=['POST']) self.app.add_route(self.peers, '/peers', methods=['GET']) self.app.add_route(self.add_peer, ...

Get Foundations of Blockchain now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.