Skip to content

Commit 1a10869

Browse files
committed
Split the progress callback into sync_progress and scan_progress
1 parent 5e7aab1 commit 1a10869

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Unreleased
2+
3+
- Split the `progress` callback into `sync_progress` and `scan_progress`
4+
15
## 0.2.1 - 2021-01-14
26

37
Migrated from [`bwt-dev/bwt`](https://github.com/bwt-dev/bwt) into a standalone repo

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ const bwtd = await BwtDaemon({
7373
// Set the gap limit of watched unused addresses
7474
gap_limit: 100,
7575

76-
// Progress notifications for history scanning (a full rescan from genesis can take 20-30 minutes)
77-
progress: (type, progress, detail) => console.log('bwt %s progress %f%%', type, progress*100, detail),
76+
// Progress notifications for initial block download and wallet rescanning
77+
sync_progress: (progress, tip_time) =>
78+
console.log(`Initial block download in progress... (${progress*100}% done, synced up to ${tip_time})`),
79+
scan_progress: (progress, eta) =>
80+
console.log(`Wallet rescanning in progress... (${progress*100} done, ETA ${eta} seconds)`),
81+
}
7882
}).start()
7983

8084
// Get the assigned address/port for the Electrum/HTTP servers
@@ -90,7 +94,8 @@ See [`example.js`](example.js) for a more complete example, including connecting
9094
The list of options is available in the [libbwt C FFI documentation](https://github.com/bwt-dev/libbwt#config-options).
9195
The nodejs wrapper also provides the following additional options:
9296

93-
- `progress` - callback for progress update notifications, invoked with `(type, progress, detail)` (optional)
97+
- `sync_progress` - callback for IBD progress notifications, invoked with `(progress, tip_time)`
98+
- `scan_progress` - callback for wallet rescan progress notifications, invoked with `(progress, eta)`
9499
- `electrum` - setting to `true` is an alias for `electrum_addr=127.0.0.1:0`
95100
- `http` - setting to `true` is an alias for `http_addr=127.0.0.1:0`
96101

index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ class BwtDaemon extends EventEmitter {
4242
constructor(options) {
4343
super()
4444

45-
if (options.progress) this.on('progress', take_prop(options, 'progress'))
45+
if (options.sync_progress) this.on('progress:sync', take_prop(options, 'sync_progress'))
46+
if (options.scan_progress) this.on('progress:scan', take_prop(options, 'scan_progress'))
47+
4648
this.options = normalize_options(options)
4749

4850
this.ready = new Promise((resolve, reject) => {
@@ -88,10 +90,11 @@ class BwtDaemon extends EventEmitter {
8890
this.emit('error', detail_s)
8991
break
9092
case 'progress:sync':
91-
this.emit('progress', 'sync', progress_n, { tip_time: detail_n })
93+
const tip_time = new Date(detail_n*1000)
94+
this.emit('progress:sync', progress_n, tip_time)
9295
break
9396
case 'progress:scan':
94-
this.emit('progress', 'scan', progress_n, { eta: detail_n })
97+
this.emit('progress:scan', progress_n, detail_n /*ETA in seconds*/)
9598
break
9699
case 'ready:http':
97100
this.http_addr = detail_s

0 commit comments

Comments
 (0)