add coinlabel, addresslabel

This commit is contained in:
Craig Raw 2020-04-10 17:00:09 +02:00
parent 4046555db8
commit e7f30bdfe1
13 changed files with 202 additions and 31 deletions

2
drongo

@ -1 +1 @@
Subproject commit 2f5655708df1b7722dfb4098cd9c79aad1a35886 Subproject commit 14767c3250281d52c1b7da21c1ab0dc83076fda8

View file

@ -0,0 +1,79 @@
package com.sparrowwallet.sparrow.control;
import com.sparrowwallet.drongo.Utils;
import com.sparrowwallet.drongo.address.Address;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tooltip;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
public class AddressLabel extends IdLabel {
private final ObjectProperty<Address> addressProperty = new SimpleObjectProperty<>();
private Tooltip tooltip;
private AddressContextMenu contextMenu;
public AddressLabel() {
this("");
}
public AddressLabel(String text) {
super(text);
addressProperty().addListener((observable, oldValue, newValue) -> {
setAddressAsText(newValue);
contextMenu.copyHex.setText("Copy " + newValue.getOutputScriptDataType());
});
tooltip = new Tooltip();
contextMenu = new AddressContextMenu();
}
public final ObjectProperty<Address> addressProperty() {
return addressProperty;
}
public final Address getAddress() {
return addressProperty.get();
}
public final void setAddress(Address value) {
this.addressProperty.set(value);
}
private void setAddressAsText(Address address) {
if(address != null) {
tooltip.setText(address.getScriptType() + " " + Utils.bytesToHex(address.getOutputScriptData()));
setTooltip(tooltip);
setContextMenu(contextMenu);
setText(address.toString());
}
}
private class AddressContextMenu extends ContextMenu {
private MenuItem copyAddress;
private MenuItem copyHex;
public AddressContextMenu() {
copyAddress = new MenuItem("Copy Address");
copyAddress.setOnAction(AE -> {
hide();
ClipboardContent content = new ClipboardContent();
content.putString(getAddress().toString());
Clipboard.getSystemClipboard().setContent(content);
});
copyHex = new MenuItem("Copy Script Output Bytes");
copyHex.setOnAction(AE -> {
hide();
ClipboardContent content = new ClipboardContent();
content.putString(Utils.bytesToHex(getAddress().getOutputScriptData()));
Clipboard.getSystemClipboard().setContent(content);
});
getItems().addAll(copyAddress, copyHex);
}
}
}

View file

@ -0,0 +1,88 @@
package com.sparrowwallet.sparrow.control;
import com.sparrowwallet.drongo.protocol.Transaction;
import javafx.beans.property.LongProperty;
import javafx.beans.property.SimpleLongProperty;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tooltip;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
public class CoinLabel extends CopyableLabel {
public static final int MAX_SATS_SHOWN = 1000000;
private DecimalFormat btcFormat = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
private final LongProperty value = new SimpleLongProperty();
private Tooltip tooltip;
private CoinContextMenu contextMenu;
public CoinLabel() {
this("Unknown");
}
public CoinLabel(String text) {
super(text);
btcFormat.setMaximumFractionDigits(8);
valueProperty().addListener((observable, oldValue, newValue) -> setValueAsText((Long)newValue));
tooltip = new Tooltip();
contextMenu = new CoinContextMenu();
}
public final LongProperty valueProperty() {
return value;
}
public final long getValue() {
return value.get();
}
public final void setValue(long value) {
this.value.set(value);
}
private void setValueAsText(Long value) {
setTooltip(tooltip);
setContextMenu(contextMenu);
String satsValue = String.format(Locale.ENGLISH, "%,d",value) + " sats";
String btcValue = btcFormat.format(value.doubleValue() / Transaction.SATOSHIS_PER_BITCOIN) + " BTC";
if(value > MAX_SATS_SHOWN) {
tooltip.setText(satsValue);
setText(btcValue);
} else {
tooltip.setText(btcValue);
setText(satsValue);
}
}
private class CoinContextMenu extends ContextMenu {
private MenuItem copySatsValue;
private MenuItem copyBtcValue;
public CoinContextMenu() {
copySatsValue = new MenuItem("Copy Value in Satoshis");
copySatsValue.setOnAction(AE -> {
hide();
ClipboardContent content = new ClipboardContent();
content.putString(Long.toString(getValue()));
Clipboard.getSystemClipboard().setContent(content);
});
copyBtcValue = new MenuItem("Copy Value in BTC");
copyBtcValue.setOnAction(AE -> {
hide();
ClipboardContent content = new ClipboardContent();
content.putString(btcFormat.format((double)getValue() / Transaction.SATOSHIS_PER_BITCOIN));
Clipboard.getSystemClipboard().setContent(content);
});
getItems().addAll(copySatsValue, copyBtcValue);
}
}
}

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.sparrow.EventManager; import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.control.CoinLabel;
import com.sparrowwallet.sparrow.control.IdLabel; import com.sparrowwallet.sparrow.control.IdLabel;
import com.sparrowwallet.sparrow.control.CopyableLabel; import com.sparrowwallet.sparrow.control.CopyableLabel;
import com.sparrowwallet.sparrow.event.TransactionChangedEvent; import com.sparrowwallet.sparrow.event.TransactionChangedEvent;
@ -71,7 +72,7 @@ public class HeadersController extends TransactionFormController implements Init
private CopyableLabel virtualSize; private CopyableLabel virtualSize;
@FXML @FXML
private CopyableLabel fee; private CoinLabel fee;
@FXML @FXML
private CopyableLabel feeRate; private CopyableLabel feeRate;
@ -178,11 +179,9 @@ public class HeadersController extends TransactionFormController implements Init
} }
if(feeAmt != null) { if(feeAmt != null) {
fee.setText(feeAmt + " sats"); fee.setValue(feeAmt);
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");
} else {
fee.setText("Unknown");
} }
} }

View file

@ -6,9 +6,7 @@ import com.sparrowwallet.drongo.crypto.ECKey;
import com.sparrowwallet.drongo.protocol.*; import com.sparrowwallet.drongo.protocol.*;
import com.sparrowwallet.drongo.psbt.PSBTInput; import com.sparrowwallet.drongo.psbt.PSBTInput;
import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.control.IdLabel; import com.sparrowwallet.sparrow.control.*;
import com.sparrowwallet.sparrow.control.CopyableLabel;
import com.sparrowwallet.sparrow.control.RelativeTimelockSpinner;
import com.sparrowwallet.sparrow.event.TransactionChangedEvent; import com.sparrowwallet.sparrow.event.TransactionChangedEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
@ -40,13 +38,13 @@ public class InputController extends TransactionFormController implements Initia
private Button outpointSelect; private Button outpointSelect;
@FXML @FXML
private CopyableLabel spends; private CoinLabel spends;
@FXML @FXML
private CopyableLabel from; private CopyableLabel from;
@FXML @FXML
private IdLabel address; private AddressLabel address;
@FXML @FXML
private CodeArea scriptSigArea; private CodeArea scriptSigArea;
@ -127,7 +125,6 @@ public class InputController extends TransactionFormController implements Initia
inputFieldset.setText("Input #" + txInput.getIndex()); inputFieldset.setText("Input #" + txInput.getIndex());
outpoint.setText(txInput.getOutpoint().getHash().toString() + ":" + txInput.getOutpoint().getIndex()); outpoint.setText(txInput.getOutpoint().getHash().toString() + ":" + txInput.getOutpoint().getIndex());
spends.setText("Unknown");
from.setVisible(false); from.setVisible(false);
if(psbtInput != null) { if(psbtInput != null) {
TransactionOutput output = null; TransactionOutput output = null;
@ -138,12 +135,12 @@ public class InputController extends TransactionFormController implements Initia
} }
if(output != null) { if(output != null) {
spends.setText(output.getValue() + " sats"); spends.setValue(output.getValue());
try { try {
Address[] addresses = output.getScript().getToAddresses(); Address[] addresses = output.getScript().getToAddresses();
from.setVisible(true); from.setVisible(true);
if(addresses.length == 1) { if(addresses.length == 1) {
address.setText(addresses[0].getAddress()); address.setAddress(addresses[0]);
} else { } else {
address.setText("multiple addresses"); address.setText("multiple addresses");
} }

View file

@ -2,6 +2,7 @@ package com.sparrowwallet.sparrow.transaction;
import com.sparrowwallet.drongo.protocol.*; import com.sparrowwallet.drongo.protocol.*;
import com.sparrowwallet.drongo.psbt.PSBTInput; import com.sparrowwallet.drongo.psbt.PSBTInput;
import com.sparrowwallet.sparrow.control.CoinLabel;
import com.sparrowwallet.sparrow.control.CopyableLabel; import com.sparrowwallet.sparrow.control.CopyableLabel;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
@ -19,7 +20,7 @@ public class InputsController extends TransactionFormController implements Initi
private CopyableLabel count; private CopyableLabel count;
@FXML @FXML
private CopyableLabel total; private CoinLabel total;
@FXML @FXML
private CopyableLabel signatures; private CopyableLabel signatures;
@ -41,7 +42,6 @@ public class InputsController extends TransactionFormController implements Initi
Transaction tx = inputsForm.getTransaction(); Transaction tx = inputsForm.getTransaction();
count.setText(Integer.toString(tx.getInputs().size())); count.setText(Integer.toString(tx.getInputs().size()));
total.setText("Unknown");
signatures.setText("Unknown"); signatures.setText("Unknown");
if(inputsForm.getPsbt() != null) { if(inputsForm.getPsbt() != null) {
@ -84,7 +84,7 @@ public class InputsController extends TransactionFormController implements Initi
for(TransactionOutput output : outputs) { for(TransactionOutput output : outputs) {
totalAmt += output.getValue(); totalAmt += output.getValue();
} }
total.setText(totalAmt + " sats"); total.setValue(totalAmt);
if(showDenominator) { if(showDenominator) {
signatures.setText(foundSigs + "/" + reqSigs); signatures.setText(foundSigs + "/" + reqSigs);
} else { } else {

View file

@ -3,7 +3,8 @@ package com.sparrowwallet.sparrow.transaction;
import com.sparrowwallet.drongo.address.Address; import com.sparrowwallet.drongo.address.Address;
import com.sparrowwallet.drongo.protocol.NonStandardScriptException; import com.sparrowwallet.drongo.protocol.NonStandardScriptException;
import com.sparrowwallet.drongo.protocol.TransactionOutput; import com.sparrowwallet.drongo.protocol.TransactionOutput;
import com.sparrowwallet.sparrow.control.IdLabel; import com.sparrowwallet.sparrow.control.AddressLabel;
import com.sparrowwallet.sparrow.control.CoinLabel;
import com.sparrowwallet.sparrow.control.CopyableLabel; import com.sparrowwallet.sparrow.control.CopyableLabel;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
@ -20,13 +21,13 @@ public class OutputController extends TransactionFormController implements Initi
private Fieldset outputFieldset; private Fieldset outputFieldset;
@FXML @FXML
private CopyableLabel value; private CoinLabel value;
@FXML @FXML
private CopyableLabel to; private CopyableLabel to;
@FXML @FXML
private IdLabel address; private AddressLabel address;
@FXML @FXML
private CodeArea scriptPubKeyArea; private CodeArea scriptPubKeyArea;
@ -41,13 +42,13 @@ public class OutputController extends TransactionFormController implements Initi
outputFieldset.setText("Output #" + txOutput.getIndex()); outputFieldset.setText("Output #" + txOutput.getIndex());
value.setText(txOutput.getValue() + " sats"); value.setValue(txOutput.getValue());
to.setVisible(false); to.setVisible(false);
try { try {
Address[] addresses = txOutput.getScript().getToAddresses(); Address[] addresses = txOutput.getScript().getToAddresses();
to.setVisible(true); to.setVisible(true);
if(addresses.length == 1) { if(addresses.length == 1) {
address.setText(addresses[0].getAddress()); address.setAddress(addresses[0]);
} else { } else {
address.setText("multiple addresses"); address.setText("multiple addresses");
} }

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.protocol.TransactionOutput; import com.sparrowwallet.drongo.protocol.TransactionOutput;
import com.sparrowwallet.sparrow.control.CoinLabel;
import com.sparrowwallet.sparrow.control.CopyableLabel; import com.sparrowwallet.sparrow.control.CopyableLabel;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
@ -17,7 +18,7 @@ public class OutputsController extends TransactionFormController implements Init
private CopyableLabel count; private CopyableLabel count;
@FXML @FXML
private CopyableLabel total; private CoinLabel total;
@FXML @FXML
private PieChart outputsPie; private PieChart outputsPie;
@ -40,7 +41,7 @@ public class OutputsController extends TransactionFormController implements Init
for(TransactionOutput output : tx.getOutputs()) { for(TransactionOutput output : tx.getOutputs()) {
totalAmt += output.getValue(); totalAmt += output.getValue();
} }
total.setText(totalAmt + " sats"); total.setValue(totalAmt);
if(totalAmt > 0) { if(totalAmt > 0) {
addPieData(outputsPie, tx.getOutputs()); addPieData(outputsPie, tx.getOutputs());

View file

@ -13,6 +13,7 @@
<?import org.controlsfx.control.SegmentedButton?> <?import org.controlsfx.control.SegmentedButton?>
<?import com.sparrowwallet.sparrow.control.CopyableLabel?> <?import com.sparrowwallet.sparrow.control.CopyableLabel?>
<?import com.sparrowwallet.sparrow.control.IdLabel?> <?import com.sparrowwallet.sparrow.control.IdLabel?>
<?import com.sparrowwallet.sparrow.control.CoinLabel?>
<GridPane hgap="10.0" prefHeight="350.0" prefWidth="600.0" vgap="10.0" alignment="TOP_CENTER" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.HeadersController" stylesheets="@headers.css, @../general.css"> <GridPane hgap="10.0" prefHeight="350.0" prefWidth="600.0" vgap="10.0" alignment="TOP_CENTER" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.HeadersController" stylesheets="@headers.css, @../general.css">
<padding> <padding>
@ -92,7 +93,7 @@
<Form GridPane.columnIndex="1" GridPane.rowIndex="4"> <Form GridPane.columnIndex="1" GridPane.rowIndex="4">
<Fieldset text="Fee" inputGrow="SOMETIMES"> <Fieldset text="Fee" inputGrow="SOMETIMES">
<Field text="Amount:"> <Field text="Amount:">
<CopyableLabel fx:id="fee" /> <CoinLabel fx:id="fee" />
</Field> </Field>
<Field text="Rate:"> <Field text="Rate:">
<CopyableLabel fx:id="feeRate" /> <CopyableLabel fx:id="feeRate" />

View file

@ -14,6 +14,8 @@
<?import com.sparrowwallet.sparrow.control.RelativeTimelockSpinner?> <?import com.sparrowwallet.sparrow.control.RelativeTimelockSpinner?>
<?import com.sparrowwallet.sparrow.control.CopyableLabel?> <?import com.sparrowwallet.sparrow.control.CopyableLabel?>
<?import com.sparrowwallet.sparrow.control.IdLabel?> <?import com.sparrowwallet.sparrow.control.IdLabel?>
<?import com.sparrowwallet.sparrow.control.CoinLabel?>
<?import com.sparrowwallet.sparrow.control.AddressLabel?>
<GridPane alignment="TOP_CENTER" hgap="10.0" prefHeight="500.0" prefWidth="620.0" stylesheets="@input.css, @script.css, @../general.css" vgap="10.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.InputController"> <GridPane alignment="TOP_CENTER" hgap="10.0" prefHeight="500.0" prefWidth="620.0" stylesheets="@input.css, @script.css, @../general.css" vgap="10.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.InputController">
<padding> <padding>
@ -40,9 +42,9 @@
</Button> </Button>
</Field> </Field>
<Field text="Spends:"> <Field text="Spends:">
<CopyableLabel fx:id="spends" /> <CoinLabel fx:id="spends" />
<CopyableLabel fx:id="from" text="from" /> <CopyableLabel fx:id="from" text="from" />
<IdLabel fx:id="address" /> <AddressLabel fx:id="address" />
</Field> </Field>
</Fieldset> </Fieldset>
</Form> </Form>

View file

@ -6,6 +6,7 @@
<?import tornadofx.control.*?> <?import tornadofx.control.*?>
<?import javafx.scene.chart.PieChart?> <?import javafx.scene.chart.PieChart?>
<?import com.sparrowwallet.sparrow.control.CopyableLabel?> <?import com.sparrowwallet.sparrow.control.CopyableLabel?>
<?import com.sparrowwallet.sparrow.control.CoinLabel?>
<GridPane alignment="TOP_CENTER" hgap="10.0" prefHeight="500.0" prefWidth="600.0" stylesheets="@inputs.css, @../general.css" vgap="10.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.InputsController"> <GridPane alignment="TOP_CENTER" hgap="10.0" prefHeight="500.0" prefWidth="600.0" stylesheets="@inputs.css, @../general.css" vgap="10.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.InputsController">
<padding> <padding>
@ -26,7 +27,7 @@
<CopyableLabel fx:id="count" /> <CopyableLabel fx:id="count" />
</Field> </Field>
<Field text="Total:"> <Field text="Total:">
<CopyableLabel fx:id="total" /> <CoinLabel fx:id="total" />
</Field> </Field>
</Fieldset> </Fieldset>
</Form> </Form>

View file

@ -12,7 +12,8 @@
<?import tornadofx.control.Form?> <?import tornadofx.control.Form?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import com.sparrowwallet.sparrow.control.CopyableLabel?> <?import com.sparrowwallet.sparrow.control.CopyableLabel?>
<?import com.sparrowwallet.sparrow.control.IdLabel?> <?import com.sparrowwallet.sparrow.control.CoinLabel?>
<?import com.sparrowwallet.sparrow.control.AddressLabel?>
<GridPane alignment="TOP_CENTER" hgap="10.0" prefHeight="500.0" prefWidth="600.0" stylesheets="@output.css, @script.css, @../general.css" vgap="10.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.OutputController"> <GridPane alignment="TOP_CENTER" hgap="10.0" prefHeight="500.0" prefWidth="600.0" stylesheets="@output.css, @script.css, @../general.css" vgap="10.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.OutputController">
<padding> <padding>
@ -31,9 +32,9 @@
<Form GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="0"> <Form GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="0">
<Fieldset fx:id="outputFieldset" inputGrow="SOMETIMES" text="Output"> <Fieldset fx:id="outputFieldset" inputGrow="SOMETIMES" text="Output">
<Field text="Sends:"> <Field text="Sends:">
<CopyableLabel fx:id="value"/> <CoinLabel fx:id="value"/>
<CopyableLabel fx:id="to" text="to" /> <CopyableLabel fx:id="to" text="to" />
<IdLabel fx:id="address" /> <AddressLabel fx:id="address" />
</Field> </Field>
</Fieldset> </Fieldset>
</Form> </Form>

View file

@ -6,6 +6,7 @@
<?import tornadofx.control.*?> <?import tornadofx.control.*?>
<?import javafx.scene.chart.PieChart?> <?import javafx.scene.chart.PieChart?>
<?import com.sparrowwallet.sparrow.control.CopyableLabel?> <?import com.sparrowwallet.sparrow.control.CopyableLabel?>
<?import com.sparrowwallet.sparrow.control.CoinLabel?>
<GridPane alignment="TOP_CENTER" hgap="10.0" prefHeight="500.0" prefWidth="600.0" stylesheets="@outputs.css, @../general.css" vgap="10.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.OutputsController"> <GridPane alignment="TOP_CENTER" hgap="10.0" prefHeight="500.0" prefWidth="600.0" stylesheets="@outputs.css, @../general.css" vgap="10.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.transaction.OutputsController">
<padding> <padding>
@ -26,7 +27,7 @@
<CopyableLabel fx:id="count" /> <CopyableLabel fx:id="count" />
</Field> </Field>
<Field text="Total:"> <Field text="Total:">
<CopyableLabel fx:id="total" /> <CoinLabel fx:id="total" />
</Field> </Field>
</Fieldset> </Fieldset>
</Form> </Form>