• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

handshake-org / hsd / 6586272260

20 Oct 2023 10:02AM UTC coverage: 68.549% (-0.1%) from 68.674%
6586272260

push

github

nodech
Merge PR #859 from 'nodech/wallet-lifecycles'

7474 of 12746 branches covered (0.0%)

Branch coverage included in aggregate %.

36 of 36 new or added lines in 3 files covered. (100.0%)

23909 of 33036 relevant lines covered (72.37%)

34145.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

21.62
/lib/wallet/node.js
1
/*!
2
 * server.js - wallet server for hsd
3
 * Copyright (c) 2017-2018, Christopher Jeffrey (MIT License).
4
 * https://github.com/handshake-org/hsd
5
 */
6

7
'use strict';
8

9
const assert = require('bsert');
1✔
10
const Node = require('../node/node');
1✔
11
const WalletDB = require('./walletdb');
1✔
12
const HTTP = require('./http');
1✔
13
const Client = require('./client');
1✔
14
const RPC = require('./rpc');
1✔
15
const pkg = require('../pkg');
1✔
16

17
/**
18
 * Wallet Node
19
 * @extends Node
20
 */
21

22
class WalletNode extends Node {
23
  /**
24
   * Create a wallet node.
25
   * @constructor
26
   * @param {Object?} options
27
   */
28

29
  constructor(options) {
30
    super(pkg.name, 'hsw.conf', 'wallet.log', options);
×
31

32
    this.opened = false;
×
33

34
    this.client = new Client({
×
35
      network: this.network,
36
      url: this.config.str('node-url'),
37
      host: this.config.str('node-host'),
38
      port: this.config.uint('node-port', this.network.rpcPort),
39
      ssl: this.config.bool('node-ssl'),
40
      apiKey: this.config.str('node-api-key')
41
    });
42

43
    this.wdb = new WalletDB({
×
44
      network: this.network,
45
      logger: this.logger,
46
      workers: this.workers,
47
      client: this.client,
48
      prefix: this.config.prefix,
49
      memory: this.config.bool('memory'),
50
      maxFiles: this.config.uint('max-files'),
51
      cacheSize: this.config.mb('cache-size'),
52
      wipeNoReally: this.config.bool('wipe-no-really'),
53
      spv: this.config.bool('spv'),
54
      walletMigrate: this.config.uint('migrate'),
55
      migrateNoRescan: this.config.bool('migrate-no-rescan', false),
56
      icannlockup: this.config.bool('icannlockup', false)
57
    });
58

59
    this.rpc = new RPC(this);
×
60

61
    this.http = new HTTP({
×
62
      network: this.network,
63
      logger: this.logger,
64
      node: this,
65
      prefix: this.config.prefix,
66
      ssl: this.config.bool('ssl'),
67
      keyFile: this.config.path('ssl-key'),
68
      certFile: this.config.path('ssl-cert'),
69
      host: this.config.str('http-host'),
70
      port: this.config.uint('http-port'),
71
      apiKey: this.config.str('api-key'),
72
      walletAuth: this.config.bool('wallet-auth'),
73
      noAuth: this.config.bool('no-auth'),
74
      cors: this.config.bool('cors'),
75
      adminToken: this.config.str('admin-token')
76
    });
77

78
    this.init();
×
79
  }
80

81
  /**
82
   * Initialize the node.
83
   * @private
84
   */
85

86
  init() {
87
    this.wdb.on('error', err => this.error(err));
×
88
    this.http.on('error', err => this.error(err));
×
89

90
    this.loadPlugins();
×
91
  }
92

93
  /**
94
   * Open the node and all its child objects,
95
   * wait for the database to load.
96
   * @returns {Promise}
97
   */
98

99
  async open() {
100
    assert(!this.opened, 'WalletNode is already open.');
×
101
    this.opened = true;
×
102

103
    await this.handlePreopen();
×
104
    await this.wdb.open();
×
105

106
    this.rpc.wallet = this.wdb.primary;
×
107

108
    await this.openPlugins();
×
109

110
    await this.http.open();
×
111
    await this.wdb.connect();
×
112
    await this.handleOpen();
×
113

114
    this.logger.info('Wallet node is loaded.');
×
115
  }
116

117
  /**
118
   * Close the node, wait for the database to close.
119
   * @returns {Promise}
120
   */
121

122
  async close() {
123
    assert(this.opened, 'WalletNode is not open.');
×
124
    this.opened = false;
×
125

126
    await this.handlePreclose();
×
127
    await this.http.close();
×
128

129
    await this.closePlugins();
×
130

131
    this.rpc.wallet = null;
×
132

133
    await this.wdb.disconnect();
×
134
    await this.wdb.close();
×
135
    await this.handleClose();
×
136
  }
137
}
138

139
/*
140
 * Expose
141
 */
142

143
module.exports = WalletNode;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc