From b530ced9ede0becbef7fa16b879e65fbf0add752 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 14 Dec 2021 11:21:32 +0200 Subject: [PATCH] support scanning crypto-account and crypto-output through both qr scans on settings tab --- drongo | 2 +- .../sparrow/control/QRScanDialog.java | 3 +++ .../sparrow/wallet/KeystoreController.java | 18 ++++++++++++++++++ .../sparrow/wallet/SettingsController.java | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drongo b/drongo index 60e989b9..6ac593f1 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 60e989b946cbfa86f7121671a986788c17fbaa34 +Subproject commit 6ac593f161f7d17bf1f99658a92d7d65d25997be diff --git a/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java index aa7c0348..4235aae3 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java @@ -10,6 +10,8 @@ import com.sparrowwallet.drongo.address.P2PKHAddress; import com.sparrowwallet.drongo.address.P2SHAddress; import com.sparrowwallet.drongo.address.P2WPKHAddress; import com.sparrowwallet.drongo.crypto.*; +import com.sparrowwallet.drongo.policy.Policy; +import com.sparrowwallet.drongo.policy.PolicyType; import com.sparrowwallet.drongo.protocol.Base43; import com.sparrowwallet.drongo.protocol.ScriptType; import com.sparrowwallet.drongo.protocol.Transaction; @@ -491,6 +493,7 @@ public class QRScanDialog extends Dialog { keystore.setKeyDerivation(new KeyDerivation(masterFingerprint, KeyDerivation.writePath(outputDescriptor.getKeyDerivation(extendedKey).getDerivation()))); keystore.setExtendedPublicKey(extendedKey); wallet.getKeystores().add(keystore); + wallet.setDefaultPolicy(Policy.getPolicy(outputDescriptor.isCosigner() ? PolicyType.MULTI : PolicyType.SINGLE, wallet.getScriptType(), wallet.getKeystores(), 1)); wallets.add(wallet); } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java index 4003d295..65ad1c72 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/KeystoreController.java @@ -394,6 +394,24 @@ public class KeystoreController extends WalletFormController implements Initiali QRScanDialog.Result result = optionalResult.get(); if(result.extendedKey != null && result.extendedKey.getKey().isPubKeyOnly()) { xpub.setText(result.extendedKey.getExtendedKey()); + } else if(result.outputDescriptor != null && !result.outputDescriptor.getExtendedPublicKeys().isEmpty()) { + ExtendedKey extendedKey = result.outputDescriptor.getExtendedPublicKeys().iterator().next(); + KeyDerivation keyDerivation = result.outputDescriptor.getKeyDerivation(extendedKey); + fingerprint.setText(keyDerivation.getMasterFingerprint()); + derivation.setText(keyDerivation.getDerivationPath()); + xpub.setText(extendedKey.toString()); + } else if(result.wallets != null) { + for(Wallet wallet : result.wallets) { + if(getWalletForm().getWallet().getScriptType().equals(wallet.getScriptType()) && !wallet.getKeystores().isEmpty()) { + Keystore keystore = wallet.getKeystores().get(0); + fingerprint.setText(keystore.getKeyDerivation().getMasterFingerprint()); + derivation.setText(keystore.getKeyDerivation().getDerivationPath()); + xpub.setText(keystore.getExtendedPublicKey().toString()); + return; + } + } + + AppServices.showErrorDialog("Missing Script Type", "QR Code did not contain any information for the " + getWalletForm().getWallet().getScriptType().getDescription() + " script type."); } else if(result.exception != null) { log.error("Error scanning QR", result.exception); AppServices.showErrorDialog("Error scanning QR", result.exception.getMessage()); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java index abfc1b49..6aca20a1 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java @@ -304,7 +304,7 @@ public class SettingsController extends WalletFormController implements Initiali } else if(result.wallets != null) { for(Wallet wallet : result.wallets) { if(scriptType.getValue().equals(wallet.getScriptType()) && !wallet.getKeystores().isEmpty()) { - OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(walletForm.getWallet()); + OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(wallet); setDescriptorText(outputDescriptor.toString()); break; }