Signed-off-by: James Zuccon <zuccon@gmail.com>
This commit is contained in:
James Zuccon
2024-09-06 15:54:50 +10:00
parent 9aa43d6e97
commit f66de86eb3
18 changed files with 149 additions and 37 deletions
+1 -1
View File
@@ -10,7 +10,7 @@
"dist"
],
"scripts": {
"build": "tsc --build --clean",
"build": "tsc --build --clean && tsc --build",
"prepublishOnly": "npm run build"
},
"author": "",
@@ -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;
}
}