use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class PaymentDatabase method markPaymentSeen.
@WorkerThread
public void markPaymentSeen(@NonNull UUID uuid) {
SQLiteDatabase database = databaseHelper.getSignalWritableDatabase();
ContentValues values = new ContentValues(1);
String where = PAYMENT_UUID + " = ?";
String[] args = { uuid.toString() };
values.put(SEEN, 1);
int updated = database.update(TABLE_NAME, values, where, args);
if (updated > 0) {
notifyChanged(uuid);
}
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class PaymentDatabase method getUnseenPayments.
@WorkerThread
@NonNull
public List<PaymentTransaction> getUnseenPayments() {
SQLiteDatabase db = databaseHelper.getSignalReadableDatabase();
String query = SEEN + " = 0 AND " + STATE + " = " + State.SUCCESSFUL.serialize();
List<PaymentTransaction> results = new LinkedList<>();
try (Cursor cursor = db.query(TABLE_NAME, null, query, null, null, null, null)) {
while (cursor.moveToNext()) {
results.add(readPayment(cursor));
}
}
return results;
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class PaymentDatabase method markAllSeen.
@WorkerThread
public void markAllSeen() {
SQLiteDatabase database = databaseHelper.getSignalWritableDatabase();
ContentValues values = new ContentValues(1);
List<UUID> unseenIds = new LinkedList<>();
String[] unseenProjection = SqlUtil.buildArgs(PAYMENT_UUID);
String unseenWhile = SEEN + " != ?";
String[] unseenArgs = SqlUtil.buildArgs("1");
int updated = -1;
values.put(SEEN, 1);
try {
database.beginTransaction();
try (Cursor cursor = database.query(TABLE_NAME, unseenProjection, unseenWhile, unseenArgs, null, null, null)) {
while (cursor != null && cursor.moveToNext()) {
unseenIds.add(UUID.fromString(CursorUtil.requireString(cursor, PAYMENT_UUID)));
}
}
if (!unseenIds.isEmpty()) {
updated = database.update(TABLE_NAME, values, null, null);
}
database.setTransactionSuccessful();
} finally {
database.endTransaction();
}
if (updated > 0) {
for (final UUID unseenId : unseenIds) {
notifyUuidChanged(unseenId);
}
notifyChanged();
}
}
use of androidx.annotation.WorkerThread in project Signal-Android by WhisperSystems.
the class PaymentDatabase method getAll.
@WorkerThread
@NonNull
public List<PaymentTransaction> getAll() {
SQLiteDatabase database = databaseHelper.getSignalReadableDatabase();
List<PaymentTransaction> result = new LinkedList<>();
try (Cursor cursor = database.query(TABLE_NAME, null, null, null, null, null, TIMESTAMP + " DESC")) {
while (cursor.moveToNext()) {
result.add(readPayment(cursor));
}
}
return result;
}
use of androidx.annotation.WorkerThread 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);
}
Aggregations