-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
164 lines (137 loc) · 4.34 KB
/
index.js
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
const express = require('express');
const app = express();
const fs = require('fs')
const http = require('http')
const path = require('path')
const bodyParser = require('body-parser');
const { spawn } = require('child_process');
const request = require('request');
var Web3 = require('web3')
const web3 = new Web3(Web3.givenProvider || process.env.ENDPOINT);
require('dotenv').config();
// setup server parameters and homepage
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.listen(process.env.PORT || 3000);
app.all('/', (req, res) => {
res.sendFile('index.html', {root: __dirname});
})
// setup add endpoint action
app.all('/pages/addendpoint', (req, res) => {
fs.writeFileSync("./dls/newendpoint.json", '{"endpoint":"' + req.body.newEndpoint + '"}');
spawn('node', ['scripts/addendpoint.js']);
setTimeout(() => {
res.sendFile('pages/addendpoint.html', {root: __dirname});
}, 3000)
})
// setup create wallet action
app.all('/pages/create', (req, res) => {
spawn('node', ['scripts/create.js'])
setTimeout(() => {
res.sendFile('pages/create.html', {root: __dirname})
}, 3000)
})
// setup check balance action
app.all('/pages/balance', (req, res) => {
spawn('node', ['scripts/balance.js'])
setTimeout(() => {
res.sendFile('pages/balance.html', {root: __dirname})
}, 3000)
})
// setup add password action
app.all('/pages/addpassword', (req, res) => {
fs.writeFileSync("./dls/newpassword.json", '{"password":"' + req.body.newPassword + '"}');
spawn('node', ['scripts/addpassword.js']);
setTimeout(() => {
res.sendFile('pages/addpassword.html', {root: __dirname});
}, 3000)
})
// setup encrypt action
app.all('/pages/encrypt', (req, res) => {
spawn('node', ['scripts/encrypt.js'])
setTimeout(() => {
res.sendFile('pages/encrypt.html', {root: __dirname})
}, 3000)
})
// setup decrypt action
app.all('/pages/decrypt', (req, res) => {
spawn('node', ['scripts/decrypt.js'])
setTimeout(() => {
res.sendFile('pages/decrypt.html', {root: __dirname})
}, 3000)
})
// setup add private key action
app.all('/pages/addkey', (req, res) => {
fs.writeFileSync("./dls/newkey.json", req.body.newkey);
spawn('node', ['scripts/addkey.js']);
setTimeout(() => {
res.sendFile('pages/addkey.html', {root: __dirname});
}, 3000)
})
// setup transaction gas cost estimation
app.all('/pages/estimate', (req, res) => {
fs.writeFileSync("./dls/estimate.json", '{"to":"' + req.body.receiver + '"}');
spawn('node', ['scripts/estimate.js']);
setTimeout(() => {
res.sendFile('pages/estimate.html', {root: __dirname});
}, 3000)
})
// setup add private key action
app.all('/pages/receipt', (req, res) => {
// fs.writeFileSync("./dls/receiver.json", '{"to":"' + req.body.txReceiver + '"}');
fs.writeFileSync("./dls/txdetails.json", JSON.stringify({
"to": req.body.txReceiver,
"value": req.body.txValue,
"data": req.body.txData,
"gas": req.body.txGas
}));
spawn('node', ['scripts/send.js']);
setTimeout(() => {
res.sendFile('pages/receipt.html', {root: __dirname});
}, 3000)
})
// setup logo download
app.get('/buidl-yow-logo.png', (req, res) => {
res.download('buidl-yow-logo.png')
});
// setup new endpoint download
app.get('/dls/newendpoint.json', (req, res) => {
res.download('dls/newendpoint.json')
});
// setup key storage download
app.get('/dls/keys.json', (req, res) => {
res.download('dls/keys.json')
});
// setup balance sheet download
app.get('/dls/balance.json', (req, res) => {
res.download('dls/balance.json')
});
// setup new password download
app.get('/dls/newpassword.json', (req, res) => {
res.download('dls/newpassword.json')
});
// setup encrypted keystore download
app.get('/dls/encryptedKeyStore.json', (req, res) => {
res.download('dls/encryptedKeyStore.json')
});
// setup decrypted keystore download
app.get('/dls/decryptedKeyStore.json', (req, res) => {
res.download('dls/decryptedKeyStore.json')
});
// setup custom private key download
app.get('/dls/addkey.json', (req, res) => {
res.download('dls/addkey.json')
});
// setup transaction gas estimate download
app.get('/dls/estimate.json', (req, res) => {
res.download('dls/estimate.json')
});
// setup transaction receipt download
app.get('/dls/receipt.json', (req, res) => {
res.download('dls/receipt.json')
});
// setup stylesheet access
app.get('/css/main.css', (req, res) => {
res.download('css/main.css')
});
module.exports = app