show error dialogs on invalid files

This commit is contained in:
Craig Raw 2020-03-30 16:51:12 +02:00
parent 7bfddc1c98
commit 97de5ef6dc
2 changed files with 35 additions and 17 deletions

2
drongo

@ -1 +1 @@
Subproject commit a1696ec2e8d5ca17fc98246e374e9d3ae9ab368f
Subproject commit 314ee075c20c9a23d09e9dd84ee2b6eb3588a129

View file

@ -3,10 +3,12 @@ package com.craigraw.sparrow;
import com.craigraw.drongo.Utils;
import com.craigraw.drongo.protocol.Transaction;
import com.craigraw.drongo.psbt.PSBT;
import com.craigraw.drongo.psbt.PSBTParseException;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.stage.FileChooser;
@ -49,22 +51,34 @@ public class AppController implements Initializable {
stream.read(bytes);
stream.close();
Tab tab = null;
if(PSBT.isPSBT(Hex.toHexString(bytes))) {
Tab tab;
if(PSBT.isPSBT(bytes)) {
try {
PSBT psbt = new PSBT(bytes);
tab = addTransactionTab(file.getName(), null, psbt);
} catch(PSBTParseException e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("PSBT File Invalid");
alert.setHeaderText("PSBT File Invalid");
alert.setContentText(e.getMessage());
alert.showAndWait();
return;
}
} else {
try {
Transaction transaction = new Transaction(bytes);
tab = addTransactionTab(file.getName(), transaction, null);
} catch(Exception e) {
//TODO: Handle not a transaction
} catch(RuntimeException e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("File Invalid");
alert.setHeaderText("File Invalid");
alert.setContentText("Unknown file format or invalid transaction");
alert.showAndWait();
return;
}
}
if(tab != null) {
tabs.getSelectionModel().select(tab);
}
} catch(IOException e) {
throw new RuntimeException(e);
}
@ -87,8 +101,12 @@ public class AppController implements Initializable {
Transaction transaction = new Transaction(txbytes);
addTransactionTab(name, transaction, null);
} else if(psbtHex != null) {
try {
PSBT psbt = PSBT.fromString(psbtHex);
addTransactionTab(name, null, psbt);
} catch(Exception e) {
//ignore
}
}
}