Browse Source

add coinlabel, addresslabel

bwt
Craig Raw 5 years ago
parent
commit
e7f30bdfe1
  1. 2
      drongo
  2. 79
      src/main/java/com/sparrowwallet/sparrow/control/AddressLabel.java
  3. 88
      src/main/java/com/sparrowwallet/sparrow/control/CoinLabel.java
  4. 7
      src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java
  5. 13
      src/main/java/com/sparrowwallet/sparrow/transaction/InputController.java
  6. 6
      src/main/java/com/sparrowwallet/sparrow/transaction/InputsController.java
  7. 11
      src/main/java/com/sparrowwallet/sparrow/transaction/OutputController.java
  8. 5
      src/main/java/com/sparrowwallet/sparrow/transaction/OutputsController.java
  9. 3
      src/main/resources/com/sparrowwallet/sparrow/transaction/headers.fxml
  10. 6
      src/main/resources/com/sparrowwallet/sparrow/transaction/input.fxml
  11. 3
      src/main/resources/com/sparrowwallet/sparrow/transaction/inputs.fxml
  12. 7
      src/main/resources/com/sparrowwallet/sparrow/transaction/output.fxml
  13. 3
      src/main/resources/com/sparrowwallet/sparrow/transaction/outputs.fxml

2
drongo

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

79
src/main/java/com/sparrowwallet/sparrow/control/AddressLabel.java

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

88
src/main/java/com/sparrowwallet/sparrow/control/CoinLabel.java

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

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

@ -2,6 +2,7 @@ package com.sparrowwallet.sparrow.transaction;
import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.control.CoinLabel;
import com.sparrowwallet.sparrow.control.IdLabel;
import com.sparrowwallet.sparrow.control.CopyableLabel;
import com.sparrowwallet.sparrow.event.TransactionChangedEvent;
@ -71,7 +72,7 @@ public class HeadersController extends TransactionFormController implements Init
private CopyableLabel virtualSize;
@FXML
private CopyableLabel fee;
private CoinLabel fee;
@FXML
private CopyableLabel feeRate;
@ -178,11 +179,9 @@ public class HeadersController extends TransactionFormController implements Init
}
if(feeAmt != null) {
fee.setText(feeAmt + " sats");
fee.setValue(feeAmt);
double feeRateAmt = feeAmt.doubleValue() / tx.getVirtualSize();
feeRate.setText(String.format("%.2f", feeRateAmt) + " sats/vByte");
} else {
fee.setText("Unknown");
}
}

13
src/main/java/com/sparrowwallet/sparrow/transaction/InputController.java

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

6
src/main/java/com/sparrowwallet/sparrow/transaction/InputsController.java

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

11
src/main/java/com/sparrowwallet/sparrow/transaction/OutputController.java

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

5
src/main/java/com/sparrowwallet/sparrow/transaction/OutputsController.java

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

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

@ -13,6 +13,7 @@
<?import org.controlsfx.control.SegmentedButton?>
<?import com.sparrowwallet.sparrow.control.CopyableLabel?>
<?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">
<padding>
@ -92,7 +93,7 @@
<Form GridPane.columnIndex="1" GridPane.rowIndex="4">
<Fieldset text="Fee" inputGrow="SOMETIMES">
<Field text="Amount:">
<CopyableLabel fx:id="fee" />
<CoinLabel fx:id="fee" />
</Field>
<Field text="Rate:">
<CopyableLabel fx:id="feeRate" />

6
src/main/resources/com/sparrowwallet/sparrow/transaction/input.fxml

@ -14,6 +14,8 @@
<?import com.sparrowwallet.sparrow.control.RelativeTimelockSpinner?>
<?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="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>
@ -40,9 +42,9 @@
</Button>
</Field>
<Field text="Spends:">
<CopyableLabel fx:id="spends" />
<CoinLabel fx:id="spends" />
<CopyableLabel fx:id="from" text="from" />
<IdLabel fx:id="address" />
<AddressLabel fx:id="address" />
</Field>
</Fieldset>
</Form>

3
src/main/resources/com/sparrowwallet/sparrow/transaction/inputs.fxml

@ -6,6 +6,7 @@
<?import tornadofx.control.*?>
<?import javafx.scene.chart.PieChart?>
<?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">
<padding>
@ -26,7 +27,7 @@
<CopyableLabel fx:id="count" />
</Field>
<Field text="Total:">
<CopyableLabel fx:id="total" />
<CoinLabel fx:id="total" />
</Field>
</Fieldset>
</Form>

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

@ -12,7 +12,8 @@
<?import tornadofx.control.Form?>
<?import javafx.geometry.Insets?>
<?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">
<padding>
@ -31,9 +32,9 @@
<Form GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.rowIndex="0">
<Fieldset fx:id="outputFieldset" inputGrow="SOMETIMES" text="Output">
<Field text="Sends:">
<CopyableLabel fx:id="value"/>
<CoinLabel fx:id="value"/>
<CopyableLabel fx:id="to" text="to" />
<IdLabel fx:id="address" />
<AddressLabel fx:id="address" />
</Field>
</Fieldset>
</Form>

3
src/main/resources/com/sparrowwallet/sparrow/transaction/outputs.fxml

@ -6,6 +6,7 @@
<?import tornadofx.control.*?>
<?import javafx.scene.chart.PieChart?>
<?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">
<padding>
@ -26,7 +27,7 @@
<CopyableLabel fx:id="count" />
</Field>
<Field text="Total:">
<CopyableLabel fx:id="total" />
<CoinLabel fx:id="total" />
</Field>
</Fieldset>
</Form>

Loading…
Cancel
Save