Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public Transaction[] handleTxs(Transaction[] possibleTxs) {
Set<Transaction> sortedTxs = new TreeSet<>(
(x, y) -> Double.compare(this.makeTxFees(y), this.makeTxFees(x)));
Collections.addAll(sortedTxs, possibleTxs);
Set<Transaction> validTxs = new HashSet<>();
sortedTxs.parallelStream().filter(this::isValidTx).map(tx -> {
validTxs.add(tx);
tx.getInputs().parallelStream().map(in -> {
UTXO utxo = new UTXO(in.prevTxHash, in.outputIndex);
this.utxoPool.removeUTXO(utxo);
return null;
});
IntStream.range(0, tx.numInputs()).map(i -> {
Transaction.Output output = tx.getOutput(i);
UTXO utxo = new UTXO(tx.getHash(), i);
this.utxoPool.addUTXO(utxo, output);
return 0;
});
return null;
});
Transaction[] validTxsArray = new Transaction[validTxs.size()];
return validTxs.toArray(validTxsArray);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.