Resume tx tracking when network goes offline. (#702)

fixes #609
This commit is contained in:
softsimon 2021-08-09 13:01:29 +03:00 committed by GitHub
parent 8208bbf0b7
commit 8c29395533
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View File

@ -53,18 +53,25 @@ class WebsocketHandler {
if (parsedMessage['watch-mempool']) {
const tx = memPool.getMempool()[client['track-tx']];
if (tx) {
if (config.MEMPOOL.BACKEND !== 'esplora') {
if (config.MEMPOOL.BACKEND === 'esplora') {
response['tx'] = tx;
} else {
// tx.prevouts is missing from transactions when in bitcoind mode
try {
const fullTx = await transactionUtils.$getTransactionExtended(tx.txid, true);
response['tx'] = fullTx;
} catch (e) {
logger.debug('Error finding transaction in mempool: ' + e.message || e);
logger.debug('Error finding transaction: ' + e.message || e);
}
} else {
response['tx'] = tx;
}
} else {
client['track-mempool-tx'] = parsedMessage['track-tx'];
try {
const fullTx = await transactionUtils.$getTransactionExtended(client['track-tx'], true);
response['tx'] = fullTx;
} catch (e) {
logger.debug('Error finding transaction. ' + e.message || e);
client['track-mempool-tx'] = parsedMessage['track-tx'];
}
}
}
} else {

View File

@ -25,6 +25,7 @@ export class WebsocketService {
private goneOffline = false;
private lastWant: string | null = null;
private isTrackingTx = false;
private trackingTxId: string;
private latestGitCommit = '';
private onlineCheckTimeout: number;
private onlineCheckTimeoutTwo: number;
@ -97,6 +98,9 @@ export class WebsocketService {
if (this.lastWant) {
this.want(JSON.parse(this.lastWant), true);
}
if (this.isTrackingTx) {
this.startMultiTrackTransaction(this.trackingTxId);
}
this.stateService.connectionState$.next(2);
}
@ -119,11 +123,13 @@ export class WebsocketService {
}
this.websocketSubject.next({ 'track-tx': txId });
this.isTrackingTx = true;
this.trackingTxId = txId;
}
startMultiTrackTransaction(txId: string) {
this.websocketSubject.next({ 'track-tx': txId, 'watch-mempool': true });
this.isTrackingTx = true;
this.trackingTxId = txId;
}
stopTrackingTransaction() {