use of org.thoughtcrime.securesms.payments.ReconstructedPayment in project Signal-Android by WhisperSystems.
the class LedgerReconcile method reconcile.
@WorkerThread
@NonNull
private static List<Payment> reconcile(@NonNull Collection<? extends Payment> allLocalPaymentTransactions, @NonNull List<MobileCoinLedgerWrapper.OwnedTxo> allTxOuts) {
List<? extends Payment> nonFailedLocalPayments = Stream.of(allLocalPaymentTransactions).filter(i -> i.getState() != State.FAILED).toList();
Set<ByteString> allKnownPublicKeys = new HashSet<>(nonFailedLocalPayments.size());
Set<ByteString> allKnownKeyImages = new HashSet<>(nonFailedLocalPayments.size());
for (Payment paymentTransaction : nonFailedLocalPayments) {
PaymentMetaData.MobileCoinTxoIdentification txoIdentification = paymentTransaction.getPaymentMetaData().getMobileCoinTxoIdentification();
allKnownPublicKeys.addAll(txoIdentification.getPublicKeyList());
allKnownKeyImages.addAll(txoIdentification.getKeyImagesList());
}
Set<MobileCoinLedgerWrapper.OwnedTxo> knownTxosByKeyImage = Stream.of(allTxOuts).filter(t -> allKnownKeyImages.contains(t.getKeyImage())).collect(Collectors.toSet());
Set<MobileCoinLedgerWrapper.OwnedTxo> knownTxosByPublicKeys = Stream.of(allTxOuts).filter(t -> allKnownPublicKeys.contains(t.getPublicKey())).collect(Collectors.toSet());
// any TXO that we can't pair up the pub key for, we don't have detail for how it got into the account
Set<MobileCoinLedgerWrapper.OwnedTxo> unknownTxOutsReceived = new HashSet<>(allTxOuts);
unknownTxOutsReceived.removeAll(knownTxosByPublicKeys);
// any TXO that we can't pair up the keyimage for, we don't have detail for how it got spent
Set<MobileCoinLedgerWrapper.OwnedTxo> unknownTxOutsSpent = Stream.of(allTxOuts).filter(MobileCoinLedgerWrapper.OwnedTxo::isSpent).collect(Collectors.toSet());
unknownTxOutsSpent.removeAll(knownTxosByKeyImage);
if (unknownTxOutsReceived.isEmpty() && unknownTxOutsSpent.isEmpty()) {
return Stream.of(allLocalPaymentTransactions).map(t -> (Payment) t).toList();
}
List<DetailedTransaction> detailedTransactions = reconstructAllTransactions(unknownTxOutsReceived, unknownTxOutsSpent);
List<Payment> reconstructedPayments = new ArrayList<>(detailedTransactions.size());
List<Payment> blockDecoratedLocalPayments = decoratePaymentsWithBlockIndexes(allLocalPaymentTransactions, allTxOuts);
for (DetailedTransaction detailedTransaction : detailedTransactions) {
reconstructedPayments.add(new ReconstructedPayment(detailedTransaction.blockDetail.getBlockIndex(), detailedTransaction.blockDetail.getBlockTimestampOrZero(), detailedTransaction.transaction.getDirection(), detailedTransaction.transaction.getValue()));
}
Collections.sort(reconstructedPayments, Payment.DESCENDING_BLOCK_INDEX);
return ZipList.zipList(blockDecoratedLocalPayments, reconstructedPayments, Payment.DESCENDING_BLOCK_INDEX_UNKNOWN_FIRST);
}
use of org.thoughtcrime.securesms.payments.ReconstructedPayment in project Signal-Android by signalapp.
the class LedgerReconcile method reconcile.
@WorkerThread
@NonNull
private static List<Payment> reconcile(@NonNull Collection<? extends Payment> allLocalPaymentTransactions, @NonNull List<MobileCoinLedgerWrapper.OwnedTxo> allTxOuts) {
List<? extends Payment> nonFailedLocalPayments = Stream.of(allLocalPaymentTransactions).filter(i -> i.getState() != State.FAILED).toList();
Set<ByteString> allKnownPublicKeys = new HashSet<>(nonFailedLocalPayments.size());
Set<ByteString> allKnownKeyImages = new HashSet<>(nonFailedLocalPayments.size());
for (Payment paymentTransaction : nonFailedLocalPayments) {
PaymentMetaData.MobileCoinTxoIdentification txoIdentification = paymentTransaction.getPaymentMetaData().getMobileCoinTxoIdentification();
allKnownPublicKeys.addAll(txoIdentification.getPublicKeyList());
allKnownKeyImages.addAll(txoIdentification.getKeyImagesList());
}
Set<MobileCoinLedgerWrapper.OwnedTxo> knownTxosByKeyImage = Stream.of(allTxOuts).filter(t -> allKnownKeyImages.contains(t.getKeyImage())).collect(Collectors.toSet());
Set<MobileCoinLedgerWrapper.OwnedTxo> knownTxosByPublicKeys = Stream.of(allTxOuts).filter(t -> allKnownPublicKeys.contains(t.getPublicKey())).collect(Collectors.toSet());
// any TXO that we can't pair up the pub key for, we don't have detail for how it got into the account
Set<MobileCoinLedgerWrapper.OwnedTxo> unknownTxOutsReceived = new HashSet<>(allTxOuts);
unknownTxOutsReceived.removeAll(knownTxosByPublicKeys);
// any TXO that we can't pair up the keyimage for, we don't have detail for how it got spent
Set<MobileCoinLedgerWrapper.OwnedTxo> unknownTxOutsSpent = Stream.of(allTxOuts).filter(MobileCoinLedgerWrapper.OwnedTxo::isSpent).collect(Collectors.toSet());
unknownTxOutsSpent.removeAll(knownTxosByKeyImage);
if (unknownTxOutsReceived.isEmpty() && unknownTxOutsSpent.isEmpty()) {
return Stream.of(allLocalPaymentTransactions).map(t -> (Payment) t).toList();
}
List<DetailedTransaction> detailedTransactions = reconstructAllTransactions(unknownTxOutsReceived, unknownTxOutsSpent);
List<Payment> reconstructedPayments = new ArrayList<>(detailedTransactions.size());
List<Payment> blockDecoratedLocalPayments = decoratePaymentsWithBlockIndexes(allLocalPaymentTransactions, allTxOuts);
for (DetailedTransaction detailedTransaction : detailedTransactions) {
reconstructedPayments.add(new ReconstructedPayment(detailedTransaction.blockDetail.getBlockIndex(), detailedTransaction.blockDetail.getBlockTimestampOrZero(), detailedTransaction.transaction.getDirection(), detailedTransaction.transaction.getValue()));
}
Collections.sort(reconstructedPayments, Payment.DESCENDING_BLOCK_INDEX);
return ZipList.zipList(blockDecoratedLocalPayments, reconstructedPayments, Payment.DESCENDING_BLOCK_INDEX_UNKNOWN_FIRST);
}
Aggregations