Browse Source

broadcast fixes

bwt
Craig Raw 4 years ago
parent
commit
e5327b3d3d
  1. 2
      drongo
  2. 2
      src/main/java/com/sparrowwallet/sparrow/AppController.java
  3. 4
      src/main/java/com/sparrowwallet/sparrow/control/ConfirmationProgressIndicator.java
  4. 1
      src/main/java/com/sparrowwallet/sparrow/glyphfont/FontAwesome5.java
  5. 3
      src/main/java/com/sparrowwallet/sparrow/io/ElectrumServer.java
  6. 58
      src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java
  7. 10
      src/main/java/com/sparrowwallet/sparrow/wallet/WalletController.java
  8. 12
      src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css
  9. 7
      src/main/resources/com/sparrowwallet/sparrow/transaction/headers.fxml

2
drongo

@ -1 +1 @@
Subproject commit 4c5166a6ea886622d57254444e95efa043ba302f
Subproject commit 72a2a8bd1becaa77371d1e644c3b9e76b757a8ed

2
src/main/java/com/sparrowwallet/sparrow/AppController.java

@ -404,6 +404,8 @@ public class AppController implements Initializable {
return onlineProperty.get();
}
public static BooleanProperty onlineProperty() { return onlineProperty; }
public static Integer getCurrentBlockHeight() {
return currentBlockHeight;
}

4
src/main/java/com/sparrowwallet/sparrow/control/ConfirmationProgressIndicator.java

@ -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);

1
src/main/java/com/sparrowwallet/sparrow/glyphfont/FontAwesome5.java

@ -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'),

3
src/main/java/com/sparrowwallet/sparrow/io/ElectrumServer.java

@ -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);
}
}

58
src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java

@ -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());
}
}
}

10
src/main/java/com/sparrowwallet/sparrow/wallet/WalletController.java

@ -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);
}
}
}

12
src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css

@ -24,6 +24,18 @@
-fx-text-fill: #a0a1a7;
}
#blockchainForm .input-container {
-fx-alignment: center-left;
}
.confirmation-progress-circle, .confirmation-progress-tick {
-fx-stroke: -fx-text-base-color;
}
.confirmation-progress-arc {
-fx-fill: -fx-text-base-color;
}
#signingWalletForm .input-container {
-fx-alignment: center-left;
-fx-pref-height: 30;

7
src/main/resources/com/sparrowwallet/sparrow/transaction/headers.fxml

@ -116,7 +116,7 @@
<Form fx:id="blockchainForm" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="6">
<Fieldset text="Blockchain" inputGrow="SOMETIMES">
<Field text="Status:">
<CopyableLabel fx:id="blockStatus" />
<Label fx:id="blockStatus" contentDisplay="RIGHT" graphicTextGap="5" />
</Field>
<Field fx:id="blockHeightField" text="Block Height:">
<CopyableLabel fx:id="blockHeight" />
@ -224,6 +224,11 @@
<Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="20" icon="SATELLITE_DISH" />
</graphic>
</Button>
<Button fx:id="saveFinalButton" defaultButton="true" HBox.hgrow="ALWAYS" text="Save Final Transaction" contentDisplay="TOP" wrapText="true" textAlignment="CENTER" onAction="#saveFinalTransaction">
<graphic>
<Glyph fontFamily="Font Awesome 5 Free Solid" fontSize="20" icon="ARROW_DOWN" />
</graphic>
</Button>
</HBox>
</VBox>
</Fieldset>

Loading…
Cancel
Save