allow psbts without utxo data to be loaded if utxos are provided in an existing psbt

This commit is contained in:
Craig Raw 2021-05-28 11:09:23 +02:00
parent bc83f6fa22
commit 600a77da3a
3 changed files with 20 additions and 8 deletions

2
drongo

@ -1 +1 @@
Subproject commit 567294a4b055cc062650de45fccbbc89db714f39 Subproject commit 42ffeb95650c56bffbd5ec8f8e8f38d91faaab3f

View file

@ -18,6 +18,7 @@ import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.drongo.psbt.PSBT; import com.sparrowwallet.drongo.psbt.PSBT;
import com.sparrowwallet.drongo.psbt.PSBTInput; import com.sparrowwallet.drongo.psbt.PSBTInput;
import com.sparrowwallet.drongo.psbt.PSBTParseException; import com.sparrowwallet.drongo.psbt.PSBTParseException;
import com.sparrowwallet.drongo.psbt.PSBTSignatureException;
import com.sparrowwallet.drongo.wallet.*; import com.sparrowwallet.drongo.wallet.*;
import com.sparrowwallet.sparrow.control.*; import com.sparrowwallet.sparrow.control.*;
import com.sparrowwallet.sparrow.event.*; import com.sparrowwallet.sparrow.event.*;
@ -1176,7 +1177,8 @@ public class AppController implements Initializable {
private void addTransactionTab(String name, File file, byte[] bytes) throws PSBTParseException, ParseException, TransactionParseException { private void addTransactionTab(String name, File file, byte[] bytes) throws PSBTParseException, ParseException, TransactionParseException {
if(PSBT.isPSBT(bytes)) { if(PSBT.isPSBT(bytes)) {
PSBT psbt = new PSBT(bytes); //Don't verify signatures here - provided PSBT may omit UTXO data that can be found when combining with an existing PSBT
PSBT psbt = new PSBT(bytes, false);
addTransactionTab(name, file, psbt); addTransactionTab(name, file, psbt);
} else if(Transaction.isTransaction(bytes)) { } else if(Transaction.isTransaction(bytes)) {
try { try {
@ -1252,6 +1254,16 @@ public class AppController implements Initializable {
} }
} }
if(psbt != null) {
try {
//Any PSBTs that have reached this point could not be combined with an existing PSBT. Verify signatures before continuing
psbt.verifySignatures();
} catch(PSBTSignatureException e) {
AppServices.showErrorDialog("Invalid PSBT", e.getMessage());
return;
}
}
try { try {
String tabName = name; String tabName = name;

View file

@ -209,7 +209,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
if(parts.stream().filter(Objects::nonNull).count() == n) { if(parts.stream().filter(Objects::nonNull).count() == n) {
String complete = String.join("", parts); String complete = String.join("", parts);
try { try {
PSBT psbt = PSBT.fromString(complete); PSBT psbt = PSBT.fromString(complete, false);
result = new Result(psbt); result = new Result(psbt);
return; return;
} catch(PSBTParseException e) { } catch(PSBTParseException e) {
@ -261,7 +261,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
} }
try { try {
psbt = PSBT.fromString(qrtext); psbt = PSBT.fromString(qrtext, false);
result = new Result(psbt); result = new Result(psbt);
return; return;
} catch(PSBTParseException e) { } catch(PSBTParseException e) {
@ -273,7 +273,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
} }
try { try {
psbt = new PSBT(qrResult.getRawBytes()); psbt = new PSBT(qrResult.getRawBytes(), false);
result = new Result(psbt); result = new Result(psbt);
return; return;
} catch(Exception e) { } catch(Exception e) {
@ -298,7 +298,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
//Try Base43 used by Electrum //Try Base43 used by Electrum
try { try {
psbt = new PSBT(Base43.decode(qrtext)); psbt = new PSBT(Base43.decode(qrtext), false);
result = new Result(psbt); result = new Result(psbt);
return; return;
} catch(Exception e) { } catch(Exception e) {
@ -324,7 +324,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
if(urRegistryType.equals(RegistryType.BYTES)) { if(urRegistryType.equals(RegistryType.BYTES)) {
byte[] urBytes = (byte[])ur.decodeFromRegistry(); byte[] urBytes = (byte[])ur.decodeFromRegistry();
try { try {
PSBT psbt = new PSBT(urBytes); PSBT psbt = new PSBT(urBytes, false);
return new Result(psbt); return new Result(psbt);
} catch(PSBTParseException e) { } catch(PSBTParseException e) {
if(PSBT.isPSBT(urBytes)) { if(PSBT.isPSBT(urBytes)) {
@ -354,7 +354,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
} else if(urRegistryType.equals(RegistryType.CRYPTO_PSBT)) { } else if(urRegistryType.equals(RegistryType.CRYPTO_PSBT)) {
CryptoPSBT cryptoPSBT = (CryptoPSBT)ur.decodeFromRegistry(); CryptoPSBT cryptoPSBT = (CryptoPSBT)ur.decodeFromRegistry();
try { try {
PSBT psbt = new PSBT(cryptoPSBT.getPsbt()); PSBT psbt = new PSBT(cryptoPSBT.getPsbt(), false);
return new Result(psbt); return new Result(psbt);
} catch(Exception e) { } catch(Exception e) {
log.error("Error parsing PSBT from UR type " + urRegistryType, e); log.error("Error parsing PSBT from UR type " + urRegistryType, e);