use of org.thoughtcrime.securesms.payments.history.TransactionReconstruction in project Signal-Android by WhisperSystems.
the class LedgerReconcile method reconstructAllTransactions.
@NonNull
private static List<DetailedTransaction> reconstructAllTransactions(@NonNull Set<MobileCoinLedgerWrapper.OwnedTxo> unknownReceived, @NonNull Set<MobileCoinLedgerWrapper.OwnedTxo> unknownSpent) {
Set<Long> allBlocksWithActivity = Stream.of(unknownReceived).map(MobileCoinLedgerWrapper.OwnedTxo::getReceivedInBlock).collect(Collectors.toSet());
allBlocksWithActivity.addAll(Stream.of(unknownSpent).map(MobileCoinLedgerWrapper.OwnedTxo::getSpentInBlock).collect(Collectors.toSet()));
Map<Long, List<MobileCoinLedgerWrapper.OwnedTxo>> receivedInBlock = Stream.of(unknownReceived).collect(Collectors.groupingBy(MobileCoinLedgerWrapper.OwnedTxo::getReceivedInBlock));
Map<Long, List<MobileCoinLedgerWrapper.OwnedTxo>> spentInBlock = Stream.of(unknownSpent).filter(MobileCoinLedgerWrapper.OwnedTxo::isSpent).collect(Collectors.groupingBy(MobileCoinLedgerWrapper.OwnedTxo::getSpentInBlock));
return Stream.of(allBlocksWithActivity).sorted((a, b) -> b.compareTo(a)).flatMap(blockIndex -> {
List<MobileCoinLedgerWrapper.OwnedTxo> unspent = MapUtil.getOrDefault(receivedInBlock, blockIndex, Collections.emptyList());
List<MobileCoinLedgerWrapper.OwnedTxo> spent = MapUtil.getOrDefault(spentInBlock, blockIndex, Collections.emptyList());
if (spent.size() + unspent.size() == 0) {
throw new AssertionError();
}
Long timeStamp = null;
if (spent.size() > 0) {
timeStamp = spent.get(0).getSpentInBlockTimestamp();
}
if (timeStamp == null && unspent.size() > 0) {
timeStamp = unspent.get(0).getReceivedInBlockTimestamp();
}
TransactionReconstruction transactionReconstruction = TransactionReconstruction.estimateBlockLevelActivity(toMobileCoinList(spent), toMobileCoinList(unspent));
BlockDetail blockDetail = new BlockDetail(blockIndex, timeStamp);
return Stream.of(transactionReconstruction.getAllTransactions()).map(t -> new DetailedTransaction(blockDetail, t));
}).sorted(DetailedTransaction.DESCENDING).toList();
}
use of org.thoughtcrime.securesms.payments.history.TransactionReconstruction in project Signal-Android by signalapp.
the class LedgerReconcile method reconstructAllTransactions.
@NonNull
private static List<DetailedTransaction> reconstructAllTransactions(@NonNull Set<MobileCoinLedgerWrapper.OwnedTxo> unknownReceived, @NonNull Set<MobileCoinLedgerWrapper.OwnedTxo> unknownSpent) {
Set<Long> allBlocksWithActivity = Stream.of(unknownReceived).map(MobileCoinLedgerWrapper.OwnedTxo::getReceivedInBlock).collect(Collectors.toSet());
allBlocksWithActivity.addAll(Stream.of(unknownSpent).map(MobileCoinLedgerWrapper.OwnedTxo::getSpentInBlock).collect(Collectors.toSet()));
Map<Long, List<MobileCoinLedgerWrapper.OwnedTxo>> receivedInBlock = Stream.of(unknownReceived).collect(Collectors.groupingBy(MobileCoinLedgerWrapper.OwnedTxo::getReceivedInBlock));
Map<Long, List<MobileCoinLedgerWrapper.OwnedTxo>> spentInBlock = Stream.of(unknownSpent).filter(MobileCoinLedgerWrapper.OwnedTxo::isSpent).collect(Collectors.groupingBy(MobileCoinLedgerWrapper.OwnedTxo::getSpentInBlock));
return Stream.of(allBlocksWithActivity).sorted((a, b) -> b.compareTo(a)).flatMap(blockIndex -> {
List<MobileCoinLedgerWrapper.OwnedTxo> unspent = MapUtil.getOrDefault(receivedInBlock, blockIndex, Collections.emptyList());
List<MobileCoinLedgerWrapper.OwnedTxo> spent = MapUtil.getOrDefault(spentInBlock, blockIndex, Collections.emptyList());
if (spent.size() + unspent.size() == 0) {
throw new AssertionError();
}
Long timeStamp = null;
if (spent.size() > 0) {
timeStamp = spent.get(0).getSpentInBlockTimestamp();
}
if (timeStamp == null && unspent.size() > 0) {
timeStamp = unspent.get(0).getReceivedInBlockTimestamp();
}
TransactionReconstruction transactionReconstruction = TransactionReconstruction.estimateBlockLevelActivity(toMobileCoinList(spent), toMobileCoinList(unspent));
BlockDetail blockDetail = new BlockDetail(blockIndex, timeStamp);
return Stream.of(transactionReconstruction.getAllTransactions()).map(t -> new DetailedTransaction(blockDetail, t));
}).sorted(DetailedTransaction.DESCENDING).toList();
}
Aggregations