Skip to content

Instantly share code, notes, and snippets.

@slaykovsky
Created April 4, 2018 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slaykovsky/afbf45529cb4f923afafe7d054e1db5f to your computer and use it in GitHub Desktop.
Save slaykovsky/afbf45529cb4f923afafe7d054e1db5f to your computer and use it in GitHub Desktop.
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