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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.