-
Notifications
You must be signed in to change notification settings - Fork 90
/
hsdMain.js
60 lines (54 loc) · 1.27 KB
/
hsdMain.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
require('./sentry');
const ipc = require('electron').ipcRenderer;
const FullNode = require('hsd/lib/node/fullnode');
const WalletPlugin = require('hsd/lib/wallet/plugin');
const Script = require('hsd/lib/script/script');
const remote = require('electron').remote;
const {hashName, types} = require('hsd/lib/covenants/rules');
const {Output, MTX, Address} = require('hsd/lib/primitives');
let hsd = null;
ipc.on('start', async (_, prefix, net, apiKey) => {
if (hsd) {
ipc.send('started');
return;
}
try {
hsd = new FullNode({
config: true,
argv: true,
env: true,
logFile: true,
logConsole: false,
logLevel: 'debug',
memory: false,
workers: false,
network: net,
loader: require,
prefix: prefix,
listen: true,
bip37: true,
indexAddress: true,
indexTX: true,
apiKey,
});
} catch (e) {
ipc.send('error', e);
return;
}
hsd.ensure()
.then(() => hsd.open())
.then(() => ipc.send('started'))
.then(() => hsd.connect())
.then(() => hsd.startSync())
.catch((e) => {
console.log(e);
ipc.send('error', e);
});
});
ipc.on('close', () => {
if (!hsd) {
return;
}
hsd.close()
.then(() => remote.getCurrentWindow().close());
});