-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
59 lines (49 loc) · 1.69 KB
/
index.ts
File metadata and controls
59 lines (49 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import express from "express";
import http from 'http';
import WebSocket from 'ws';
import config from './src/config';
import socketServer from "./src/frameworks/websocket/server";
import serverConfig from './src/frameworks/webserver/server';
import routes from './src/frameworks/webserver/routes/index';
import expressConfig from "./src/frameworks/webserver/express";
import errorHandlingMiddleware from './src/frameworks/webserver/middlewares/errorHandler'
import Block from "./src/entities/block";
import Transaction, { UnspentTxOut } from "./src/entities/transaction";
import ProcessTransactions from "./src/application/use_cases/transaction/processTransactions";
import WalletService from "./src/application/services/walletService";
import socketGateway from "./src/adapters/gateways/p2pGateway";
const app = express();
const server = http.createServer(app);
// configure express
expressConfig(app);
// server configuration
serverConfig(server, config);
// Initialize the genesis block
const genesisBlock: Block = Block.createGenesisBlock();
let blockchain: Block[] = [genesisBlock as Block];
// initialize transactions and unspentOutputs list
let transactionPool: Transaction[] = [];
let unspentTxOuts: UnspentTxOut[] = ProcessTransactions.execute(blockchain[0].data, [], 0);
// initialize websocket
const sockets: WebSocket[] = [];
const socketService = socketGateway(
blockchain,
transactionPool,
unspentTxOuts,
sockets
);
socketServer(5000, sockets, socketService);
// routes for each endpoint
routes(
app,
express,
blockchain,
sockets,
unspentTxOuts,
transactionPool,
socketService
);
// initialize wallet
WalletService.initWallet();
// handle all errors
app.use(errorHandlingMiddleware);