Search in sources :

Example 26 with MobileCoinLedgerWrapper

use of org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper in project Signal-Android by signalapp.

the class PaymentLedgerUpdateJob method onRun.

@Override
protected void onRun() throws IOException, RetryLaterException {
    if (!SignalStore.paymentsValues().mobileCoinPaymentsEnabled()) {
        Log.w(TAG, "Payments are not enabled");
        return;
    }
    Long minimumBlockIndex = null;
    if (paymentUuid != null) {
        PaymentDatabase.PaymentTransaction payment = SignalDatabase.payments().getPayment(paymentUuid);
        if (payment != null) {
            minimumBlockIndex = payment.getBlockIndex();
            Log.i(TAG, "Fetching for a payment " + paymentUuid + " " + (minimumBlockIndex > 0 ? "non-zero" : "zero"));
        } else {
            Log.w(TAG, "Payment not found " + paymentUuid);
        }
    }
    MobileCoinLedgerWrapper ledger = ApplicationDependencies.getPayments().getWallet().tryGetFullLedger(minimumBlockIndex);
    if (ledger == null) {
        Log.i(TAG, "Ledger not updated yet, waiting for a minimum block index");
        throw new RetryLaterException();
    }
    Log.i(TAG, "Ledger fetched successfully");
    SignalStore.paymentsValues().setMobileCoinFullLedger(ledger);
}
Also used : RetryLaterException(org.thoughtcrime.securesms.transport.RetryLaterException) PaymentDatabase(org.thoughtcrime.securesms.database.PaymentDatabase) MobileCoinLedgerWrapper(org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper)

Aggregations

MobileCoinLedgerWrapper (org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper)26 Test (org.junit.Test)24 Payment (org.thoughtcrime.securesms.payments.Payment)24 MobileCoinLedger (org.thoughtcrime.securesms.payments.proto.MobileCoinLedger)22 PaymentDatabase (org.thoughtcrime.securesms.database.PaymentDatabase)2 RetryLaterException (org.thoughtcrime.securesms.transport.RetryLaterException)2