Search in sources :

Example 1 with Payee

use of org.thoughtcrime.securesms.payments.Payee in project Signal-Android by WhisperSystems.

the class ConfirmPaymentRepository method confirmPayment.

@AnyThread
void confirmPayment(@NonNull ConfirmPaymentState state, @NonNull Consumer<ConfirmPaymentResult> consumer) {
    Log.i(TAG, "confirmPayment");
    SignalExecutors.BOUNDED.execute(() -> {
        Balance balance = wallet.getCachedBalance();
        if (state.getTotal().requireMobileCoin().greaterThan(balance.getFullAmount().requireMobileCoin())) {
            Log.w(TAG, "The total was greater than the wallet's balance");
            consumer.accept(new ConfirmPaymentResult.Error());
            return;
        }
        Payee payee = state.getPayee();
        RecipientId recipientId;
        MobileCoinPublicAddress mobileCoinPublicAddress;
        if (payee.hasRecipientId()) {
            recipientId = payee.requireRecipientId();
            try {
                mobileCoinPublicAddress = ProfileUtil.getAddressForRecipient(Recipient.resolved(recipientId));
            } catch (IOException e) {
                Log.w(TAG, "Failed to get address for recipient " + recipientId);
                consumer.accept(new ConfirmPaymentResult.Error());
                return;
            } catch (PaymentsAddressException e) {
                Log.w(TAG, "Failed to get address for recipient " + recipientId);
                consumer.accept(new ConfirmPaymentResult.Error(e.getCode()));
                return;
            }
        } else if (payee.hasPublicAddress()) {
            recipientId = null;
            mobileCoinPublicAddress = payee.requirePublicAddress();
        } else
            throw new AssertionError();
        UUID paymentUuid = PaymentSendJob.enqueuePayment(recipientId, mobileCoinPublicAddress, Util.emptyIfNull(state.getNote()), state.getAmount().requireMobileCoin(), state.getFee().requireMobileCoin());
        Log.i(TAG, "confirmPayment: PaymentSendJob enqueued");
        consumer.accept(new ConfirmPaymentResult.Success(paymentUuid));
    });
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) IOException(java.io.IOException) PaymentsAddressException(org.thoughtcrime.securesms.payments.PaymentsAddressException) UUID(java.util.UUID) Balance(org.thoughtcrime.securesms.payments.Balance) Payee(org.thoughtcrime.securesms.payments.Payee) MobileCoinPublicAddress(org.thoughtcrime.securesms.payments.MobileCoinPublicAddress) AnyThread(androidx.annotation.AnyThread)

Example 2 with Payee

use of org.thoughtcrime.securesms.payments.Payee in project Signal-Android by WhisperSystems.

the class LedgerReconcileTest method payment.

private static Payment payment(String note, Money.MobileCoin valueAndDirection, Set<ByteString> keyImages, Set<ByteString> publicKeys) {
    UUID uuid = UUID.randomUUID();
    PaymentMetaData.MobileCoinTxoIdentification.Builder builderForValue = PaymentMetaData.MobileCoinTxoIdentification.newBuilder();
    builderForValue.addAllKeyImages(keyImages);
    builderForValue.addAllPublicKey(publicKeys);
    PaymentMetaData paymentMetaData = PaymentMetaData.newBuilder().setMobileCoinTxoIdentification(builderForValue).build();
    return new Payment() {

        @Override
        @NonNull
        public UUID getUuid() {
            return uuid;
        }

        @Override
        @NonNull
        public Payee getPayee() {
            return new Payee(RecipientId.from(1));
        }

        @Override
        public long getBlockIndex() {
            return 0;
        }

        @Override
        public long getBlockTimestamp() {
            return 0;
        }

        @Override
        public long getTimestamp() {
            return 0;
        }

        @Override
        @NonNull
        public Direction getDirection() {
            return valueAndDirection.isNegative() ? Direction.SENT : Direction.RECEIVED;
        }

        @Override
        @NonNull
        public State getState() {
            return State.SUCCESSFUL;
        }

        @Override
        @Nullable
        public FailureReason getFailureReason() {
            return null;
        }

        @Override
        @NonNull
        public String getNote() {
            return note;
        }

        @Override
        @NonNull
        public Money getAmount() {
            return valueAndDirection.abs();
        }

        @Override
        @NonNull
        public Money getFee() {
            return getAmount().toZero();
        }

        @Override
        @NonNull
        public PaymentMetaData getPaymentMetaData() {
            return paymentMetaData;
        }

        @Override
        public boolean isSeen() {
            return true;
        }
    };
}
Also used : Payment(org.thoughtcrime.securesms.payments.Payment) PaymentMetaData(org.thoughtcrime.securesms.payments.proto.PaymentMetaData) UUID(java.util.UUID) Payee(org.thoughtcrime.securesms.payments.Payee)

Aggregations

UUID (java.util.UUID)2 Payee (org.thoughtcrime.securesms.payments.Payee)2 AnyThread (androidx.annotation.AnyThread)1 IOException (java.io.IOException)1 Balance (org.thoughtcrime.securesms.payments.Balance)1 MobileCoinPublicAddress (org.thoughtcrime.securesms.payments.MobileCoinPublicAddress)1 Payment (org.thoughtcrime.securesms.payments.Payment)1 PaymentsAddressException (org.thoughtcrime.securesms.payments.PaymentsAddressException)1 PaymentMetaData (org.thoughtcrime.securesms.payments.proto.PaymentMetaData)1 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)1