broadcast fixes

This commit is contained in:
Craig Raw
2020-07-31 10:36:59 +02:00
parent 39e5031a78
commit e5327b3d3d
9 changed files with 86 additions and 13 deletions
@@ -404,6 +404,8 @@ public class AppController implements Initializable {
return onlineProperty.get();
}
public static BooleanProperty onlineProperty() { return onlineProperty; }
public static Integer getCurrentBlockHeight() {
return currentBlockHeight;
}
@@ -50,7 +50,7 @@ public class ConfirmationProgressIndicator extends StackPane {
Timeline arcLengthTimeline = new Timeline();
KeyValue arcLengthValue = new KeyValue(arc.lengthProperty(), getDegrees(newValue.intValue()));
KeyFrame arcLengthFrame = new KeyFrame(Duration.millis(1000), arcLengthValue);
KeyFrame arcLengthFrame = new KeyFrame(Duration.millis(3000), arcLengthValue);
arcLengthTimeline.getKeyFrames().add(arcLengthFrame);
sequence.getChildren().add(arcLengthTimeline);
@@ -86,7 +86,7 @@ public class ConfirmationProgressIndicator extends StackPane {
upTickLineTimeline.getKeyFrames().add(upTickLineFrame);
sequence.getChildren().add(upTickLineTimeline);
FadeTransition groupFadeOut = new FadeTransition(Duration.minutes(1), confirmationGroup);
FadeTransition groupFadeOut = new FadeTransition(Duration.minutes(10), confirmationGroup);
groupFadeOut.setFromValue(1);
groupFadeOut.setToValue(0);
sequence.getChildren().add(groupFadeOut);
@@ -15,6 +15,7 @@ public class FontAwesome5 extends GlyphFont {
* The individual glyphs offered by the FontAwesome5 font.
*/
public static enum Glyph implements INamedCharacter {
ARROW_DOWN('\uf063'),
ARROW_UP('\uf062'),
CAMERA('\uf030'),
CHECK_CIRCLE('\uf058'),
@@ -246,8 +246,7 @@ public class ElectrumServer {
for(WalletNode node : nodes) {
if(node.getIndex() >= startIndex) {
String scriptHash = getScriptHash(wallet, node);
if(!subscribedScriptHashes.containsKey(scriptHash)) {
scriptHashes.add(scriptHash);
if(!subscribedScriptHashes.containsKey(scriptHash) && scriptHashes.add(scriptHash)) {
batchRequest.add(node.getDerivationPath(), "blockchain.scripthash.subscribe", scriptHash);
}
}
@@ -1,6 +1,7 @@
package com.sparrowwallet.sparrow.transaction;
import com.sparrowwallet.drongo.SecureString;
import com.sparrowwallet.drongo.Utils;
import com.sparrowwallet.drongo.protocol.*;
import com.sparrowwallet.drongo.psbt.PSBT;
import com.sparrowwallet.drongo.psbt.PSBTInput;
@@ -12,6 +13,7 @@ import com.sparrowwallet.sparrow.event.*;
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5Brands;
import com.sparrowwallet.sparrow.io.ElectrumServer;
import com.sparrowwallet.sparrow.io.Storage;
import com.sparrowwallet.sparrow.wallet.TransactionEntry;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
@@ -105,7 +107,7 @@ public class HeadersController extends TransactionFormController implements Init
private Form blockchainForm;
@FXML
private CopyableLabel blockStatus;
private Label blockStatus;
@FXML
private Field blockHeightField;
@@ -173,6 +175,9 @@ public class HeadersController extends TransactionFormController implements Init
@FXML
private Button broadcastButton;
@FXML
private Button saveFinalButton;
@Override
public void initialize(URL location, ResourceBundle resources) {
EventManager.get().register(this);
@@ -308,6 +313,11 @@ public class HeadersController extends TransactionFormController implements Init
broadcastProgressBar.managedProperty().bind(broadcastProgressBar.visibleProperty());
broadcastProgressBar.visibleProperty().bind(signaturesProgressBar.visibleProperty().not());
broadcastButton.managedProperty().bind(broadcastButton.visibleProperty());
saveFinalButton.managedProperty().bind(saveFinalButton.visibleProperty());
saveFinalButton.visibleProperty().bind(broadcastButton.visibleProperty().not());
broadcastButton.visibleProperty().bind(AppController.onlineProperty());
blockchainForm.setVisible(false);
signingWalletForm.setVisible(false);
sigHashForm.setVisible(false);
@@ -433,6 +443,17 @@ public class HeadersController extends TransactionFormController implements Init
} else {
blockStatus.setText(confirmations + " Confirmations");
}
if(confirmations <= TransactionEntry.BLOCKS_TO_CONFIRM) {
ConfirmationProgressIndicator indicator;
if(blockStatus.getGraphic() == null) {
indicator = new ConfirmationProgressIndicator(confirmations);
blockStatus.setGraphic(indicator);
} else {
indicator = (ConfirmationProgressIndicator)blockStatus.getGraphic();
indicator.setConfirmations(confirmations);
}
}
}
blockHeightField.managedProperty().bind(blockHeightField.visibleProperty());
@@ -644,6 +665,12 @@ public class HeadersController extends TransactionFormController implements Init
broadcastButton.setDisable(true);
extractTransaction(event);
if(headersForm.getSigningWallet() instanceof FinalizingPSBTWallet) {
//Ensure the script hashes of the UTXOs in FinalizingPSBTWallet are subscribed to
ElectrumServer.TransactionHistoryService historyService = new ElectrumServer.TransactionHistoryService(headersForm.getSigningWallet());
historyService.start();
}
ElectrumServer.BroadcastTransactionService broadcastTransactionService = new ElectrumServer.BroadcastTransactionService(headersForm.getTransaction());
broadcastTransactionService.setOnSucceeded(workerStateEvent -> {
//Do nothing and wait for WalletNodeHistoryChangedEvent to indicate tx is in mempool
@@ -659,6 +686,29 @@ public class HeadersController extends TransactionFormController implements Init
broadcastTransactionService.start();
}
public void saveFinalTransaction(ActionEvent event) {
Stage window = new Stage();
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save Final Transaction");
if(headersForm.getName() != null && !headersForm.getName().isEmpty()) {
fileChooser.setInitialFileName(headersForm.getName().replace(".psbt", "") + ".txn");
}
File file = fileChooser.showSaveDialog(window);
if(file != null) {
try {
try(PrintWriter writer = new PrintWriter(file, StandardCharsets.UTF_8)) {
Transaction finalTx = headersForm.getPsbt().extractTransaction();
writer.print(Utils.bytesToHex(finalTx.bitcoinSerialize()));
}
} catch(IOException e) {
AppController.showErrorDialog("Error saving transaction", "Cannot write to " + file.getAbsolutePath());
}
}
}
@Subscribe
public void transactionChanged(TransactionChangedEvent event) {
if(headersForm.getTransaction().equals(event.getTransaction())) {
@@ -830,9 +880,9 @@ public class HeadersController extends TransactionFormController implements Init
}
@Subscribe
public void walletBlockHeightChanged(WalletBlockHeightChangedEvent event) {
if(headersForm.getSigningWallet() != null && event.getWallet() == headersForm.getSigningWallet() && headersForm.getBlockTransaction() != null) {
updateBlockchainForm(headersForm.getBlockTransaction(), event.getBlockHeight());
public void newBlock(NewBlockEvent event) {
if(headersForm.getBlockTransaction() != null) {
updateBlockchainForm(headersForm.getBlockTransaction(), event.getHeight());
}
}
}
@@ -79,14 +79,18 @@ public class WalletController extends WalletFormController implements Initializa
configure(walletForm.getWallet().isValid());
}
public void configure(boolean isWalletValid) {
public void configure(boolean validWallet) {
for(Toggle toggle : walletMenu.getToggles()) {
if(toggle.getUserData().equals(Function.SETTINGS)) {
if(!isWalletValid) {
if(!validWallet) {
toggle.setSelected(true);
}
} else {
((ToggleButton)toggle).setDisable(!isWalletValid);
if(toggle.getUserData().equals(Function.TRANSACTIONS) && validWallet && walletMenu.getSelectedToggle() == null) {
toggle.setSelected(true);
}
((ToggleButton)toggle).setDisable(!validWallet);
}
}
}