view blocktransaction and transaction input/output selection

This commit is contained in:
Craig Raw 2020-06-10 16:15:56 +02:00
parent 936d42e7fd
commit a3a20a788d
17 changed files with 213 additions and 44 deletions

2
drongo

@ -1 +1 @@
Subproject commit 0d56692784f5dfc50197533eb00ccf8e5c42e471 Subproject commit 728b6ce5ef21233b5e1687d3fb4277b79eb2e4e1

View file

@ -12,19 +12,18 @@ import com.sparrowwallet.drongo.protocol.ScriptType;
import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.drongo.psbt.PSBT; import com.sparrowwallet.drongo.psbt.PSBT;
import com.sparrowwallet.drongo.psbt.PSBTParseException; import com.sparrowwallet.drongo.psbt.PSBTParseException;
import com.sparrowwallet.drongo.wallet.Keystore; import com.sparrowwallet.drongo.wallet.*;
import com.sparrowwallet.drongo.wallet.KeystoreSource;
import com.sparrowwallet.drongo.wallet.MnemonicException;
import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.sparrow.control.*; import com.sparrowwallet.sparrow.control.*;
import com.sparrowwallet.sparrow.event.*; import com.sparrowwallet.sparrow.event.*;
import com.sparrowwallet.sparrow.io.*; import com.sparrowwallet.sparrow.io.*;
import com.sparrowwallet.sparrow.preferences.PreferencesDialog; import com.sparrowwallet.sparrow.preferences.PreferencesDialog;
import com.sparrowwallet.sparrow.transaction.TransactionController; import com.sparrowwallet.sparrow.transaction.TransactionController;
import com.sparrowwallet.sparrow.wallet.HashIndexEntry;
import com.sparrowwallet.sparrow.wallet.WalletController; import com.sparrowwallet.sparrow.wallet.WalletController;
import com.sparrowwallet.sparrow.wallet.WalletForm; import com.sparrowwallet.sparrow.wallet.WalletForm;
import de.codecentric.centerdevice.MenuToolkit; import de.codecentric.centerdevice.MenuToolkit;
import javafx.animation.*; import javafx.animation.*;
import javafx.application.Platform;
import javafx.concurrent.Worker; import javafx.concurrent.Worker;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
@ -39,7 +38,6 @@ import javafx.stage.FileChooser;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.util.Duration; import javafx.util.Duration;
import org.controlsfx.control.StatusBar; import org.controlsfx.control.StatusBar;
import org.controlsfx.tools.Platform;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
@ -80,6 +78,8 @@ public class AppController implements Initializable {
private ElectrumServer.ConnectionService connectionService; private ElectrumServer.ConnectionService connectionService;
public static Integer currentBlockHeight;
public static boolean showTxHexProperty; public static boolean showTxHexProperty;
@Override @Override
@ -190,7 +190,7 @@ public class AppController implements Initializable {
} }
private void setOsxApplicationMenu() { private void setOsxApplicationMenu() {
if(Platform.getCurrent().getPlatformId().toLowerCase().equals("mac")) { if(org.controlsfx.tools.Platform.getCurrent().getPlatformId().toLowerCase().equals("mac")) {
MenuToolkit tk = MenuToolkit.toolkit(); MenuToolkit tk = MenuToolkit.toolkit();
MenuItem preferences = new MenuItem("Preferences..."); MenuItem preferences = new MenuItem("Preferences...");
preferences.setOnAction(this::openPreferences); preferences.setOnAction(this::openPreferences);
@ -289,6 +289,10 @@ public class AppController implements Initializable {
} }
} }
public static Integer getCurrentBlockHeight() {
return currentBlockHeight;
}
public static void showErrorDialog(String title, String content) { public static void showErrorDialog(String title, String content) {
Alert alert = new Alert(Alert.AlertType.ERROR); Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(title); alert.setTitle(title);
@ -519,13 +523,13 @@ public class AppController implements Initializable {
private Tab addTransactionTab(String name, byte[] bytes) throws PSBTParseException, ParseException, TransactionParseException { private Tab addTransactionTab(String name, byte[] bytes) throws PSBTParseException, ParseException, TransactionParseException {
if(PSBT.isPSBT(bytes)) { if(PSBT.isPSBT(bytes)) {
PSBT psbt = new PSBT(bytes); PSBT psbt = new PSBT(bytes);
return addTransactionTab(name, null, psbt); return addTransactionTab(name, psbt);
} }
if(Transaction.isTransaction(bytes)) { if(Transaction.isTransaction(bytes)) {
try { try {
Transaction transaction = new Transaction(bytes); Transaction transaction = new Transaction(bytes);
return addTransactionTab(name, transaction, null); return addTransactionTab(name, transaction);
} catch(Exception e) { } catch(Exception e) {
throw new TransactionParseException(e.getMessage()); throw new TransactionParseException(e.getMessage());
} }
@ -534,15 +538,34 @@ public class AppController implements Initializable {
throw new ParseException("Not a valid PSBT or transaction", 0); throw new ParseException("Not a valid PSBT or transaction", 0);
} }
private Tab addTransactionTab(String name, Transaction transaction, PSBT psbt) { private Tab addTransactionTab(String name, Transaction transaction) {
return addTransactionTab(name, transaction, null, null);
}
private Tab addTransactionTab(String name, PSBT psbt) {
return addTransactionTab(name, psbt.getTransaction(), psbt, null);
}
private Tab addTransactionTab(BlockTransaction blockTransaction) {
return addTransactionTab(null, blockTransaction.getTransaction(), null, blockTransaction);
}
private Tab addTransactionTab(String name, Transaction transaction, PSBT psbt, BlockTransaction blockTransaction) {
for(Tab tab : tabs.getTabs()) {
TabData tabData = (TabData)tab.getUserData();
if(tabData instanceof TransactionTabData) {
TransactionTabData transactionTabData = (TransactionTabData)tabData;
if(transactionTabData.getTransaction() == transaction) {
return tab;
}
}
}
try { try {
String tabName = name; String tabName = name;
if(tabName == null || tabName.isEmpty()) { if(tabName == null || tabName.isEmpty()) {
if(transaction != null) { tabName = "[" + transaction.getTxId().toString().substring(0, 6) + "]";
tabName = "[" + transaction.getTxId().toString().substring(0, 6) + "]";
} else if(psbt != null) {
tabName = "[" + psbt.getTransaction().getTxId().toString().substring(0, 6) + "]";
}
} }
Tab tab = new Tab(tabName); Tab tab = new Tab(tabName);
@ -554,11 +577,9 @@ public class AppController implements Initializable {
tab.setContent(transactionLoader.load()); tab.setContent(transactionLoader.load());
TransactionController controller = transactionLoader.getController(); TransactionController controller = transactionLoader.getController();
if(transaction != null) { controller.setPSBT(psbt);
controller.setTransaction(transaction); controller.setBlockTransaction(blockTransaction);
} else if(psbt != null) { controller.setTransaction(transaction);
controller.setPSBT(psbt);
}
tabs.getTabs().add(tab); tabs.getTabs().add(tab);
return tab; return tab;
@ -672,6 +693,7 @@ public class AppController implements Initializable {
@Subscribe @Subscribe
public void newConnection(ConnectionEvent event) { public void newConnection(ConnectionEvent event) {
currentBlockHeight = event.getBlockHeight();
String banner = event.getServerBanner(); String banner = event.getServerBanner();
String status = "Connected: " + (banner == null ? "Server" : banner.split(System.lineSeparator(), 2)[0]) + " at height " + event.getBlockHeight(); String status = "Connected: " + (banner == null ? "Server" : banner.split(System.lineSeparator(), 2)[0]) + " at height " + event.getBlockHeight();
EventManager.get().post(new StatusEvent(status)); EventManager.get().post(new StatusEvent(status));
@ -686,7 +708,21 @@ public class AppController implements Initializable {
@Subscribe @Subscribe
public void newBlock(NewBlockEvent event) { public void newBlock(NewBlockEvent event) {
currentBlockHeight = event.getHeight();
String status = "Updating to new block height " + event.getHeight(); String status = "Updating to new block height " + event.getHeight();
EventManager.get().post(new StatusEvent(status)); EventManager.get().post(new StatusEvent(status));
} }
@Subscribe
public void viewTransaction(ViewTransactionEvent event) {
Tab tab = addTransactionTab(event.getBlockTransaction());
tabs.getSelectionModel().select(tab);
Platform.runLater(() -> {
if(event.getHashIndexEntry().getType().equals(HashIndexEntry.Type.INPUT)) {
EventManager.get().post(new TransactionInputSelectedEvent(event.getHashIndexEntry().getHashIndex().getIndex()));
} else {
EventManager.get().post(new TransactionOutputSelectedEvent(event.getHashIndexEntry().getHashIndex().getIndex()));
}
});
}
} }

View file

@ -6,7 +6,7 @@ import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.event.ReceiveActionEvent; import com.sparrowwallet.sparrow.event.ReceiveActionEvent;
import com.sparrowwallet.sparrow.event.ReceiveToEvent; import com.sparrowwallet.sparrow.event.ReceiveToEvent;
import com.sparrowwallet.sparrow.event.TransactionViewEvent; import com.sparrowwallet.sparrow.event.ViewTransactionEvent;
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5; import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
import com.sparrowwallet.sparrow.wallet.Entry; import com.sparrowwallet.sparrow.wallet.Entry;
import com.sparrowwallet.sparrow.wallet.HashIndexEntry; import com.sparrowwallet.sparrow.wallet.HashIndexEntry;
@ -159,7 +159,7 @@ public class AddressTreeTable extends TreeTableView<Entry> {
searchGlyph.setFontSize(12); searchGlyph.setFontSize(12);
viewTransactionButton.setGraphic(searchGlyph); viewTransactionButton.setGraphic(searchGlyph);
viewTransactionButton.setOnAction(event -> { viewTransactionButton.setOnAction(event -> {
EventManager.get().post(new TransactionViewEvent(hashIndexEntry.getBlockTransaction(), hashIndexEntry)); EventManager.get().post(new ViewTransactionEvent(hashIndexEntry.getBlockTransaction(), hashIndexEntry));
}); });
setGraphic(viewTransactionButton); setGraphic(viewTransactionButton);
} }

View file

@ -0,0 +1,13 @@
package com.sparrowwallet.sparrow.event;
public class TransactionInputSelectedEvent {
private final long index;
public TransactionInputSelectedEvent(long index) {
this.index = index;
}
public long getIndex() {
return index;
}
}

View file

@ -0,0 +1,13 @@
package com.sparrowwallet.sparrow.event;
public class TransactionOutputSelectedEvent {
private final long index;
public TransactionOutputSelectedEvent(long index) {
this.index = index;
}
public long getIndex() {
return index;
}
}

View file

@ -3,15 +3,15 @@ package com.sparrowwallet.sparrow.event;
import com.sparrowwallet.drongo.wallet.BlockTransaction; import com.sparrowwallet.drongo.wallet.BlockTransaction;
import com.sparrowwallet.sparrow.wallet.HashIndexEntry; import com.sparrowwallet.sparrow.wallet.HashIndexEntry;
public class TransactionViewEvent { public class ViewTransactionEvent {
public final BlockTransaction blockTransaction; public final BlockTransaction blockTransaction;
public final HashIndexEntry hashIndexEntry; public final HashIndexEntry hashIndexEntry;
public TransactionViewEvent(BlockTransaction blockTransaction) { public ViewTransactionEvent(BlockTransaction blockTransaction) {
this(blockTransaction, null); this(blockTransaction, null);
} }
public TransactionViewEvent(BlockTransaction blockTransaction, HashIndexEntry hashIndexEntry) { public ViewTransactionEvent(BlockTransaction blockTransaction, HashIndexEntry hashIndexEntry) {
this.blockTransaction = blockTransaction; this.blockTransaction = blockTransaction;
this.hashIndexEntry = hashIndexEntry; this.hashIndexEntry = hashIndexEntry;
} }

View file

@ -1,6 +1,7 @@
package com.sparrowwallet.sparrow.transaction; package com.sparrowwallet.sparrow.transaction;
import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.sparrow.AppController;
import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.control.CoinLabel; import com.sparrowwallet.sparrow.control.CoinLabel;
import com.sparrowwallet.sparrow.control.IdLabel; import com.sparrowwallet.sparrow.control.IdLabel;
@ -13,6 +14,7 @@ import tornadofx.control.DateTimePicker;
import tornadofx.control.Field; import tornadofx.control.Field;
import tornadofx.control.Fieldset; import tornadofx.control.Fieldset;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import tornadofx.control.Form;
import java.net.URL; import java.net.URL;
import java.time.*; import java.time.*;
@ -77,6 +79,15 @@ public class HeadersController extends TransactionFormController implements Init
@FXML @FXML
private CopyableLabel feeRate; private CopyableLabel feeRate;
@FXML
private Form blockchainForm;
@FXML
private CopyableLabel blockStatus;
@FXML
private CopyableLabel blockHeight;
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
EventManager.get().register(this); EventManager.get().register(this);
@ -97,6 +108,7 @@ public class HeadersController extends TransactionFormController implements Init
tx.setVersion(newValue); tx.setVersion(newValue);
EventManager.get().post(new TransactionChangedEvent(tx)); EventManager.get().post(new TransactionChangedEvent(tx));
}); });
version.setDisable(!headersForm.isEditable());
String type = "Legacy"; String type = "Legacy";
if(tx.isSegwit()) { if(tx.isSegwit()) {
@ -170,6 +182,12 @@ public class HeadersController extends TransactionFormController implements Init
EventManager.get().post(new TransactionChangedEvent(tx)); EventManager.get().post(new TransactionChangedEvent(tx));
}); });
locktimeNoneType.setDisable(!headersForm.isEditable());
locktimeBlockType.setDisable(!headersForm.isEditable());
locktimeDateType.setDisable(!headersForm.isEditable());
locktimeBlock.setDisable(!headersForm.isEditable());
locktimeDate.setDisable(!headersForm.isEditable());
size.setText(tx.getSize() + " B"); size.setText(tx.getSize() + " B");
virtualSize.setText(tx.getVirtualSize() + " vB"); virtualSize.setText(tx.getVirtualSize() + " vB");
@ -183,6 +201,20 @@ public class HeadersController extends TransactionFormController implements Init
double feeRateAmt = feeAmt.doubleValue() / tx.getVirtualSize(); double feeRateAmt = feeAmt.doubleValue() / tx.getVirtualSize();
feeRate.setText(String.format("%.2f", feeRateAmt) + " sats/vByte"); feeRate.setText(String.format("%.2f", feeRateAmt) + " sats/vByte");
} }
blockchainForm.managedProperty().bind(blockchainForm.visibleProperty());
blockchainForm.setVisible(headersForm.getBlockTransaction() != null);
if(headersForm.getBlockTransaction() != null) {
Integer currentHeight = AppController.getCurrentBlockHeight();
if(currentHeight == null) {
blockStatus.setText("Unknown");
} else {
int confirmations = currentHeight - headersForm.getBlockTransaction().getHeight() + 1;
blockStatus.setText(confirmations + " Confirmations");
}
blockHeight.setText(Integer.toString(headersForm.getBlockTransaction().getHeight()));
}
} }
private void updateTxId() { private void updateTxId() {

View file

@ -2,6 +2,7 @@ package com.sparrowwallet.sparrow.transaction;
import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.drongo.psbt.PSBT; import com.sparrowwallet.drongo.psbt.PSBT;
import com.sparrowwallet.drongo.wallet.BlockTransaction;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Node; import javafx.scene.Node;
@ -12,6 +13,10 @@ public class HeadersForm extends TransactionForm {
super(psbt); super(psbt);
} }
public HeadersForm(BlockTransaction blockTransaction) {
super(blockTransaction);
}
public HeadersForm(Transaction transaction) { public HeadersForm(Transaction transaction) {
super(transaction); super(transaction);
} }

View file

@ -277,6 +277,7 @@ public class InputController extends TransactionFormController implements Initia
} }
} }
}); });
rbf.setDisable(!inputForm.isEditable());
} }
private void initializeLocktimeFields(TransactionInput txInput) { private void initializeLocktimeFields(TransactionInput txInput) {
@ -348,6 +349,13 @@ public class InputController extends TransactionFormController implements Initia
locktimeRelativeSeconds.valueProperty().addListener((obs, oldValue, newValue) -> { locktimeRelativeSeconds.valueProperty().addListener((obs, oldValue, newValue) -> {
setRelativeLocktime(txInput, transaction); setRelativeLocktime(txInput, transaction);
}); });
locktimeNoneType.setDisable(!inputForm.isEditable());
locktimeAbsoluteType.setDisable(!inputForm.isEditable());
locktimeRelativeType.setDisable(!inputForm.isEditable());
locktimeRelativeBlocks.setDisable(!inputForm.isEditable());
locktimeRelativeSeconds.setDisable(!inputForm.isEditable());
locktimeRelativeCombo.setDisable(!inputForm.isEditable());
} }
private void updateAbsoluteLocktimeField(Transaction transaction) { private void updateAbsoluteLocktimeField(Transaction transaction) {

View file

@ -4,6 +4,7 @@ import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.drongo.protocol.TransactionInput; import com.sparrowwallet.drongo.protocol.TransactionInput;
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.wallet.BlockTransaction;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Node; import javafx.scene.Node;
@ -19,6 +20,11 @@ public class InputForm extends TransactionForm {
this.psbtInput = psbtInput; this.psbtInput = psbtInput;
} }
public InputForm(BlockTransaction blockTransaction, TransactionInput transactionInput) {
super(blockTransaction);
this.transactionInput = transactionInput;
}
public InputForm(Transaction transaction, TransactionInput transactionInput) { public InputForm(Transaction transaction, TransactionInput transactionInput) {
super(transaction); super(transaction);
this.transactionInput = transactionInput; this.transactionInput = transactionInput;

View file

@ -2,6 +2,7 @@ package com.sparrowwallet.sparrow.transaction;
import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.drongo.psbt.PSBT; import com.sparrowwallet.drongo.psbt.PSBT;
import com.sparrowwallet.drongo.wallet.BlockTransaction;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Node; import javafx.scene.Node;
@ -12,6 +13,10 @@ public class InputsForm extends TransactionForm {
super(psbt); super(psbt);
} }
public InputsForm(BlockTransaction blockTransaction) {
super(blockTransaction);
}
public InputsForm(Transaction transaction) { public InputsForm(Transaction transaction) {
super(transaction); super(transaction);
} }

View file

@ -4,6 +4,7 @@ import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.drongo.protocol.TransactionOutput; import com.sparrowwallet.drongo.protocol.TransactionOutput;
import com.sparrowwallet.drongo.psbt.PSBT; import com.sparrowwallet.drongo.psbt.PSBT;
import com.sparrowwallet.drongo.psbt.PSBTOutput; import com.sparrowwallet.drongo.psbt.PSBTOutput;
import com.sparrowwallet.drongo.wallet.BlockTransaction;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Node; import javafx.scene.Node;
@ -19,6 +20,11 @@ public class OutputForm extends TransactionForm {
this.psbtOutput = psbtOutput; this.psbtOutput = psbtOutput;
} }
public OutputForm(BlockTransaction blockTransaction, TransactionOutput transactionOutput) {
super(blockTransaction);
this.transactionOutput = transactionOutput;
}
public OutputForm(Transaction transaction, TransactionOutput transactionOutput) { public OutputForm(Transaction transaction, TransactionOutput transactionOutput) {
super(transaction); super(transaction);
this.transactionOutput = transactionOutput; this.transactionOutput = transactionOutput;

View file

@ -2,6 +2,7 @@ package com.sparrowwallet.sparrow.transaction;
import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.drongo.psbt.PSBT; import com.sparrowwallet.drongo.psbt.PSBT;
import com.sparrowwallet.drongo.wallet.BlockTransaction;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Node; import javafx.scene.Node;
@ -12,6 +13,10 @@ public class OutputsForm extends TransactionForm {
super(psbt); super(psbt);
} }
public OutputsForm(BlockTransaction blockTransaction) {
super(blockTransaction);
}
public OutputsForm(Transaction transaction) { public OutputsForm(Transaction transaction) {
super(transaction); super(transaction);
} }

View file

@ -6,11 +6,10 @@ import com.sparrowwallet.drongo.protocol.*;
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.PSBTOutput; import com.sparrowwallet.drongo.psbt.PSBTOutput;
import com.sparrowwallet.drongo.wallet.BlockTransaction;
import com.sparrowwallet.sparrow.AppController; import com.sparrowwallet.sparrow.AppController;
import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.event.TransactionChangedEvent; import com.sparrowwallet.sparrow.event.*;
import com.sparrowwallet.sparrow.event.TransactionTabChangedEvent;
import com.sparrowwallet.sparrow.event.TransactionTabSelectedEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.Node; import javafx.scene.Node;
@ -26,6 +25,8 @@ import org.fxmisc.richtext.CodeArea;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.List;
import java.util.Optional;
import java.util.ResourceBundle; import java.util.ResourceBundle;
public class TransactionController implements Initializable { public class TransactionController implements Initializable {
@ -47,6 +48,7 @@ public class TransactionController implements Initializable {
private Transaction transaction; private Transaction transaction;
private PSBT psbt; private PSBT psbt;
private BlockTransaction blockTransaction;
private int selectedInputIndex = -1; private int selectedInputIndex = -1;
private int selectedOutputIndex = -1; private int selectedOutputIndex = -1;
@ -62,11 +64,11 @@ public class TransactionController implements Initializable {
} }
private void initializeTxTree() { private void initializeTxTree() {
HeadersForm headersForm = (psbt == null ? new HeadersForm(transaction) : new HeadersForm(psbt)); HeadersForm headersForm = (psbt != null ? new HeadersForm(psbt) : (blockTransaction != null ? new HeadersForm(blockTransaction) : new HeadersForm(transaction)));
TreeItem<TransactionForm> rootItem = new TreeItem<>(headersForm); TreeItem<TransactionForm> rootItem = new TreeItem<>(headersForm);
rootItem.setExpanded(true); rootItem.setExpanded(true);
InputsForm inputsForm = (psbt == null ? new InputsForm(transaction) : new InputsForm(psbt)); InputsForm inputsForm = (psbt != null ? new InputsForm(psbt) : (blockTransaction != null ? new InputsForm(blockTransaction) : new InputsForm(transaction)));
TreeItem<TransactionForm> inputsItem = new TreeItem<>(inputsForm); TreeItem<TransactionForm> inputsItem = new TreeItem<>(inputsForm);
inputsItem.setExpanded(true); inputsItem.setExpanded(true);
for (TransactionInput txInput : transaction.getInputs()) { for (TransactionInput txInput : transaction.getInputs()) {
@ -74,12 +76,12 @@ public class TransactionController implements Initializable {
if (psbt != null && psbt.getPsbtInputs().size() > txInput.getIndex()) { if (psbt != null && psbt.getPsbtInputs().size() > txInput.getIndex()) {
psbtInput = psbt.getPsbtInputs().get(txInput.getIndex()); psbtInput = psbt.getPsbtInputs().get(txInput.getIndex());
} }
InputForm inputForm = (psbt == null ? new InputForm(transaction, txInput) : new InputForm(psbt, psbtInput)); InputForm inputForm = (psbt != null ? new InputForm(psbt, psbtInput) : (blockTransaction != null ? new InputForm(blockTransaction, txInput) : new InputForm(transaction, txInput)));
TreeItem<TransactionForm> inputItem = new TreeItem<>(inputForm); TreeItem<TransactionForm> inputItem = new TreeItem<>(inputForm);
inputsItem.getChildren().add(inputItem); inputsItem.getChildren().add(inputItem);
} }
OutputsForm outputsForm = (psbt == null ? new OutputsForm(transaction) : new OutputsForm(psbt)); OutputsForm outputsForm = (psbt != null ? new OutputsForm(psbt) : (blockTransaction != null ? new OutputsForm(blockTransaction) : new OutputsForm(transaction)));
TreeItem<TransactionForm> outputsItem = new TreeItem<>(outputsForm); TreeItem<TransactionForm> outputsItem = new TreeItem<>(outputsForm);
outputsItem.setExpanded(true); outputsItem.setExpanded(true);
for (TransactionOutput txOutput : transaction.getOutputs()) { for (TransactionOutput txOutput : transaction.getOutputs()) {
@ -87,7 +89,7 @@ public class TransactionController implements Initializable {
if (psbt != null && psbt.getPsbtOutputs().size() > txOutput.getIndex()) { if (psbt != null && psbt.getPsbtOutputs().size() > txOutput.getIndex()) {
psbtOutput = psbt.getPsbtOutputs().get(txOutput.getIndex()); psbtOutput = psbt.getPsbtOutputs().get(txOutput.getIndex());
} }
OutputForm outputForm = (psbt == null ? new OutputForm(transaction, txOutput) : new OutputForm(psbt, psbtOutput)); OutputForm outputForm = (psbt != null ? new OutputForm(psbt, psbtOutput) : (blockTransaction != null ? new OutputForm(blockTransaction, txOutput) : new OutputForm(transaction, txOutput)));
TreeItem<TransactionForm> outputItem = new TreeItem<>(outputForm); TreeItem<TransactionForm> outputItem = new TreeItem<>(outputForm);
outputsItem.getChildren().add(outputItem); outputsItem.getChildren().add(outputItem);
} }
@ -229,19 +231,20 @@ public class TransactionController implements Initializable {
return cursor; return cursor;
} }
public void setPSBT(PSBT psbt) {
this.psbt = psbt;
this.transaction = psbt.getTransaction();
initializeView();
}
public void setTransaction(Transaction transaction) { public void setTransaction(Transaction transaction) {
this.transaction = transaction; this.transaction = transaction;
initializeView(); initializeView();
} }
public void setPSBT(PSBT psbt) {
this.psbt = psbt;
}
public void setBlockTransaction(BlockTransaction blockTransaction) {
this.blockTransaction = blockTransaction;
}
@Subscribe @Subscribe
public void transactionChanged(TransactionChangedEvent event) { public void transactionChanged(TransactionChangedEvent event) {
if(event.getTransaction().equals(transaction)) { if(event.getTransaction().equals(transaction)) {
@ -259,4 +262,25 @@ public class TransactionController implements Initializable {
public void tabChanged(TransactionTabChangedEvent event) { public void tabChanged(TransactionTabChangedEvent event) {
transactionMasterDetail.setShowDetailNode(event.isTxHexVisible()); transactionMasterDetail.setShowDetailNode(event.isTxHexVisible());
} }
@Subscribe
public void inputSelected(TransactionInputSelectedEvent event) {
Optional<TreeItem<TransactionForm>> optionalInputs = txtree.getRoot().getChildren().stream().filter(item -> item.getValue() instanceof InputsForm).findFirst();
selectItem(optionalInputs, (int)event.getIndex());
}
@Subscribe
public void outputSelected(TransactionOutputSelectedEvent event) {
Optional<TreeItem<TransactionForm>> optionalOutputs = txtree.getRoot().getChildren().stream().filter(item -> item.getValue() instanceof OutputsForm).findFirst();
selectItem(optionalOutputs, (int)event.getIndex());
}
private void selectItem(Optional<TreeItem<TransactionForm>> optionalParent, int index) {
if(optionalParent.isPresent()) {
List<TreeItem<TransactionForm>> inputs = optionalParent.get().getChildren();
if(inputs.size() > index) {
txtree.getSelectionModel().select(inputs.get(index));
}
}
}
} }

View file

@ -2,6 +2,7 @@ package com.sparrowwallet.sparrow.transaction;
import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.drongo.psbt.PSBT; import com.sparrowwallet.drongo.psbt.PSBT;
import com.sparrowwallet.drongo.wallet.BlockTransaction;
import javafx.scene.Node; import javafx.scene.Node;
import java.io.IOException; import java.io.IOException;
@ -9,12 +10,18 @@ import java.io.IOException;
public abstract class TransactionForm { public abstract class TransactionForm {
private Transaction transaction; private Transaction transaction;
private PSBT psbt; private PSBT psbt;
private BlockTransaction blockTransaction;
public TransactionForm(PSBT psbt) { public TransactionForm(PSBT psbt) {
this.transaction = psbt.getTransaction(); this.transaction = psbt.getTransaction();
this.psbt = psbt; this.psbt = psbt;
} }
public TransactionForm(BlockTransaction blockTransaction) {
this.transaction = blockTransaction.getTransaction();
this.blockTransaction = blockTransaction;
}
public TransactionForm(Transaction transaction) { public TransactionForm(Transaction transaction) {
this.transaction = transaction; this.transaction = transaction;
} }
@ -27,5 +34,13 @@ public abstract class TransactionForm {
return psbt; return psbt;
} }
public BlockTransaction getBlockTransaction() {
return blockTransaction;
}
public boolean isEditable() {
return blockTransaction == null;
}
public abstract Node getContents() throws IOException; public abstract Node getContents() throws IOException;
} }

View file

@ -124,5 +124,6 @@ public class WalletForm {
@Subscribe @Subscribe
public void newBlock(NewBlockEvent event) { public void newBlock(NewBlockEvent event) {
refreshHistory(); refreshHistory();
wallet.setStoredBlockHeight(event.getHeight());
} }
} }

View file

@ -99,13 +99,13 @@
<Separator GridPane.columnIndex="0" GridPane.rowIndex="5" GridPane.columnSpan="2" styleClass="form-separator"/> <Separator GridPane.columnIndex="0" GridPane.rowIndex="5" GridPane.columnSpan="2" styleClass="form-separator"/>
<Form GridPane.columnIndex="0" GridPane.rowIndex="6"> <Form fx:id="blockchainForm" GridPane.columnIndex="0" GridPane.rowIndex="6">
<Fieldset text="Blockchain" inputGrow="SOMETIMES"> <Fieldset text="Blockchain" inputGrow="SOMETIMES">
<Field text="Status:"> <Field text="Status:">
<CopyableLabel fx:id="blockStatusField" /> <CopyableLabel fx:id="blockStatus" />
</Field> </Field>
<Field text="Block:"> <Field text="Block Height:">
<CopyableLabel fx:id="blockField" /> <CopyableLabel fx:id="blockHeight" />
</Field> </Field>
</Fieldset> </Fieldset>
</Form> </Form>