Add sequence number to track-mempool subscription messages
This commit is contained in:
parent
f8d30bf528
commit
5172f032e7
@ -558,6 +558,10 @@ class WebsocketHandler {
|
|||||||
|
|
||||||
const latestTransactions = memPool.getLatestTransactions();
|
const latestTransactions = memPool.getLatestTransactions();
|
||||||
|
|
||||||
|
if (memPool.isInSync()) {
|
||||||
|
this.mempoolSequence++;
|
||||||
|
}
|
||||||
|
|
||||||
const replacedTransactions: { replaced: string, by: TransactionExtended }[] = [];
|
const replacedTransactions: { replaced: string, by: TransactionExtended }[] = [];
|
||||||
for (const tx of newTransactions) {
|
for (const tx of newTransactions) {
|
||||||
if (rbfTransactions[tx.txid]) {
|
if (rbfTransactions[tx.txid]) {
|
||||||
@ -567,12 +571,14 @@ class WebsocketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const mempoolDeltaTxids: MempoolDeltaTxids = {
|
const mempoolDeltaTxids: MempoolDeltaTxids = {
|
||||||
|
sequence: this.mempoolSequence,
|
||||||
added: newTransactions.map(tx => tx.txid),
|
added: newTransactions.map(tx => tx.txid),
|
||||||
removed: deletedTransactions.map(tx => tx.txid),
|
removed: deletedTransactions.map(tx => tx.txid),
|
||||||
mined: [],
|
mined: [],
|
||||||
replaced: replacedTransactions.map(replacement => ({ replaced: replacement.replaced, by: replacement.by.txid })),
|
replaced: replacedTransactions.map(replacement => ({ replaced: replacement.replaced, by: replacement.by.txid })),
|
||||||
};
|
};
|
||||||
const mempoolDelta: MempoolDelta = {
|
const mempoolDelta: MempoolDelta = {
|
||||||
|
sequence: this.mempoolSequence,
|
||||||
added: newTransactions,
|
added: newTransactions,
|
||||||
removed: deletedTransactions.map(tx => tx.txid),
|
removed: deletedTransactions.map(tx => tx.txid),
|
||||||
mined: [],
|
mined: [],
|
||||||
@ -638,10 +644,6 @@ class WebsocketHandler {
|
|||||||
const addressCache = this.makeAddressCache(newTransactions);
|
const addressCache = this.makeAddressCache(newTransactions);
|
||||||
const removedAddressCache = this.makeAddressCache(deletedTransactions);
|
const removedAddressCache = this.makeAddressCache(deletedTransactions);
|
||||||
|
|
||||||
if (memPool.isInSync()) {
|
|
||||||
this.mempoolSequence++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO - Fix indentation after PR is merged
|
// TODO - Fix indentation after PR is merged
|
||||||
for (const server of this.webSocketServers) {
|
for (const server of this.webSocketServers) {
|
||||||
server.clients.forEach(async (client) => {
|
server.clients.forEach(async (client) => {
|
||||||
@ -1034,6 +1036,10 @@ class WebsocketHandler {
|
|||||||
|
|
||||||
const mBlocksWithTransactions = mempoolBlocks.getMempoolBlocksWithTransactions();
|
const mBlocksWithTransactions = mempoolBlocks.getMempoolBlocksWithTransactions();
|
||||||
|
|
||||||
|
if (memPool.isInSync()) {
|
||||||
|
this.mempoolSequence++;
|
||||||
|
}
|
||||||
|
|
||||||
const replacedTransactions: { replaced: string, by: TransactionExtended }[] = [];
|
const replacedTransactions: { replaced: string, by: TransactionExtended }[] = [];
|
||||||
for (const txid of Object.keys(rbfTransactions)) {
|
for (const txid of Object.keys(rbfTransactions)) {
|
||||||
for (const replaced of rbfTransactions[txid].replaced) {
|
for (const replaced of rbfTransactions[txid].replaced) {
|
||||||
@ -1041,12 +1047,14 @@ class WebsocketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const mempoolDeltaTxids: MempoolDeltaTxids = {
|
const mempoolDeltaTxids: MempoolDeltaTxids = {
|
||||||
|
sequence: this.mempoolSequence,
|
||||||
added: [],
|
added: [],
|
||||||
removed: [],
|
removed: [],
|
||||||
mined: transactions.map(tx => tx.txid),
|
mined: transactions.map(tx => tx.txid),
|
||||||
replaced: replacedTransactions.map(replacement => ({ replaced: replacement.replaced, by: replacement.by.txid })),
|
replaced: replacedTransactions.map(replacement => ({ replaced: replacement.replaced, by: replacement.by.txid })),
|
||||||
};
|
};
|
||||||
const mempoolDelta: MempoolDelta = {
|
const mempoolDelta: MempoolDelta = {
|
||||||
|
sequence: this.mempoolSequence,
|
||||||
added: [],
|
added: [],
|
||||||
removed: [],
|
removed: [],
|
||||||
mined: transactions.map(tx => tx.txid),
|
mined: transactions.map(tx => tx.txid),
|
||||||
@ -1061,10 +1069,6 @@ class WebsocketHandler {
|
|||||||
return responseCache[key];
|
return responseCache[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memPool.isInSync()) {
|
|
||||||
this.mempoolSequence++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO - Fix indentation after PR is merged
|
// TODO - Fix indentation after PR is merged
|
||||||
for (const server of this.webSocketServers) {
|
for (const server of this.webSocketServers) {
|
||||||
server.clients.forEach((client) => {
|
server.clients.forEach((client) => {
|
||||||
|
@ -72,6 +72,7 @@ export interface MempoolBlockDelta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface MempoolDeltaTxids {
|
export interface MempoolDeltaTxids {
|
||||||
|
sequence: number,
|
||||||
added: string[];
|
added: string[];
|
||||||
removed: string[];
|
removed: string[];
|
||||||
mined: string[];
|
mined: string[];
|
||||||
@ -79,6 +80,7 @@ export interface MempoolDeltaTxids {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface MempoolDelta {
|
export interface MempoolDelta {
|
||||||
|
sequence: number,
|
||||||
added: MempoolTransactionExtended[];
|
added: MempoolTransactionExtended[];
|
||||||
removed: string[];
|
removed: string[];
|
||||||
mined: string[];
|
mined: string[];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user