-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
76 lines (51 loc) · 1.75 KB
/
index.js
File metadata and controls
76 lines (51 loc) · 1.75 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
60
61
62
63
64
65
66
67
68
69
70
// Importing libs
const WB = require('kryptokrona-wallet-backend-js');
const express = require('express');
const app = express()
var cors = require('cors')
// Importing functions
const {getKeyset, backgroundSyncTransactions} = require('./utils/walletFunctions');
const {sleep} = require('./utils/misc')
// Loading in the global values
const globals = require('./globals.js');
// Importing all the routes
const testRoute = require('./routes/testRoute')
const paymentRoute = require('./routes/paymentRoute')
const addPaymentsRoute = require('./routes/addPaymentsRoute')
const getAddressRoute = require('./routes/getAddressRoute')
const generatePaymentIDRoute = require('./routes/generatePaymentIDRoute')
// Express.js settings
app.use(cors())
// Adding all the routes
app.use('/test', testRoute)
app.use('/payment', paymentRoute)
app.use('/addPayment', addPaymentsRoute)
app.use('/getAddress', getAddressRoute)
app.use('/generatePaymentID', generatePaymentIDRoute)
// Start the web server
app.listen(3030, async function(err){
if (err) console.log(err);
console.log("Server listening on port", 3030);
await globals.start()
const wallet = globals.getWallet()
const keyset = await getKeyset()
globals.keyset(keyset)
console.log(keyset)
while (true) {
try {
await sleep(10 * 1000)
console.log('Checking for tx....')
backgroundSyncTransactions(keyset)
} catch(error) {
console.error(error)
}
}
});
process.on( 'SIGINT', async function() {
console.log( "\nGracefully shutting down from SIGINT (Ctrl-C)" );
const wallet = globals.getWallet()
await wallet.stop()
// some other closing procedures go here
process.exit();
})
module.exports = app