use of org.thoughtcrime.securesms.database.PaymentDatabase in project Signal-Android by WhisperSystems.
the class PaymentNotificationSendJob method onRun.
@Override
protected void onRun() throws Exception {
if (!Recipient.self().isRegistered()) {
throw new NotPushRegisteredException();
}
PaymentDatabase paymentDatabase = SignalDatabase.payments();
Recipient recipient = Recipient.resolved(recipientId);
if (recipient.isUnregistered()) {
Log.w(TAG, recipientId + " not registered!");
return;
}
SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
SignalServiceAddress address = RecipientUtil.toSignalServiceAddress(context, recipient);
Optional<UnidentifiedAccessPair> unidentifiedAccess = UnidentifiedAccessUtil.getAccessFor(context, recipient);
PaymentDatabase.PaymentTransaction payment = paymentDatabase.getPayment(uuid);
if (payment == null) {
Log.w(TAG, "Could not find payment, cannot send notification " + uuid);
return;
}
if (payment.getReceipt() == null) {
Log.w(TAG, "Could not find payment receipt, cannot send notification " + uuid);
return;
}
SignalServiceDataMessage dataMessage = SignalServiceDataMessage.newBuilder().withPayment(new SignalServiceDataMessage.Payment(new SignalServiceDataMessage.PaymentNotification(payment.getReceipt(), payment.getNote()))).build();
SendMessageResult sendMessageResult = messageSender.sendDataMessage(address, unidentifiedAccess, ContentHint.DEFAULT, dataMessage, IndividualSendEvents.EMPTY);
if (sendMessageResult.getIdentityFailure() != null) {
Log.w(TAG, "Identity failure for " + recipient.getId());
} else if (sendMessageResult.isUnregisteredFailure()) {
Log.w(TAG, "Unregistered failure for " + recipient.getId());
} else if (sendMessageResult.getSuccess() == null) {
throw new RetryLaterException();
} else {
Log.i(TAG, String.format("Payment notification sent to %s for %s", recipientId, uuid));
}
}
use of org.thoughtcrime.securesms.database.PaymentDatabase in project Signal-Android by WhisperSystems.
the class PaymentTransactionCheckJob method onRun.
@Override
protected void onRun() throws Exception {
PaymentDatabase paymentDatabase = SignalDatabase.payments();
PaymentDatabase.PaymentTransaction payment = paymentDatabase.getPayment(uuid);
if (payment == null) {
Log.w(TAG, "No payment found for UUID " + uuid);
return;
}
Payments payments = ApplicationDependencies.getPayments();
switch(payment.getDirection()) {
case SENT:
{
Log.i(TAG, "Checking sent status of " + uuid);
PaymentTransactionId paymentTransactionId = new PaymentTransactionId.MobileCoin(Objects.requireNonNull(payment.getTransaction()), Objects.requireNonNull(payment.getReceipt()), payment.getFee().requireMobileCoin());
Wallet.TransactionStatusResult status = payments.getWallet().getSentTransactionStatus(paymentTransactionId);
switch(status.getTransactionStatus()) {
case COMPLETE:
paymentDatabase.markPaymentSuccessful(uuid, status.getBlockIndex());
Log.i(TAG, "Marked sent payment successful " + uuid);
break;
case FAILED:
paymentDatabase.markPaymentFailed(uuid, FailureReason.UNKNOWN);
Log.i(TAG, "Marked sent payment failed " + uuid);
break;
case IN_PROGRESS:
Log.i(TAG, "Sent payment still in progress " + uuid);
throw new IncompleteTransactionException();
default:
throw new AssertionError();
}
break;
}
case RECEIVED:
{
Log.i(TAG, "Checking received status of " + uuid);
Wallet.ReceivedTransactionStatus transactionStatus = payments.getWallet().getReceivedTransactionStatus(Objects.requireNonNull(payment.getReceipt()));
switch(transactionStatus.getStatus()) {
case COMPLETE:
paymentDatabase.markReceivedPaymentSuccessful(uuid, transactionStatus.getAmount(), transactionStatus.getBlockIndex());
Log.i(TAG, "Marked received payment successful " + uuid);
break;
case FAILED:
paymentDatabase.markPaymentFailed(uuid, FailureReason.UNKNOWN);
Log.i(TAG, "Marked received payment failed " + uuid);
break;
case IN_PROGRESS:
Log.i(TAG, "Received payment still in progress " + uuid);
throw new IncompleteTransactionException();
default:
throw new AssertionError();
}
break;
}
default:
{
throw new AssertionError();
}
}
}
use of org.thoughtcrime.securesms.database.PaymentDatabase in project Signal-Android by WhisperSystems.
the class MessageContentProcessor method handlePayment.
private void handlePayment(@NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message, @NonNull Recipient senderRecipient) {
log(content.getTimestamp(), "Payment message.");
if (!message.getPayment().isPresent()) {
throw new AssertionError();
}
if (!message.getPayment().get().getPaymentNotification().isPresent()) {
warn(content.getTimestamp(), "Ignoring payment message without notification");
return;
}
SignalServiceDataMessage.PaymentNotification paymentNotification = message.getPayment().get().getPaymentNotification().get();
PaymentDatabase paymentDatabase = SignalDatabase.payments();
UUID uuid = UUID.randomUUID();
String queue = "Payment_" + PushProcessMessageJob.getQueueName(senderRecipient.getId());
try {
paymentDatabase.createIncomingPayment(uuid, senderRecipient.getId(), message.getTimestamp(), paymentNotification.getNote(), Money.MobileCoin.ZERO, Money.MobileCoin.ZERO, paymentNotification.getReceipt());
} catch (PaymentDatabase.PublicKeyConflictException e) {
warn(content.getTimestamp(), "Ignoring payment with public key already in database");
return;
} catch (SerializationException e) {
warn(content.getTimestamp(), "Ignoring payment with bad data.", e);
}
ApplicationDependencies.getJobManager().startChain(new PaymentTransactionCheckJob(uuid, queue)).then(PaymentLedgerUpdateJob.updateLedger()).enqueue();
}
use of org.thoughtcrime.securesms.database.PaymentDatabase in project Signal-Android by signalapp.
the class PaymentNotificationSendJob method onRun.
@Override
protected void onRun() throws Exception {
if (!Recipient.self().isRegistered()) {
throw new NotPushRegisteredException();
}
PaymentDatabase paymentDatabase = SignalDatabase.payments();
Recipient recipient = Recipient.resolved(recipientId);
if (recipient.isUnregistered()) {
Log.w(TAG, recipientId + " not registered!");
return;
}
SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
SignalServiceAddress address = RecipientUtil.toSignalServiceAddress(context, recipient);
Optional<UnidentifiedAccessPair> unidentifiedAccess = UnidentifiedAccessUtil.getAccessFor(context, recipient);
PaymentDatabase.PaymentTransaction payment = paymentDatabase.getPayment(uuid);
if (payment == null) {
Log.w(TAG, "Could not find payment, cannot send notification " + uuid);
return;
}
if (payment.getReceipt() == null) {
Log.w(TAG, "Could not find payment receipt, cannot send notification " + uuid);
return;
}
SignalServiceDataMessage dataMessage = SignalServiceDataMessage.newBuilder().withPayment(new SignalServiceDataMessage.Payment(new SignalServiceDataMessage.PaymentNotification(payment.getReceipt(), payment.getNote()))).build();
SendMessageResult sendMessageResult = messageSender.sendDataMessage(address, unidentifiedAccess, ContentHint.DEFAULT, dataMessage, IndividualSendEvents.EMPTY);
if (sendMessageResult.getIdentityFailure() != null) {
Log.w(TAG, "Identity failure for " + recipient.getId());
} else if (sendMessageResult.isUnregisteredFailure()) {
Log.w(TAG, "Unregistered failure for " + recipient.getId());
} else if (sendMessageResult.getSuccess() == null) {
throw new RetryLaterException();
} else {
Log.i(TAG, String.format("Payment notification sent to %s for %s", recipientId, uuid));
}
}
use of org.thoughtcrime.securesms.database.PaymentDatabase in project Signal-Android by signalapp.
the class PaymentTransactionCheckJob method onRun.
@Override
protected void onRun() throws Exception {
PaymentDatabase paymentDatabase = SignalDatabase.payments();
PaymentDatabase.PaymentTransaction payment = paymentDatabase.getPayment(uuid);
if (payment == null) {
Log.w(TAG, "No payment found for UUID " + uuid);
return;
}
Payments payments = ApplicationDependencies.getPayments();
switch(payment.getDirection()) {
case SENT:
{
Log.i(TAG, "Checking sent status of " + uuid);
PaymentTransactionId paymentTransactionId = new PaymentTransactionId.MobileCoin(Objects.requireNonNull(payment.getTransaction()), Objects.requireNonNull(payment.getReceipt()), payment.getFee().requireMobileCoin());
Wallet.TransactionStatusResult status = payments.getWallet().getSentTransactionStatus(paymentTransactionId);
switch(status.getTransactionStatus()) {
case COMPLETE:
paymentDatabase.markPaymentSuccessful(uuid, status.getBlockIndex());
Log.i(TAG, "Marked sent payment successful " + uuid);
break;
case FAILED:
paymentDatabase.markPaymentFailed(uuid, FailureReason.UNKNOWN);
Log.i(TAG, "Marked sent payment failed " + uuid);
break;
case IN_PROGRESS:
Log.i(TAG, "Sent payment still in progress " + uuid);
throw new IncompleteTransactionException();
default:
throw new AssertionError();
}
break;
}
case RECEIVED:
{
Log.i(TAG, "Checking received status of " + uuid);
Wallet.ReceivedTransactionStatus transactionStatus = payments.getWallet().getReceivedTransactionStatus(Objects.requireNonNull(payment.getReceipt()));
switch(transactionStatus.getStatus()) {
case COMPLETE:
paymentDatabase.markReceivedPaymentSuccessful(uuid, transactionStatus.getAmount(), transactionStatus.getBlockIndex());
Log.i(TAG, "Marked received payment successful " + uuid);
break;
case FAILED:
paymentDatabase.markPaymentFailed(uuid, FailureReason.UNKNOWN);
Log.i(TAG, "Marked received payment failed " + uuid);
break;
case IN_PROGRESS:
Log.i(TAG, "Received payment still in progress " + uuid);
throw new IncompleteTransactionException();
default:
throw new AssertionError();
}
break;
}
default:
{
throw new AssertionError();
}
}
}
Aggregations