use of bisq.core.dao.proposal.Proposal in project bisq-desktop by bisq-network.
the class BaseProposalView method createProposalColumns.
// /////////////////////////////////////////////////////////////////////////////////////////
// TableColumns
// /////////////////////////////////////////////////////////////////////////////////////////
protected void createProposalColumns(TableView<ProposalListItem> tableView) {
TableColumn<ProposalListItem, ProposalListItem> dateColumn = new AutoTooltipTableColumn<ProposalListItem, ProposalListItem>(Res.get("shared.dateTime")) {
{
setMinWidth(190);
setMaxWidth(190);
}
};
dateColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
dateColumn.setCellFactory(new Callback<TableColumn<ProposalListItem, ProposalListItem>, TableCell<ProposalListItem, ProposalListItem>>() {
@Override
public TableCell<ProposalListItem, ProposalListItem> call(TableColumn<ProposalListItem, ProposalListItem> column) {
return new TableCell<ProposalListItem, ProposalListItem>() {
@Override
public void updateItem(final ProposalListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
setText(bsqFormatter.formatDateTime(item.getProposal().getProposalPayload().getCreationDate()));
else
setText("");
}
};
}
});
dateColumn.setComparator(Comparator.comparing(o3 -> o3.getProposal().getProposalPayload().getCreationDate()));
dateColumn.setSortType(TableColumn.SortType.DESCENDING);
tableView.getColumns().add(dateColumn);
tableView.getSortOrder().add(dateColumn);
TableColumn<ProposalListItem, ProposalListItem> nameColumn = new AutoTooltipTableColumn<>(Res.get("shared.name"));
nameColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
nameColumn.setCellFactory(new Callback<TableColumn<ProposalListItem, ProposalListItem>, TableCell<ProposalListItem, ProposalListItem>>() {
@Override
public TableCell<ProposalListItem, ProposalListItem> call(TableColumn<ProposalListItem, ProposalListItem> column) {
return new TableCell<ProposalListItem, ProposalListItem>() {
@Override
public void updateItem(final ProposalListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
setText(item.getProposal().getProposalPayload().getName());
else
setText("");
}
};
}
});
nameColumn.setComparator(Comparator.comparing(o2 -> o2.getProposal().getProposalPayload().getName()));
tableView.getColumns().add(nameColumn);
TableColumn<ProposalListItem, ProposalListItem> titleColumn = new AutoTooltipTableColumn<>(Res.get("dao.proposal.title"));
titleColumn.setPrefWidth(100);
titleColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
titleColumn.setCellFactory(new Callback<TableColumn<ProposalListItem, ProposalListItem>, TableCell<ProposalListItem, ProposalListItem>>() {
@Override
public TableCell<ProposalListItem, ProposalListItem> call(TableColumn<ProposalListItem, ProposalListItem> column) {
return new TableCell<ProposalListItem, ProposalListItem>() {
@Override
public void updateItem(final ProposalListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
setText(item.getProposal().getProposalPayload().getTitle());
else
setText("");
}
};
}
});
titleColumn.setComparator(Comparator.comparing(o2 -> o2.getProposal().getProposalPayload().getTitle()));
tableView.getColumns().add(titleColumn);
TableColumn<ProposalListItem, ProposalListItem> uidColumn = new AutoTooltipTableColumn<>(Res.get("shared.id"));
uidColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
uidColumn.setCellFactory(new Callback<TableColumn<ProposalListItem, ProposalListItem>, TableCell<ProposalListItem, ProposalListItem>>() {
@Override
public TableCell<ProposalListItem, ProposalListItem> call(TableColumn<ProposalListItem, ProposalListItem> column) {
return new TableCell<ProposalListItem, ProposalListItem>() {
private HyperlinkWithIcon field;
@Override
public void updateItem(final ProposalListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
final Proposal proposal = item.getProposal();
final ProposalPayload proposalPayload = proposal.getProposalPayload();
field = new HyperlinkWithIcon(proposalPayload.getShortId());
field.setOnAction(event -> {
new ProposalDetailsWindow(bsqFormatter, bsqWalletService, proposalPayload).show();
});
field.setTooltip(new Tooltip(Res.get("tooltip.openPopupForDetails")));
setGraphic(field);
} else {
setGraphic(null);
if (field != null)
field.setOnAction(null);
}
}
};
}
});
uidColumn.setComparator(Comparator.comparing(o -> o.getProposal().getProposalPayload().getUid()));
tableView.getColumns().add(uidColumn);
}
use of bisq.core.dao.proposal.Proposal in project bisq-desktop by bisq-network.
the class ActiveProposalsView method onPhaseChanged.
@Override
protected void onPhaseChanged(DaoPeriodService.Phase phase) {
super.onPhaseChanged(phase);
changeVoteViewItemsVisibility(phase == DaoPeriodService.Phase.BLIND_VOTE);
if (removeButton != null) {
removeButton.setManaged(false);
removeButton.setVisible(false);
removeButton = null;
}
if (selectedProposalListItem != null && proposalDisplay != null && !daoPeriodService.isTxInPastCycle(selectedProposalListItem.getProposal().getTxId())) {
final Proposal proposal = selectedProposalListItem.getProposal();
switch(phase) {
case PROPOSAL:
if (proposalCollectionsService.isMine(proposal)) {
if (removeButton == null) {
removeButton = addButtonAfterGroup(detailsGridPane, proposalDisplay.incrementAndGetGridRow(), Res.get("dao.proposal.active.remove"));
removeButton.setOnAction(event -> onRemove());
} else {
removeButton.setManaged(true);
removeButton.setVisible(true);
}
}
break;
case BREAK1:
break;
case BLIND_VOTE:
if (acceptButton == null) {
Tuple3<Button, Button, Button> tuple = add3ButtonsAfterGroup(detailsGridPane, proposalDisplay.incrementAndGetGridRow(), Res.get("dao.proposal.myVote.accept"), Res.get("dao.proposal.myVote.reject"), Res.get("dao.proposal.myVote.cancelVote"));
acceptButton = tuple.first;
acceptButton.setDefaultButton(false);
rejectButton = tuple.second;
cancelVoteButton = tuple.third;
acceptButton.setOnAction(event -> onAccept());
rejectButton.setOnAction(event -> onReject());
cancelVoteButton.setOnAction(event -> onCancelVote());
} else {
acceptButton.setManaged(true);
acceptButton.setVisible(true);
rejectButton.setManaged(true);
rejectButton.setVisible(true);
cancelVoteButton.setManaged(true);
cancelVoteButton.setVisible(true);
}
break;
case BREAK2:
break;
case VOTE_REVEAL:
break;
case BREAK3:
break;
case ISSUANCE:
break;
case BREAK4:
break;
case UNDEFINED:
default:
log.warn("Undefined phase: " + phase);
break;
}
}
}
use of bisq.core.dao.proposal.Proposal in project bisq-desktop by bisq-network.
the class MakeProposalView method publishProposal.
private void publishProposal(ProposalType type) {
try {
Proposal proposal = createProposal(type);
Transaction tx = Objects.requireNonNull(proposal).getTx();
Coin miningFee = Objects.requireNonNull(tx).getFee();
int txSize = tx.bitcoinSerialize().length;
validateInputs();
new Popup<>().headLine(Res.get("dao.proposal.create.confirm")).confirmation(Res.get("dao.proposal.create.confirm.info", bsqFormatter.formatCoinWithCode(ProposalConsensus.getCreateCompensationRequestFee(readableBsqBlockChain)), btcFormatter.formatCoinWithCode(miningFee), CoinUtil.getFeePerByte(miningFee, txSize), (txSize / 1000d))).actionButtonText(Res.get("shared.yes")).onAction(() -> {
proposalCollectionsService.publishProposal(proposal, new FutureCallback<Transaction>() {
@Override
public void onSuccess(@Nullable Transaction transaction) {
proposalDisplay.clearForm();
proposalTypeComboBox.getSelectionModel().clearSelection();
new Popup<>().confirmation(Res.get("dao.tx.published.success")).show();
}
@Override
public void onFailure(@NotNull Throwable t) {
log.error(t.toString());
new Popup<>().warning(t.toString()).show();
}
});
}).closeButtonText(Res.get("shared.cancel")).show();
} catch (InsufficientMoneyException e) {
BSFormatter formatter = e instanceof InsufficientBsqException ? bsqFormatter : btcFormatter;
new Popup<>().warning(Res.get("dao.proposal.create.missingFunds", formatter.formatCoinWithCode(e.missing))).show();
} catch (CompensationAmountException e) {
new Popup<>().warning(Res.get("validation.bsq.amountBelowMinAmount", bsqFormatter.formatCoinWithCode(e.required))).show();
} catch (TransactionVerificationException | WalletException e) {
log.error(e.toString());
e.printStackTrace();
new Popup<>().warning(e.toString()).show();
} catch (ChangeBelowDustException e) {
// TODO
e.printStackTrace();
}
}
use of bisq.core.dao.proposal.Proposal in project bisq-core by bisq-network.
the class IssuanceConsensus method applyVoteResult.
public static void applyVoteResult(Map<Proposal, Integer> stakeByProposalMap, ReadableBsqBlockChain readableBsqBlockChain, WritableBsqBlockChain writableBsqBlockChain) {
Map<String, TxOutput> txOutputsByTxIdMap = new HashMap<>();
final Set<TxOutput> compReqIssuanceTxOutputs = readableBsqBlockChain.getCompReqIssuanceTxOutputs();
compReqIssuanceTxOutputs.stream().filter(// our candidate is not yet verified and not set
txOutput -> !txOutput.isVerified()).forEach(txOutput -> txOutputsByTxIdMap.put(txOutput.getTxId(), txOutput));
stakeByProposalMap.forEach((proposal, value) -> {
int stakeResult = value;
if (stakeResult >= QUORUM) {
final String txId = proposal.getTxId();
if (txOutputsByTxIdMap.containsKey(txId)) {
final TxOutput txOutput = txOutputsByTxIdMap.get(txId);
writableBsqBlockChain.issueBsq(txOutput);
log.info("We issued new BSQ to txOutput {} for proposal {}", txOutput, proposal);
}
} else {
log.warn("We got a successful vote result but did not reach the quorum. stake={}, quorum={}", stakeResult, QUORUM);
}
});
}
use of bisq.core.dao.proposal.Proposal in project bisq-core by bisq-network.
the class VoteService method getClonedProposalList.
private ProposalList getClonedProposalList(FilteredList<Proposal> proposals) throws InvalidProtocolBufferException {
ProposalList cloned = ProposalList.clone(new ProposalList(proposals));
final List<Proposal> sortedProposals = VoteConsensus.getSortedProposalList(cloned.getList());
return new ProposalList(sortedProposals);
}
Aggregations