@@ -22,6 +22,35 @@ export class TransactionGraph {
|
||||
this.transactions.delete(txHash);
|
||||
}
|
||||
|
||||
removeDependentTransactions(txHash: string): string[] {
|
||||
const removedTxids: string[] = [];
|
||||
const toRemove: Set<string> = new Set([txHash]);
|
||||
|
||||
const findDependents = (id: string) => {
|
||||
for (const [otherTxid, tx] of this.transactions) {
|
||||
if (
|
||||
tx
|
||||
.getInputs()
|
||||
.some((input) => binToHex(input.outpointTransactionHash) === id)
|
||||
) {
|
||||
toRemove.add(otherTxid);
|
||||
findDependents(otherTxid);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
findDependents(txHash);
|
||||
|
||||
for (const id of toRemove) {
|
||||
if (this.transactions.has(id)) {
|
||||
this.transactions.delete(id);
|
||||
removedTxids.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
return removedTxids;
|
||||
}
|
||||
|
||||
getTransaction(txHash: string): Transaction | undefined {
|
||||
return this.transactions.get(txHash);
|
||||
}
|
||||
@@ -122,4 +151,10 @@ export class TransactionGraph {
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
getNextTransactionToBroadcast(): Transaction | undefined {
|
||||
// This is pretty inefficient in the sense we recompile the graph each time.
|
||||
// But I'm not sure if that would really have much real-world performance impact.
|
||||
return this.getBroadcastOrder()[0] ?? undefined;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user