diff --git a/drongo b/drongo index 9663629e..5d456a10 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 9663629e344ad19f5eb550f6d87bd27048f3704e +Subproject commit 5d456a10df1375b41e6159efc540b3d90cfbfc4d diff --git a/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java index 3aa442ae..fd2b5a27 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java @@ -2,9 +2,11 @@ package com.sparrowwallet.sparrow.control; import com.github.sarxos.webcam.WebcamResolution; import com.sparrowwallet.drongo.Utils; +import com.sparrowwallet.drongo.address.Address; import com.sparrowwallet.drongo.protocol.Base43; import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.psbt.PSBT; +import com.sparrowwallet.drongo.uri.BitcoinURI; import com.sparrowwallet.sparrow.ur.ResultType; import com.sparrowwallet.sparrow.ur.UR; import com.sparrowwallet.sparrow.ur.URDecoder; @@ -99,6 +101,24 @@ public class QRScanDialog extends Dialog { } else { PSBT psbt; Transaction transaction; + BitcoinURI bitcoinURI; + Address address; + try { + bitcoinURI = new BitcoinURI(qrtext); + result = new Result(bitcoinURI); + return; + } catch(Exception e) { + //Ignore, not an BIP 21 URI + } + + try { + address = Address.fromString(qrtext); + result = new Result(address); + return; + } catch(Exception e) { + //Ignore, not an address + } + try { psbt = PSBT.fromString(qrtext); result = new Result(psbt); @@ -132,9 +152,8 @@ public class QRScanDialog extends Dialog { } //Try Base43 used by Electrum - byte[] base43 = Base43.decode(qrResult.getText()); try { - psbt = new PSBT(base43); + psbt = new PSBT(Base43.decode(qrResult.getText())); result = new Result(psbt); return; } catch(Exception e) { @@ -142,14 +161,14 @@ public class QRScanDialog extends Dialog { } try { - transaction = new Transaction(base43); + transaction = new Transaction(Base43.decode(qrResult.getText())); result = new Result(transaction); return; } catch(Exception e) { //Ignore, not parseable as base43 decoded bytes } - result = new Result("Cannot parse QR code into a PSBT or transaction"); + result = new Result("Cannot parse QR code into a PSBT, transaction or address"); } } } @@ -157,12 +176,14 @@ public class QRScanDialog extends Dialog { public static class Result { public final Transaction transaction; public final PSBT psbt; + public final BitcoinURI uri; public final String error; public final Throwable exception; public Result(Transaction transaction) { this.transaction = transaction; this.psbt = null; + this.uri = null; this.error = null; this.exception = null; } @@ -170,6 +191,23 @@ public class QRScanDialog extends Dialog { public Result(PSBT psbt) { this.transaction = null; this.psbt = psbt; + this.uri = null; + this.error = null; + this.exception = null; + } + + public Result(BitcoinURI uri) { + this.transaction = null; + this.psbt = null; + this.uri = uri; + this.error = null; + this.exception = null; + } + + public Result(Address address) { + this.transaction = null; + this.psbt = null; + this.uri = BitcoinURI.fromAddress(address); this.error = null; this.exception = null; } @@ -177,6 +215,7 @@ public class QRScanDialog extends Dialog { public Result(String error) { this.transaction = null; this.psbt = null; + this.uri = null; this.error = error; this.exception = null; } @@ -184,6 +223,7 @@ public class QRScanDialog extends Dialog { public Result(Throwable exception) { this.transaction = null; this.psbt = null; + this.uri = null; this.error = null; this.exception = exception; } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index 97a9d7f4..3590ab15 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -496,6 +496,25 @@ public class SendController extends WalletFormController implements Initializabl return address.getScriptType().getDustThreshold(txOutput, getFeeRate()); } + public void scanQrAddress(ActionEvent event) { + QRScanDialog qrScanDialog = new QRScanDialog(); + Optional optionalResult = qrScanDialog.showAndWait(); + if(optionalResult.isPresent()) { + QRScanDialog.Result result = optionalResult.get(); + if(result.uri != null) { + if(result.uri.getAddress() != null) { + address.setText(result.uri.getAddress().toString()); + } + if(result.uri.getLabel() != null) { + label.setText(result.uri.getLabel()); + } + if(result.uri.getAmount() != null) { + setRecipientValueSats(result.uri.getAmount()); + } + } + } + } + public void clear(ActionEvent event) { address.setText(""); label.setText(""); diff --git a/src/main/resources/com/sparrowwallet/sparrow/wallet/send.fxml b/src/main/resources/com/sparrowwallet/sparrow/wallet/send.fxml index 9e5f479d..195619ee 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/wallet/send.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/wallet/send.fxml @@ -20,6 +20,7 @@ +
@@ -61,6 +62,15 @@ +
+
+ +
+
diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index bf3bf87f..2130aac8 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -1,6 +1,10 @@ + + + + ${user.home}/.sparrow/sparrow.log