|
|
@ -1,11 +1,14 @@ |
|
|
|
package com.sparrowwallet.sparrow.wallet; |
|
|
|
|
|
|
|
import com.csvreader.CsvWriter; |
|
|
|
import com.google.common.eventbus.Subscribe; |
|
|
|
import com.sparrowwallet.drongo.BitcoinUnit; |
|
|
|
import com.sparrowwallet.drongo.protocol.Transaction; |
|
|
|
import com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex; |
|
|
|
import com.sparrowwallet.sparrow.AppServices; |
|
|
|
import com.sparrowwallet.sparrow.EventManager; |
|
|
|
import com.sparrowwallet.sparrow.control.CoinLabel; |
|
|
|
import com.sparrowwallet.sparrow.control.EntryCell; |
|
|
|
import com.sparrowwallet.sparrow.control.UtxosChart; |
|
|
|
import com.sparrowwallet.sparrow.control.UtxosTreeTable; |
|
|
|
import com.sparrowwallet.sparrow.event.*; |
|
|
@ -17,14 +20,23 @@ import javafx.fxml.FXML; |
|
|
|
import javafx.fxml.Initializable; |
|
|
|
import javafx.scene.control.Button; |
|
|
|
import javafx.scene.control.Tooltip; |
|
|
|
|
|
|
|
import javafx.stage.FileChooser; |
|
|
|
import javafx.stage.Stage; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.net.URL; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Locale; |
|
|
|
import java.util.ResourceBundle; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
public class UtxosController extends WalletFormController implements Initializable { |
|
|
|
private static final Logger log = LoggerFactory.getLogger(UtxosController.class); |
|
|
|
|
|
|
|
@FXML |
|
|
|
private UtxosTreeTable utxosTable; |
|
|
@ -96,6 +108,42 @@ public class UtxosController extends WalletFormController implements Initializab |
|
|
|
utxosTable.getSelectionModel().clearSelection(); |
|
|
|
} |
|
|
|
|
|
|
|
public void exportUtxos(ActionEvent event) { |
|
|
|
Stage window = new Stage(); |
|
|
|
|
|
|
|
FileChooser fileChooser = new FileChooser(); |
|
|
|
fileChooser.setTitle("Export UTXOs to CSV"); |
|
|
|
fileChooser.setInitialFileName(getWalletForm().getWallet().getName() + "-utxos.csv"); |
|
|
|
|
|
|
|
AppServices.moveToActiveWindowScreen(window, 800, 450); |
|
|
|
File file = fileChooser.showSaveDialog(window); |
|
|
|
if(file != null) { |
|
|
|
try(FileOutputStream outputStream = new FileOutputStream(file)) { |
|
|
|
CsvWriter writer = new CsvWriter(outputStream, ',', StandardCharsets.UTF_8); |
|
|
|
writer.writeRecord(new String[] {"Date", "Output", "Address", "Label", "Value"}); |
|
|
|
for(Entry entry : getWalletForm().getWalletUtxosEntry().getChildren()) { |
|
|
|
UtxoEntry utxoEntry = (UtxoEntry)entry; |
|
|
|
writer.write(utxoEntry.getBlockTransaction().getDate() == null ? "Unconfirmed" : EntryCell.DATE_FORMAT.format(utxoEntry.getBlockTransaction().getDate())); |
|
|
|
writer.write(utxoEntry.getHashIndex().toString()); |
|
|
|
writer.write(utxoEntry.getAddress().getAddress()); |
|
|
|
writer.write(utxoEntry.getLabel()); |
|
|
|
writer.write(getCoinValue(utxoEntry.getValue())); |
|
|
|
writer.endRecord(); |
|
|
|
} |
|
|
|
writer.close(); |
|
|
|
} catch(IOException e) { |
|
|
|
log.error("Error exporting UTXOs as CSV", e); |
|
|
|
AppServices.showErrorDialog("Error exporting UTXOs as CSV", e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private String getCoinValue(Long value) { |
|
|
|
return BitcoinUnit.BTC.equals(utxosTable.getBitcoinUnit()) ? |
|
|
|
CoinLabel.getBTCFormat().format(value.doubleValue() / Transaction.SATOSHIS_PER_BITCOIN) : |
|
|
|
String.format(Locale.ENGLISH, "%d", value); |
|
|
|
} |
|
|
|
|
|
|
|
@Subscribe |
|
|
|
public void walletNodesChanged(WalletNodesChangedEvent event) { |
|
|
|
if(event.getWallet().equals(walletForm.getWallet())) { |
|
|
|