-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
65 lines (60 loc) · 2.06 KB
/
main.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
// Required libraries
const IOTA = require('iota.lib.js');
const SQLite3 = require('sqlite3');
// Required app components
const entryPoint = require('./entryPoint');
const rightsManager = require('./rightsManager');
const sensor = require('./sensor');
global.mam = require('./mam');
global.buyer = require('./buyer');
global.seller = require('./seller');
// Global APIs
global.iota = new IOTA({ provider: 'https://node.iota.moe:443' });
global.db = new SQLite3.Database('log.db');
// Global variables
global.myPort = ***;
global.myName = '***' + myPort;
global.mySeed = '***';
global.minWeightMagnitude = 14;
global.depth = 3;
// Init app
exports.init = function () {
iota.api.getNewAddress(mySeed, { 'returnAll': true }, function (error, addresses) {
if (error) {
console.error(error);
} else {
global.addressIndex = addresses.length - 1;
entryPoint.run();
rightsManager.run();
sensor.run();
}
});
}
// Useful function for sending transfers
/*global.doPromotes = function (transactionHash, currentHash) {
for (let index = 0; index < 3; index++) {
iota.api.getLatestInclusion([transactionHash], function (error, included) {
if (error) {
console.error(error);
} else if (included[0]) {
console.log('Transaction confirmed');
console.log('--------------------------------');
process.exit();
}
});
iota.api.promoteTransaction(
currentHash, depth, minWeightMagnitude,
[{ 'address': '9'.repeat(81), 'value': 0 }],
{ 'delay': 0 },
function (error, promote) {
if (error) {
console.error(error);
} else {
let promoteHash = promote[0].hash;
console.log('Promote:', promoteHash);
doPromotes(transactionHash, promoteHash);
}
}
);
}
}*/