-
Notifications
You must be signed in to change notification settings - Fork 0
/
testEVMExpress.ts
141 lines (123 loc) · 3.8 KB
/
testEVMExpress.ts
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import express from 'express';
import bodyParser from 'body-parser';
import callEthereumVirtualMachine from './callEthereumVirtualMachine';
import sandboxEthereumVirtualMachineCall from './sandboxEthereumVirtualMachineCall';
import putAccount from './putEVMAccount';
import putContract from './putEVMContract';
import getAccount from './getEVMAccount';
import getStateRoot from './getStateRootForEVM';
import setStateRoot from './setEVMStateRoot';
import estimateGasUsed from './estimateGasUsedForTransaction';
import getCurrentBlock from './getCurrentBlockchainBlock';
import setCurrentBlockParams from './setParamsForCurrentBlock';
import getTransactionWithReceiptToStore from './getTransactionWithStoredReceipt';
import getBlockToStore from './getBlockToStoreInBlockchain';
import storeLog from './storeEVMLog';
// Create the express application
const app = express();
// The port the express app will listen on
const port: number = 3000;
// Add body parser middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// routes - unsecure now
// Add the / route
app.get('/', (req: any, res: any) => {
res.send('Hello world!');
});
// callEthereumVirtualMachine
app.post('/callEVM', async (req: any, res: any) => {
const data = req.body;
const result = await callEthereumVirtualMachine(data);
res.send(result);
});
// sandboxEthereumVirtualMachineCall
app.post('/sandboxCall', async (req: any, res: any) => {
const data = req.body;
const result = await sandboxEthereumVirtualMachineCall(data, false);
res.send(result);
});
// putAccount
app.post('/putAccount', async (req: any, res: any) => {
const data = req.body;
const result = await putAccount(data.address, data.account);
res.send(result);
});
// putContract
app.post('/putContract', async (req: any, res: any) => {
const data = req.body;
const result = await putContract(
data.address,
data.contract,
data.nonce,
data.code,
data.storage
);
res.send(result);
});
// getAccount
app.get('/getAccount', async (req: any, res: any) => {
const data = req.body;
const result = await getAccount(data.address);
res.send(result);
});
// getStateRoot
app.get('/getStateRoot', async (req: any, res: any) => {
const data = req.body;
const result = await getStateRoot();
res.send(result);
});
// setStateRoot
app.post('/setStateRoot', async (req: any, res: any) => {
const data = req.body;
const result = await setStateRoot(data.stateRoot);
res.send(result);
});
// estimateGasUsed - get
app.get('/estimateGasUsed', async (req: any, res: any) => {
const data = req.body;
const result = await estimateGasUsed(data.tx);
res.send(result);
});
// getCurrentBlock
app.get('/getCurrentBlock', async (req: any, res: any) => {
const data = req.body;
const result = await getCurrentBlock();
res.send(result);
});
// setCurrentBlockParams
app.post('/setCurrentBlockParams', async (req: any, res: any) => {
const data = req.body;
const result = await setCurrentBlockParams(
data.nextIndex,
data.timestamp,
data.parentHash
);
res.send(result);
});
// getTransactionWithReceiptToStore
app.get('/getTransactionWithReceiptToStore', async (req: any, res: any) => {
const data = req.body;
const result = await getTransactionWithReceiptToStore(
data.transactionInHex,
data.evmResult,
data.logsMap
);
res.send(result);
});
// getBlockToStore
app.get('/getBlockToStore', async (req: any, res: any) => {
const data = req.body;
const result = await getBlockToStore(data.currentHash);
res.send(result);
});
// storeLog
app.get('/storeLog', async (req: any, res: any) => {
const data = req.body;
const result = await storeLog(data.logsMap, data.logInstance);
res.send(result);
});
// Add the /messages route
app.listen(port, () => {
console.log(`Listening at http://localhost:${port}/`);
});