Search in sources :

Example 1 with InvalidReceiptException

use of com.mobilecoin.lib.exceptions.InvalidReceiptException 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

NonNull (androidx.annotation.NonNull)1 WorkerThread (androidx.annotation.WorkerThread)1 Receipt (com.mobilecoin.lib.Receipt)1 AmountDecoderException (com.mobilecoin.lib.exceptions.AmountDecoderException)1 AttestationException (com.mobilecoin.lib.exceptions.AttestationException)1 InvalidFogResponse (com.mobilecoin.lib.exceptions.InvalidFogResponse)1 InvalidReceiptException (com.mobilecoin.lib.exceptions.InvalidReceiptException)1 NetworkException (com.mobilecoin.lib.exceptions.NetworkException)1 SerializationException (com.mobilecoin.lib.exceptions.SerializationException)1 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1