Search in sources :

Example 1 with InvalidAddressException

use of com.sparrowwallet.drongo.address.InvalidAddressException in project sparrow by sparrowwallet.

the class SendController method updateTransaction.

public void updateTransaction(List<Payment> transactionPayments) {
    if (walletTransactionService != null && walletTransactionService.isRunning()) {
        walletTransactionService.setIgnoreResult(true);
        walletTransactionService.cancel();
    }
    try {
        List<Payment> payments = transactionPayments != null ? transactionPayments : getPayments();
        updateOptimizationButtons(payments);
        if (!userFeeSet.get() || (getFeeValueSats() != null && getFeeValueSats() > 0)) {
            Wallet wallet = getWalletForm().getWallet();
            Long userFee = userFeeSet.get() ? getFeeValueSats() : null;
            double feeRate = getUserFeeRate();
            Integer currentBlockHeight = AppServices.getCurrentBlockHeight();
            boolean groupByAddress = Config.get().isGroupByAddress();
            boolean includeMempoolOutputs = Config.get().isIncludeMempoolOutputs();
            boolean includeSpentMempoolOutputs = includeSpentMempoolOutputsProperty.get();
            walletTransactionService = new WalletTransactionService(wallet, getUtxoSelectors(payments), getUtxoFilters(), payments, opReturnsList, excludedChangeNodes, feeRate, getMinimumFeeRate(), userFee, currentBlockHeight, groupByAddress, includeMempoolOutputs, includeSpentMempoolOutputs);
            walletTransactionService.setOnSucceeded(event -> {
                if (!walletTransactionService.isIgnoreResult()) {
                    walletTransactionProperty.setValue(walletTransactionService.getValue());
                    insufficientInputsProperty.set(false);
                }
            });
            walletTransactionService.setOnFailed(event -> {
                if (!walletTransactionService.isIgnoreResult()) {
                    transactionDiagram.clear();
                    walletTransactionProperty.setValue(null);
                    if (event.getSource().getException() instanceof InsufficientFundsException) {
                        insufficientInputsProperty.set(true);
                    }
                }
            });
            final WalletTransactionService currentWalletTransactionService = walletTransactionService;
            final KeyFrame delay = new KeyFrame(Duration.millis(200), e -> {
                if (currentWalletTransactionService.isRunning()) {
                    transactionDiagram.update("Selecting UTXOs...");
                    createButton.setDisable(true);
                    notificationButton.setDisable(true);
                }
            });
            final Timeline timeline = new Timeline(delay);
            timeline.play();
            walletTransactionService.start();
        }
    } catch (InvalidAddressException | IllegalStateException e) {
        walletTransactionProperty.setValue(null);
    }
}
Also used : Timeline(javafx.animation.Timeline) KeyFrame(javafx.animation.KeyFrame) InvalidAddressException(com.sparrowwallet.drongo.address.InvalidAddressException)

Example 2 with InvalidAddressException

use of com.sparrowwallet.drongo.address.InvalidAddressException in project sparrow by sparrowwallet.

the class PaymentController method getPayment.

public Payment getPayment(boolean sendAll) {
    try {
        Address recipientAddress = getRecipientAddress();
        Long value = sendAll ? Long.valueOf(getRecipientDustThreshold() + 1) : getRecipientValueSats();
        if (!label.getText().isEmpty() && value != null && value >= getRecipientDustThreshold()) {
            Payment payment = new Payment(recipientAddress, label.getText(), value, sendAll);
            if (address.getUserData() != null) {
                payment.setType((Payment.Type) address.getUserData());
            }
            return payment;
        }
    } catch (InvalidAddressException e) {
    // ignore
    }
    throw new IllegalStateException("Invalid payment specified");
}
Also used : PayNymAddress(com.sparrowwallet.sparrow.paynym.PayNymAddress) Address(com.sparrowwallet.drongo.address.Address) P2PKHAddress(com.sparrowwallet.drongo.address.P2PKHAddress) InvalidAddressException(com.sparrowwallet.drongo.address.InvalidAddressException)

Example 3 with InvalidAddressException

use of com.sparrowwallet.drongo.address.InvalidAddressException in project sparrow by sparrowwallet.

the class VersionCheckService method verifySignature.

private boolean verifySignature(VersionCheck versionCheck) {
    try {
        for (String addressString : versionCheck.signatures.keySet()) {
            if (!addressString.equals("1LiJx1HQ49L2LzhBwbgwXdHiGodvPg5YaV")) {
                log.warn("Invalid address for version check " + addressString);
                continue;
            }
            String signature = versionCheck.signatures.get(addressString);
            ECKey signedMessageKey = ECKey.signedMessageToKey(versionCheck.version, signature, false);
            Address providedAddress = Address.fromString(addressString);
            Address signedMessageAddress = ScriptType.P2PKH.getAddress(signedMessageKey);
            if (providedAddress.equals(signedMessageAddress)) {
                return true;
            } else {
                log.warn("Invalid signature for version check " + signature + " from address " + addressString);
            }
        }
    } catch (SignatureException e) {
        log.error("Error in version check signature", e);
    } catch (InvalidAddressException e) {
        log.error("Error in version check address", e);
    }
    return false;
}
Also used : Address(com.sparrowwallet.drongo.address.Address) ECKey(com.sparrowwallet.drongo.crypto.ECKey) SignatureException(java.security.SignatureException) InvalidAddressException(com.sparrowwallet.drongo.address.InvalidAddressException)

Example 4 with InvalidAddressException

use of com.sparrowwallet.drongo.address.InvalidAddressException in project sparrow by sparrowwallet.

the class UtxosController method previewPremix.

private void previewPremix(Wallet wallet, Tx0Preview tx0Preview, List<UtxoEntry> utxoEntries) {
    Wallet masterWallet = wallet.isMasterWallet() ? wallet : wallet.getMasterWallet();
    Wallet premixWallet = masterWallet.getChildWallet(StandardAccount.WHIRLPOOL_PREMIX);
    Wallet badbankWallet = masterWallet.getChildWallet(StandardAccount.WHIRLPOOL_BADBANK);
    List<Payment> payments = new ArrayList<>();
    if (tx0Preview.getTx0Data().getFeeAddress() != null) {
        try {
            Address whirlpoolFeeAddress = Address.fromString(tx0Preview.getTx0Data().getFeeAddress());
            Payment whirlpoolFeePayment = new Payment(whirlpoolFeeAddress, "Whirlpool Fee", tx0Preview.getFeeValue(), false);
            whirlpoolFeePayment.setType(Payment.Type.WHIRLPOOL_FEE);
            payments.add(whirlpoolFeePayment);
        } catch (InvalidAddressException e) {
            throw new IllegalStateException("Cannot parse whirlpool fee address " + tx0Preview.getTx0Data().getFeeAddress(), e);
        }
    }
    WalletNode badbankNode = badbankWallet.getFreshNode(KeyPurpose.RECEIVE);
    Payment changePayment = new Payment(badbankNode.getAddress(), "Badbank Change", tx0Preview.getChangeValue(), false);
    payments.add(changePayment);
    WalletNode premixNode = null;
    for (int i = 0; i < tx0Preview.getNbPremix(); i++) {
        premixNode = premixWallet.getFreshNode(KeyPurpose.RECEIVE, premixNode);
        Address premixAddress = premixNode.getAddress();
        payments.add(new Payment(premixAddress, "Premix #" + i, tx0Preview.getPremixValue(), false));
    }
    List<byte[]> opReturns = List.of(new byte[64]);
    final List<BlockTransactionHashIndex> utxos = utxoEntries.stream().map(HashIndexEntry::getHashIndex).collect(Collectors.toList());
    Platform.runLater(() -> {
        EventManager.get().post(new SendActionEvent(getWalletForm().getWallet(), utxos));
        Platform.runLater(() -> EventManager.get().post(new SpendUtxoEvent(getWalletForm().getWallet(), utxos, payments, opReturns, tx0Preview.getTx0MinerFee(), tx0Preview.getPool())));
    });
}
Also used : Address(com.sparrowwallet.drongo.address.Address) InvalidAddressException(com.sparrowwallet.drongo.address.InvalidAddressException)

Aggregations

InvalidAddressException (com.sparrowwallet.drongo.address.InvalidAddressException)4 Address (com.sparrowwallet.drongo.address.Address)3 P2PKHAddress (com.sparrowwallet.drongo.address.P2PKHAddress)1 ECKey (com.sparrowwallet.drongo.crypto.ECKey)1 PayNymAddress (com.sparrowwallet.sparrow.paynym.PayNymAddress)1 SignatureException (java.security.SignatureException)1 KeyFrame (javafx.animation.KeyFrame)1 Timeline (javafx.animation.Timeline)1