Search in sources :

Example 6 with SerializationException

use of com.mobilecoin.lib.exceptions.SerializationException in project Signal-Android by signalapp.

the class Wallet method getReceivedTransactionStatus.

@WorkerThread
@NonNull
public ReceivedTransactionStatus getReceivedTransactionStatus(@NonNull byte[] receiptBytes) throws IOException {
    try {
        Receipt receipt = Receipt.fromBytes(receiptBytes);
        Receipt.Status status = mobileCoinClient.getReceiptStatus(receipt);
        switch(status) {
            case UNKNOWN:
                Log.w(TAG, "Unknown received Transaction Status");
                return ReceivedTransactionStatus.inProgress();
            case FAILED:
                return ReceivedTransactionStatus.failed();
            case RECEIVED:
                BigInteger amount = receipt.getAmount(account);
                return ReceivedTransactionStatus.complete(Money.picoMobileCoin(amount), status.getBlockIndex().longValue());
            default:
                throw new IllegalStateException("Unknown Transaction Status: " + status);
        }
    } catch (SerializationException | InvalidFogResponse | InvalidReceiptException e) {
        Log.w(TAG, e);
        return ReceivedTransactionStatus.failed();
    } catch (NetworkException | AttestationException e) {
        throw new IOException(e);
    } catch (AmountDecoderException e) {
        Log.w(TAG, "Failed to decode amount", e);
        return ReceivedTransactionStatus.failed();
    }
}
Also used : AmountDecoderException(com.mobilecoin.lib.exceptions.AmountDecoderException) Receipt(com.mobilecoin.lib.Receipt) SerializationException(com.mobilecoin.lib.exceptions.SerializationException) AttestationException(com.mobilecoin.lib.exceptions.AttestationException) IOException(java.io.IOException) InvalidFogResponse(com.mobilecoin.lib.exceptions.InvalidFogResponse) BigInteger(java.math.BigInteger) InvalidReceiptException(com.mobilecoin.lib.exceptions.InvalidReceiptException) NetworkException(com.mobilecoin.lib.exceptions.NetworkException) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 7 with SerializationException

use of com.mobilecoin.lib.exceptions.SerializationException in project Signal-Android by signalapp.

the class Wallet method getSentTransactionStatus.

@WorkerThread
@NonNull
public TransactionStatusResult getSentTransactionStatus(@NonNull PaymentTransactionId transactionId) throws IOException {
    try {
        PaymentTransactionId.MobileCoin mobcoinTransaction = (PaymentTransactionId.MobileCoin) transactionId;
        Transaction transaction = Transaction.fromBytes(mobcoinTransaction.getTransaction());
        Transaction.Status status = mobileCoinClient.getAccountSnapshot().getTransactionStatus(transaction);
        switch(status) {
            case UNKNOWN:
                Log.w(TAG, "Unknown sent Transaction Status");
                return TransactionStatusResult.inProgress();
            case FAILED:
                return TransactionStatusResult.failed();
            case ACCEPTED:
                return TransactionStatusResult.complete(status.getBlockIndex().longValue());
            default:
                throw new IllegalStateException("Unknown Transaction Status: " + status);
        }
    } catch (SerializationException | InvalidFogResponse e) {
        Log.w(TAG, e);
        return TransactionStatusResult.failed();
    } catch (NetworkException | AttestationException e) {
        Log.w(TAG, e);
        throw new IOException(e);
    }
}
Also used : SerializationException(com.mobilecoin.lib.exceptions.SerializationException) AttestationException(com.mobilecoin.lib.exceptions.AttestationException) IOException(java.io.IOException) InvalidFogResponse(com.mobilecoin.lib.exceptions.InvalidFogResponse) PendingTransaction(com.mobilecoin.lib.PendingTransaction) Transaction(com.mobilecoin.lib.Transaction) NetworkException(com.mobilecoin.lib.exceptions.NetworkException) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 8 with SerializationException

use of com.mobilecoin.lib.exceptions.SerializationException in project Signal-Android by signalapp.

the class MessageContentProcessor method handleSynchronizeOutgoingPayment.

private void handleSynchronizeOutgoingPayment(@NonNull SignalServiceContent content, @NonNull OutgoingPaymentMessage outgoingPaymentMessage) {
    RecipientId recipientId = outgoingPaymentMessage.getRecipient().transform(RecipientId::from).orNull();
    long timestamp = outgoingPaymentMessage.getBlockTimestamp();
    if (timestamp == 0) {
        timestamp = System.currentTimeMillis();
    }
    Optional<MobileCoinPublicAddress> address = outgoingPaymentMessage.getAddress().transform(MobileCoinPublicAddress::fromBytes);
    if (!address.isPresent() && recipientId == null) {
        log(content.getTimestamp(), "Inserting defrag");
        address = Optional.of(ApplicationDependencies.getPayments().getWallet().getMobileCoinPublicAddress());
        recipientId = Recipient.self().getId();
    }
    UUID uuid = UUID.randomUUID();
    try {
        SignalDatabase.payments().createSuccessfulPayment(uuid, recipientId, address.get(), timestamp, outgoingPaymentMessage.getBlockIndex(), outgoingPaymentMessage.getNote().or(""), outgoingPaymentMessage.getAmount(), outgoingPaymentMessage.getFee(), outgoingPaymentMessage.getReceipt().toByteArray(), PaymentMetaDataUtil.fromKeysAndImages(outgoingPaymentMessage.getPublicKeys(), outgoingPaymentMessage.getKeyImages()));
    } catch (SerializationException e) {
        warn(content.getTimestamp(), "Ignoring synchronized outgoing payment with bad data.", e);
    }
    log("Inserted synchronized payment " + uuid);
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) SerializationException(com.mobilecoin.lib.exceptions.SerializationException) UUID(java.util.UUID) MobileCoinPublicAddress(org.thoughtcrime.securesms.payments.MobileCoinPublicAddress)

Example 9 with SerializationException

use of com.mobilecoin.lib.exceptions.SerializationException in project Signal-Android by signalapp.

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();
}
Also used : SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) SerializationException(com.mobilecoin.lib.exceptions.SerializationException) PaymentDatabase(org.thoughtcrime.securesms.database.PaymentDatabase) UUID(java.util.UUID) PaymentTransactionCheckJob(org.thoughtcrime.securesms.jobs.PaymentTransactionCheckJob)

Example 10 with SerializationException

use of com.mobilecoin.lib.exceptions.SerializationException in project Signal-Android by WhisperSystems.

the class Wallet method getReceivedTransactionStatus.

@WorkerThread
@NonNull
public ReceivedTransactionStatus getReceivedTransactionStatus(@NonNull byte[] receiptBytes) throws IOException {
    try {
        Receipt receipt = Receipt.fromBytes(receiptBytes);
        Receipt.Status status = mobileCoinClient.getReceiptStatus(receipt);
        switch(status) {
            case UNKNOWN:
                Log.w(TAG, "Unknown received Transaction Status");
                return ReceivedTransactionStatus.inProgress();
            case FAILED:
                return ReceivedTransactionStatus.failed();
            case RECEIVED:
                BigInteger amount = receipt.getAmount(account);
                return ReceivedTransactionStatus.complete(Money.picoMobileCoin(amount), status.getBlockIndex().longValue());
            default:
                throw new IllegalStateException("Unknown Transaction Status: " + status);
        }
    } catch (SerializationException | InvalidFogResponse | InvalidReceiptException e) {
        Log.w(TAG, e);
        return ReceivedTransactionStatus.failed();
    } catch (NetworkException | AttestationException e) {
        throw new IOException(e);
    } catch (AmountDecoderException e) {
        Log.w(TAG, "Failed to decode amount", e);
        return ReceivedTransactionStatus.failed();
    }
}
Also used : AmountDecoderException(com.mobilecoin.lib.exceptions.AmountDecoderException) Receipt(com.mobilecoin.lib.Receipt) SerializationException(com.mobilecoin.lib.exceptions.SerializationException) AttestationException(com.mobilecoin.lib.exceptions.AttestationException) IOException(java.io.IOException) InvalidFogResponse(com.mobilecoin.lib.exceptions.InvalidFogResponse) BigInteger(java.math.BigInteger) InvalidReceiptException(com.mobilecoin.lib.exceptions.InvalidReceiptException) NetworkException(com.mobilecoin.lib.exceptions.NetworkException) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Aggregations

SerializationException (com.mobilecoin.lib.exceptions.SerializationException)12 WorkerThread (androidx.annotation.WorkerThread)6 AttestationException (com.mobilecoin.lib.exceptions.AttestationException)6 InvalidFogResponse (com.mobilecoin.lib.exceptions.InvalidFogResponse)6 NetworkException (com.mobilecoin.lib.exceptions.NetworkException)6 NonNull (androidx.annotation.NonNull)4 PendingTransaction (com.mobilecoin.lib.PendingTransaction)4 IOException (java.io.IOException)4 BigInteger (java.math.BigInteger)4 UUID (java.util.UUID)4 ContentValues (android.content.ContentValues)2 Receipt (com.mobilecoin.lib.Receipt)2 Transaction (com.mobilecoin.lib.Transaction)2 AmountDecoderException (com.mobilecoin.lib.exceptions.AmountDecoderException)2 FeeRejectedException (com.mobilecoin.lib.exceptions.FeeRejectedException)2 FogReportException (com.mobilecoin.lib.exceptions.FogReportException)2 FragmentedAccountException (com.mobilecoin.lib.exceptions.FragmentedAccountException)2 InsufficientFundsException (com.mobilecoin.lib.exceptions.InsufficientFundsException)2 InvalidReceiptException (com.mobilecoin.lib.exceptions.InvalidReceiptException)2 InvalidTransactionException (com.mobilecoin.lib.exceptions.InvalidTransactionException)2