MCPcopy
hub / github.com/lhartikk/naivechain / initHttpServer

Function initHttpServer

main.js:34–54  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32var blockchain = [getGenesisBlock()];
33
34var initHttpServer = () => {
35 var app = express();
36 app.use(bodyParser.json());
37
38 app.get('/blocks', (req, res) => res.send(JSON.stringify(blockchain)));
39 app.post('/mineBlock', (req, res) => {
40 var newBlock = generateNextBlock(req.body.data);
41 addBlock(newBlock);
42 broadcast(responseLatestMsg());
43 console.log('block added: ' + JSON.stringify(newBlock));
44 res.send();
45 });
46 app.get('/peers', (req, res) => {
47 res.send(sockets.map(s => s._socket.remoteAddress + ':' + s._socket.remotePort));
48 });
49 app.post('/addPeer', (req, res) => {
50 connectToPeers([req.body.peer]);
51 res.send();
52 });
53 app.listen(http_port, () => console.log('Listening http on port: ' + http_port));
54};
55
56
57var initP2PServer = () => {

Callers 1

main.jsFile · 0.85

Calls 5

generateNextBlockFunction · 0.85
addBlockFunction · 0.85
broadcastFunction · 0.85
responseLatestMsgFunction · 0.85
connectToPeersFunction · 0.85

Tested by

no test coverage detected