From 0502eec0cddf3d87c8f4ca1654bdbbe5eef992ad Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Fri, 9 Jul 2021 13:35:45 +0200 Subject: [PATCH] dont show message sign context menu item when message signing cant be performed --- drongo | 2 +- .../com/sparrowwallet/sparrow/control/EntryCell.java | 12 ++++++++---- .../sparrow/control/MessageSignDialog.java | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/drongo b/drongo index 5013a0ef..e53574ea 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 5013a0ef2fd0c80d4a568891c77361ed0c436173 +Subproject commit e53574ea542aa8311dba61e18658482611d74632 diff --git a/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java b/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java index b732f566..30745f89 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java @@ -3,6 +3,7 @@ package com.sparrowwallet.sparrow.control; import com.sparrowwallet.drongo.KeyPurpose; import com.sparrowwallet.drongo.Utils; import com.sparrowwallet.drongo.address.Address; +import com.sparrowwallet.drongo.protocol.ScriptType; import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.protocol.TransactionInput; import com.sparrowwallet.drongo.protocol.TransactionOutput; @@ -118,8 +119,7 @@ public class EntryCell extends TreeTableCell { }); actionBox.getChildren().add(receiveButton); - if(nodeEntry.getWallet().getKeystores().size() == 1 && - (nodeEntry.getWallet().getKeystores().get(0).hasPrivateKey() || nodeEntry.getWallet().getKeystores().get(0).getSource() == KeystoreSource.HW_USB)) { + if(canSignMessage(nodeEntry.getWallet())) { Button signMessageButton = new Button(""); signMessageButton.setGraphic(getSignMessageGlyph()); signMessageButton.setOnAction(event -> { @@ -127,7 +127,6 @@ public class EntryCell extends TreeTableCell { messageSignDialog.showAndWait(); }); actionBox.getChildren().add(signMessageButton); - setContextMenu(new AddressContextMenu(address, nodeEntry.getOutputDescriptor(), nodeEntry)); } setGraphic(actionBox); @@ -268,6 +267,11 @@ public class EntryCell extends TreeTableCell { Platform.runLater(() -> EventManager.get().post(new SpendUtxoEvent(transactionEntry.getWallet(), List.of(utxo), List.of(payment), blockTransaction.getFee(), false))); } + private static boolean canSignMessage(Wallet wallet) { + return wallet.getKeystores().size() == 1 && wallet.getScriptType() != ScriptType.P2TR && + (wallet.getKeystores().get(0).hasPrivateKey() || wallet.getKeystores().get(0).getSource() == KeystoreSource.HW_USB); + } + private static boolean containsWalletOutputs(TransactionEntry transactionEntry) { return transactionEntry.getChildren().stream() .filter(e -> e instanceof HashIndexEntry) @@ -463,7 +467,7 @@ public class EntryCell extends TreeTableCell { }); getItems().add(receiveToAddress); - if(nodeEntry != null) { + if(nodeEntry != null && canSignMessage(nodeEntry.getWallet())) { MenuItem signVerifyMessage = new MenuItem("Sign/Verify Message"); signVerifyMessage.setGraphic(getSignMessageGlyph()); signVerifyMessage.setOnAction(AE -> { diff --git a/src/main/java/com/sparrowwallet/sparrow/control/MessageSignDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/MessageSignDialog.java index a535142f..7310dc46 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/MessageSignDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/MessageSignDialog.java @@ -282,8 +282,8 @@ public class MessageSignDialog extends Dialog { private boolean isValidAddress() { try { - getAddress(); - return true; + Address address = getAddress(); + return address.getScriptType() != ScriptType.P2TR; } catch (InvalidAddressException e) { return false; }