show warning dialog when a legacy multi output descriptor is entered

This commit is contained in:
Craig Raw 2022-10-24 16:50:08 +02:00
parent 6ad81e1228
commit ab2c77695b
2 changed files with 11 additions and 2 deletions

View file

@ -66,13 +66,18 @@ public class Descriptor implements WalletImport, WalletExport {
@Override @Override
public Wallet importWallet(InputStream inputStream, String password) throws ImportException { public Wallet importWallet(InputStream inputStream, String password) throws ImportException {
try { try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
inputStream.transferTo(baos);
InputStream firstClone = new ByteArrayInputStream(baos.toByteArray());
InputStream secondClone = new ByteArrayInputStream(baos.toByteArray());
try { try {
return PdfUtils.getOutputDescriptor(inputStream).toWallet(); return PdfUtils.getOutputDescriptor(firstClone).toWallet();
} catch(Exception e) { } catch(Exception e) {
//ignore //ignore
} }
String outputDescriptor = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n")); String outputDescriptor = new BufferedReader(new InputStreamReader(secondClone, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
OutputDescriptor descriptor = OutputDescriptor.getOutputDescriptor(outputDescriptor.trim()); OutputDescriptor descriptor = OutputDescriptor.getOutputDescriptor(outputDescriptor.trim());
return descriptor.toWallet(); return descriptor.toWallet();
} catch(Exception e) { } catch(Exception e) {

View file

@ -404,6 +404,10 @@ public class SettingsController extends WalletFormController implements Initiali
(walletForm.getWallet().getPolicyType() == PolicyType.MULTI ? "\nKey expressions are shown in canonical order." : "")); (walletForm.getWallet().getPolicyType() == PolicyType.MULTI ? "\nKey expressions are shown in canonical order." : ""));
Optional<String> text = dialog.showAndWait(); Optional<String> text = dialog.showAndWait();
if(text.isPresent() && !text.get().isEmpty() && !text.get().equals(outputDescriptorString)) { if(text.isPresent() && !text.get().isEmpty() && !text.get().equals(outputDescriptorString)) {
if(text.get().contains("(multi(")) {
AppServices.showWarningDialog("Legacy multisig wallet detected", "Sparrow supports BIP67 compatible multisig wallets only.\n\nThe public keys will be lexicographically sorted, and the output descriptor represented with sortedmulti.");
}
setDescriptorText(text.get().replace("\n", "")); setDescriptorText(text.get().replace("\n", ""));
} }
} }