Created
April 4, 2018 20:09
-
-
Save slaykovsky/afbf45529cb4f923afafe7d054e1db5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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