Search in sources :

Example 16 with Address

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

the class SparrowPostmixHandler method computeNextDestination.

protected MixDestination computeNextDestination() throws Exception {
    // index
    int index = Math.max(getIndexHandler().getAndIncrementUnconfirmed(), startIndex);
    // address
    WalletNode node = new WalletNode(wallet, keyPurpose, index);
    Address address = node.getAddress();
    String path = XPubUtil.getInstance().getPath(index, keyPurpose.getPathIndex().num());
    log.info("Mixing to external xPub -> receiveAddress=" + address + ", path=" + path);
    return new MixDestination(DestinationType.XPUB, index, address.toString(), path);
}
Also used : Address(com.sparrowwallet.drongo.address.Address) MixDestination(com.samourai.whirlpool.client.mix.handler.MixDestination) WalletNode(com.sparrowwallet.drongo.wallet.WalletNode)

Example 17 with Address

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

the class PrivateKeySweepDialog method createTransaction.

private void createTransaction() {
    try {
        DumpedPrivateKey privateKey = getPrivateKey();
        ScriptType scriptType = keyScriptType.getValue();
        Address fromAddress = scriptType.getAddress(privateKey.getKey());
        Address destAddress = getToAddress();
        ElectrumServer.AddressUtxosService addressUtxosService = new ElectrumServer.AddressUtxosService(fromAddress);
        addressUtxosService.setOnSucceeded(successEvent -> {
            createTransaction(privateKey.getKey(), scriptType, addressUtxosService.getValue(), destAddress);
        });
        addressUtxosService.setOnFailed(failedEvent -> {
            log.error("Error retrieving outputs for address " + fromAddress, failedEvent.getSource().getException());
            AppServices.showErrorDialog("Error retrieving outputs for address", failedEvent.getSource().getException().getMessage());
        });
        addressUtxosService.start();
    } catch (Exception e) {
        log.error("Error creating sweep transaction", e);
    }
}
Also used : ElectrumServer(com.sparrowwallet.sparrow.net.ElectrumServer) Address(com.sparrowwallet.drongo.address.Address) DumpedPrivateKey(com.sparrowwallet.drongo.crypto.DumpedPrivateKey) InvalidAddressException(com.sparrowwallet.drongo.address.InvalidAddressException) IOException(java.io.IOException)

Example 18 with Address

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

the class PrivateKeySweepDialog method setFromAddress.

private void setFromAddress() {
    DumpedPrivateKey privateKey = getPrivateKey();
    ScriptType scriptType = keyScriptType.getValue();
    Address address = scriptType.getAddress(privateKey.getKey());
    keyAddress.setText(address.toString());
}
Also used : Address(com.sparrowwallet.drongo.address.Address) DumpedPrivateKey(com.sparrowwallet.drongo.crypto.DumpedPrivateKey)

Example 19 with Address

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

the class EntryCell method updateItem.

@Override
protected void updateItem(Entry entry, boolean empty) {
    super.updateItem(entry, empty);
    applyRowStyles(this, entry);
    if (empty) {
        setText(null);
        setGraphic(null);
    } else {
        if (entry instanceof TransactionEntry) {
            TransactionEntry transactionEntry = (TransactionEntry) entry;
            if (transactionEntry.getBlockTransaction().getHeight() == -1) {
                setText("Unconfirmed Parent");
                setContextMenu(new UnconfirmedTransactionContextMenu(transactionEntry));
            } else if (transactionEntry.getBlockTransaction().getHeight() == 0) {
                setText("Unconfirmed");
                setContextMenu(new UnconfirmedTransactionContextMenu(transactionEntry));
            } else {
                String date = DATE_FORMAT.format(transactionEntry.getBlockTransaction().getDate());
                setText(date);
                setContextMenu(new TransactionContextMenu(date, transactionEntry.getBlockTransaction()));
            }
            Tooltip tooltip = new Tooltip();
            tooltip.setShowDelay(Duration.millis(250));
            tooltip.setText(getTooltip(transactionEntry));
            setTooltip(tooltip);
            if (transactionEntry.getBlockTransaction().getHeight() <= 0) {
                tooltip.setOnShowing(event -> {
                    tooltip.setText(getTooltip(transactionEntry));
                });
            }
            HBox actionBox = new HBox();
            actionBox.getStyleClass().add("cell-actions");
            Button viewTransactionButton = new Button("");
            viewTransactionButton.setGraphic(getViewTransactionGlyph());
            viewTransactionButton.setOnAction(event -> {
                EventManager.get().post(new ViewTransactionEvent(this.getScene().getWindow(), transactionEntry.getBlockTransaction()));
            });
            actionBox.getChildren().add(viewTransactionButton);
            BlockTransaction blockTransaction = transactionEntry.getBlockTransaction();
            if (blockTransaction.getHeight() <= 0 && blockTransaction.getTransaction().isReplaceByFee() && transactionEntry.getWallet().allInputsFromWallet(blockTransaction.getHash())) {
                Button increaseFeeButton = new Button("");
                increaseFeeButton.setGraphic(getIncreaseFeeRBFGlyph());
                increaseFeeButton.setOnAction(event -> {
                    increaseFee(transactionEntry);
                });
                actionBox.getChildren().add(increaseFeeButton);
            }
            if (blockTransaction.getHeight() <= 0 && containsWalletOutputs(transactionEntry)) {
                Button cpfpButton = new Button("");
                cpfpButton.setGraphic(getIncreaseFeeCPFPGlyph());
                cpfpButton.setOnAction(event -> {
                    createCpfp(transactionEntry);
                });
                actionBox.getChildren().add(cpfpButton);
            }
            setGraphic(actionBox);
        } else if (entry instanceof NodeEntry) {
            NodeEntry nodeEntry = (NodeEntry) entry;
            Address address = nodeEntry.getAddress();
            setText(address.toString());
            setContextMenu(new AddressContextMenu(address, nodeEntry.getOutputDescriptor(), nodeEntry));
            Tooltip tooltip = new Tooltip();
            tooltip.setShowDelay(Duration.millis(250));
            tooltip.setText(nodeEntry.getNode().toString());
            setTooltip(tooltip);
            getStyleClass().add("address-cell");
            HBox actionBox = new HBox();
            actionBox.getStyleClass().add("cell-actions");
            if (!nodeEntry.getNode().getWallet().isBip47()) {
                Button receiveButton = new Button("");
                receiveButton.setGraphic(getReceiveGlyph());
                receiveButton.setOnAction(event -> {
                    EventManager.get().post(new ReceiveActionEvent(nodeEntry));
                    Platform.runLater(() -> EventManager.get().post(new ReceiveToEvent(nodeEntry)));
                });
                actionBox.getChildren().add(receiveButton);
            }
            if (canSignMessage(nodeEntry.getNode())) {
                Button signMessageButton = new Button("");
                signMessageButton.setGraphic(getSignMessageGlyph());
                signMessageButton.setOnAction(event -> {
                    MessageSignDialog messageSignDialog = new MessageSignDialog(nodeEntry.getWallet(), nodeEntry.getNode());
                    messageSignDialog.showAndWait();
                });
                actionBox.getChildren().add(signMessageButton);
            }
            setGraphic(actionBox);
            if (nodeEntry.getWallet().isWhirlpoolChildWallet()) {
                setText(address.toString().substring(0, 20) + "...");
                setContextMenu(null);
                setGraphic(new HBox());
            }
        } else if (entry instanceof HashIndexEntry) {
            HashIndexEntry hashIndexEntry = (HashIndexEntry) entry;
            setText(hashIndexEntry.getDescription());
            setContextMenu(getTreeTableView().getStyleClass().contains("bip47") ? null : new HashIndexEntryContextMenu(getTreeTableView(), hashIndexEntry));
            Tooltip tooltip = new Tooltip();
            tooltip.setShowDelay(Duration.millis(250));
            tooltip.setText(hashIndexEntry.getHashIndex().toString());
            setTooltip(tooltip);
            HBox actionBox = new HBox();
            actionBox.getStyleClass().add("cell-actions");
            Button viewTransactionButton = new Button("");
            viewTransactionButton.setGraphic(getViewTransactionGlyph());
            viewTransactionButton.setOnAction(event -> {
                EventManager.get().post(new ViewTransactionEvent(this.getScene().getWindow(), hashIndexEntry.getBlockTransaction(), hashIndexEntry));
            });
            actionBox.getChildren().add(viewTransactionButton);
            if (hashIndexEntry.getType().equals(HashIndexEntry.Type.OUTPUT) && hashIndexEntry.isSpendable() && !hashIndexEntry.getHashIndex().isSpent()) {
                Button spendUtxoButton = new Button("");
                spendUtxoButton.setGraphic(getSendGlyph());
                spendUtxoButton.setOnAction(event -> {
                    sendSelectedUtxos(getTreeTableView(), hashIndexEntry);
                });
                actionBox.getChildren().add(spendUtxoButton);
            }
            setGraphic(getTreeTableView().getStyleClass().contains("bip47") ? null : actionBox);
        }
    }
}
Also used : Address(com.sparrowwallet.drongo.address.Address) Pos(javafx.geometry.Pos) java.util(java.util) com.sparrowwallet.drongo.wallet(com.sparrowwallet.drongo.wallet) javafx.scene.control(javafx.scene.control) LoggerFactory(org.slf4j.LoggerFactory) MempoolRateSize(com.sparrowwallet.sparrow.net.MempoolRateSize) SimpleDateFormat(java.text.SimpleDateFormat) Matcher(java.util.regex.Matcher) Glyph(org.controlsfx.glyphfont.Glyph) Utils(com.sparrowwallet.drongo.Utils) com.sparrowwallet.drongo.protocol(com.sparrowwallet.drongo.protocol) FontAwesome5(com.sparrowwallet.sparrow.glyphfont.FontAwesome5) DateFormat(java.text.DateFormat) com.sparrowwallet.sparrow.wallet(com.sparrowwallet.sparrow.wallet) HBox(javafx.scene.layout.HBox) Logger(org.slf4j.Logger) com.sparrowwallet.sparrow.event(com.sparrowwallet.sparrow.event) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) Duration(javafx.util.Duration) AppServices(com.sparrowwallet.sparrow.AppServices) KeyPurpose(com.sparrowwallet.drongo.KeyPurpose) Clipboard(javafx.scene.input.Clipboard) EventManager(com.sparrowwallet.sparrow.EventManager) ClipboardContent(javafx.scene.input.ClipboardContent) FontAwesome(org.controlsfx.glyphfont.FontAwesome) Pattern(java.util.regex.Pattern) HBox(javafx.scene.layout.HBox) Address(com.sparrowwallet.drongo.address.Address)

Example 20 with Address

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

the class MessageSignDialog method verifyMessage.

private boolean verifyMessage(ECKey signedMessageKey) throws InvalidAddressException, SignatureException {
    Address providedAddress = getAddress();
    ScriptType scriptType = providedAddress.getScriptType();
    if (scriptType == ScriptType.P2SH) {
        scriptType = ScriptType.P2SH_P2WPKH;
    }
    if (!ScriptType.getScriptTypesForPolicyType(PolicyType.SINGLE).contains(scriptType)) {
        throw new IllegalArgumentException("Only single signature P2PKH, P2SH-P2WPKH or P2WPKH addresses can verify messages.");
    }
    Address signedMessageAddress = scriptType.getAddress(signedMessageKey);
    return providedAddress.equals(signedMessageAddress);
}
Also used : ScriptType(com.sparrowwallet.drongo.protocol.ScriptType) Address(com.sparrowwallet.drongo.address.Address)

Aggregations

Address (com.sparrowwallet.drongo.address.Address)26 Test (org.junit.Test)6 InvalidAddressException (com.sparrowwallet.drongo.address.InvalidAddressException)5 ECKey (com.sparrowwallet.drongo.crypto.ECKey)5 KeyPurpose (com.sparrowwallet.drongo.KeyPurpose)4 TransactionOutput (com.sparrowwallet.drongo.protocol.TransactionOutput)4 P2PKHAddress (com.sparrowwallet.drongo.address.P2PKHAddress)3 com.sparrowwallet.drongo.wallet (com.sparrowwallet.drongo.wallet)3 PayNymAddress (com.sparrowwallet.sparrow.paynym.PayNymAddress)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 InvalidPaymentCodeException (com.sparrowwallet.drongo.bip47.InvalidPaymentCodeException)2 DumpedPrivateKey (com.sparrowwallet.drongo.crypto.DumpedPrivateKey)2 NonStandardScriptException (com.sparrowwallet.drongo.protocol.NonStandardScriptException)2 ScriptType (com.sparrowwallet.drongo.protocol.ScriptType)2 Transaction (com.sparrowwallet.drongo.protocol.Transaction)2 BitcoinURI (com.sparrowwallet.drongo.uri.BitcoinURI)2 AppServices (com.sparrowwallet.sparrow.AppServices)2 EventManager (com.sparrowwallet.sparrow.EventManager)2