Skip to content

Commit

Permalink
Merge pull request #6742 from jmacxx/csv_export_proof_of_burn
Browse files Browse the repository at this point in the history
Add CSV export for Proof of Burn table.
  • Loading branch information
alejandrogarcia83 authored Jun 30, 2023
2 parents 60e48d9 + aa79b01 commit 6b0f32f
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,25 @@
import org.bitcoinj.core.InsufficientMoneyException;
import org.bitcoinj.core.Transaction;

import com.googlecode.jcsv.writer.CSVEntryConverter;

import javax.inject.Inject;
import javax.inject.Named;

import javafx.stage.Stage;

import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.GridPane;

import javafx.geometry.HPos;
import javafx.geometry.Insets;

import javafx.beans.InvalidationListener;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ChangeListener;
Expand All @@ -72,7 +80,10 @@

import javafx.util.Callback;


import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import static bisq.desktop.util.FormBuilder.addButtonAfterGroup;
Expand All @@ -95,6 +106,7 @@ public class ProofOfBurnView extends ActivatableView<GridPane, Void> implements
private Button burnButton;
private TableView<MyProofOfBurnListItem> myItemsTableView;
private TableView<ProofOfBurnListItem> allTxsTableView;
private Hyperlink exportAsCSVHyperlink;

private final ObservableList<MyProofOfBurnListItem> myItemsObservableList = FXCollections.observableArrayList();
private final SortedList<MyProofOfBurnListItem> myItemsSortedList = new SortedList<>(myItemsObservableList);
Expand Down Expand Up @@ -153,6 +165,14 @@ public void initialize() {
createColumnsForAllTxs();
allTxsTableView.setItems(allItemsSortedList);

exportAsCSVHyperlink = new Hyperlink(Res.get("shared.exportCSV"));
GridPane.setRowIndex(exportAsCSVHyperlink, ++gridRow);
GridPane.setColumnIndex(exportAsCSVHyperlink, 0);
GridPane.setMargin(exportAsCSVHyperlink, new Insets(-5, 0, 0, 0));
GridPane.setHalignment(exportAsCSVHyperlink, HPos.RIGHT);
root.getChildren().add(exportAsCSVHyperlink);
exportAsCSVHyperlink.setOnAction(e -> exportToCSV());

createListeners();
}

Expand Down Expand Up @@ -301,6 +321,27 @@ private void doPublishFeeTx(Transaction transaction, String preImageAsString) {
preImageTextField.resetValidation();
}

private void exportToCSV() {
List<String> result = new ArrayList<>();
String separator = "~";
String tableColumns = "Amount~Date~Hash~TxId~Pubkey";
CSVEntryConverter<String> headerConverter = item -> tableColumns.split(separator);
CSVEntryConverter<String> contentConverter = item -> item.split(separator);
for (ProofOfBurnListItem item: allItemsSortedList) {
String line = bsqFormatter.formatCoin(item.getAmount())
+ separator + item.getDateAsString()
+ separator + item.getHashAsHex()
+ separator + item.getTxId()
+ separator + item.getPubKey();
result.add(line);
}
GUIUtil.exportCSV("proofOfBurnTransactions.csv",
headerConverter,
contentConverter,
"",
result,
(Stage) root.getScene().getWindow());
}

///////////////////////////////////////////////////////////////////////////////////////////
// Table columns
Expand Down

0 comments on commit 6b0f32f

Please sign in to comment.