-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.js
59 lines (50 loc) · 1.98 KB
/
start.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
/*jslint node: true */
'use strict';
// Obyte imports (libraries)
const constants = require('ocore/constants.js');
const conf = require('ocore/conf');
const eventBus = require('ocore/event_bus');
const headlessWallet = require('headless-obyte');
const device = require('ocore/device.js');
const walletGeneral = require('ocore/wallet_general');
// ObyFit imports (modules)
const config = require('./conf_game.js');
const scheduler = require('./scheduler.js');
const chatting = require('./chat.js');
const newTransactions = require('./newTransactions.js');
const stableTransactions = require('./stableTransactions.js');
// headless wallet is ready Event
eventBus.once('headless_wallet_ready', () => {
headlessWallet.setupChatEventHandlers();
/* ****************** OBY FIT *********************** */
const app = require('./startup/app');
// !!!!!!!!!!!! Change for deployment !!!!!!!!!!!!!!!! //
const server = app.listen(process.env.PORT || 8080, () => {
console.log(`Express is running on port ${server.address().port}`);
});
// add AA's address to the watched list of addresses
let aaAddress = config.aaAddress;
walletGeneral.addWatchedAddress(aaAddress, function() {
console.log('====== AA address: ' + aaAddress + ' is added to the list of watched addresses');
});
// user pairs his device with the bot
eventBus.on('paired', (from_address, pairing_secret) => {
device.sendMessageToDevice(from_address, 'text',
"Welcome to ObyFit Bot! Please enter your wallet address.");
});
// user sends message to the bot
eventBus.on('text', (from_address, text) => {
text = text.trim();
//chatting.chatting(from_address, text);
});
});
// user pays to the AA
eventBus.on('new_my_transactions', (arrUnits) => {
newTransactions.newTransactions(arrUnits);
});
// user payment is confirmed to the AA
eventBus.on('my_transactions_became_stable', (arrUnits) => {
stableTransactions.stableTransactions(arrUnits);
});
scheduler.startScheduler();
process.on('unhandledRejection', up => { throw up; });