Skip to content

Commit

Permalink
wdb: add events for open/close and connect/disconnect.
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Oct 20, 2023
1 parent 7bd2078 commit f11615d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ you run it for the first time.**
### Wallet Changes:

- Add migration that recalculates txdb balances to fix any inconsistencies.
- WalletDB Now emits events for: `open`, `close`, `connect`, `disconnect`.
- HTTP Changes:
- All transaction creating endpoints now accept `hardFee` for specifying the
exact fee.
Expand Down
9 changes: 8 additions & 1 deletion lib/wallet/walletdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class WalletDB extends EventEmitter {
});

this.client.on('connect', async () => {
this.emit('connect');
try {
await this.syncNode();
this.emit('sync done', this.state);
Expand All @@ -131,6 +132,7 @@ class WalletDB extends EventEmitter {
});

this.client.on('disconnect', async () => {
this.emit('disconnect');
this.filterSent = false;
});

Expand Down Expand Up @@ -225,6 +227,9 @@ class WalletDB extends EventEmitter {
this.logger.info('Rescanning...');
await this.scan(0);
}

this.logger.info('WalletDB opened.');
this.emit('open');
}

/**
Expand Down Expand Up @@ -277,7 +282,9 @@ class WalletDB extends EventEmitter {
this.unregister(wallet);
}

return this.db.close();
await this.db.close();
this.logger.info('WalletDB Closed.');
this.emit('close');
}

/**
Expand Down

0 comments on commit f11615d

Please sign in to comment.