Search in sources :

Example 1 with Proposal

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);
}
Also used : TableGroupHeadline(bisq.desktop.components.TableGroupHeadline) ActivatableView(bisq.desktop.common.view.ActivatableView) BsqBlockChainChangeDispatcher(bisq.core.dao.blockchain.BsqBlockChainChangeDispatcher) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) FXCollections(javafx.collections.FXCollections) BsqNode(bisq.core.dao.node.BsqNode) Proposal(bisq.core.dao.proposal.Proposal) FxmlView(bisq.desktop.common.view.FxmlView) TableColumn(javafx.scene.control.TableColumn) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) TableCell(javafx.scene.control.TableCell) ScrollPane(javafx.scene.control.ScrollPane) Insets(javafx.geometry.Insets) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) Res(bisq.core.locale.Res) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) BsqBlockChain(bisq.core.dao.blockchain.BsqBlockChain) GridPane(javafx.scene.layout.GridPane) SortedList(javafx.collections.transformation.SortedList) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) DaoPeriodService(bisq.core.dao.DaoPeriodService) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Node(javafx.scene.Node) Subscription(org.fxmisc.easybind.Subscription) Collectors(java.util.stream.Collectors) BsqFormatter(bisq.desktop.util.BsqFormatter) BsqWalletService(bisq.core.btc.wallet.BsqWalletService) Priority(javafx.scene.layout.Priority) ProposalPayload(bisq.core.dao.proposal.ProposalPayload) List(java.util.List) EasyBind(org.fxmisc.easybind.EasyBind) ObservableList(javafx.collections.ObservableList) ChangeListener(javafx.beans.value.ChangeListener) Comparator(java.util.Comparator) ProposalCollectionsService(bisq.core.dao.proposal.ProposalCollectionsService) Tooltip(javafx.scene.control.Tooltip) TableColumn(javafx.scene.control.TableColumn) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) TableCell(javafx.scene.control.TableCell) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) ProposalPayload(bisq.core.dao.proposal.ProposalPayload) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) Proposal(bisq.core.dao.proposal.Proposal)

Example 2 with Proposal

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;
        }
    }
}
Also used : Button(javafx.scene.control.Button) Proposal(bisq.core.dao.proposal.Proposal)

Example 3 with Proposal

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();
    }
}
Also used : WalletException(bisq.core.btc.exceptions.WalletException) TransactionVerificationException(bisq.core.btc.exceptions.TransactionVerificationException) InsufficientMoneyException(org.bitcoinj.core.InsufficientMoneyException) BSFormatter(bisq.desktop.util.BSFormatter) CompensationAmountException(bisq.core.dao.proposal.compensation.CompensationAmountException) ChangeBelowDustException(bisq.core.btc.wallet.ChangeBelowDustException) Coin(org.bitcoinj.core.Coin) Transaction(org.bitcoinj.core.Transaction) InsufficientBsqException(bisq.core.btc.wallet.InsufficientBsqException) Popup(bisq.desktop.main.overlays.popups.Popup) Proposal(bisq.core.dao.proposal.Proposal)

Example 4 with Proposal

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);
        }
    });
}
Also used : Encryption(bisq.common.crypto.Encryption) Arrays(java.util.Arrays) Slf4j(lombok.extern.slf4j.Slf4j) ReadableBsqBlockChain(bisq.core.dao.blockchain.ReadableBsqBlockChain) Map(java.util.Map) Set(java.util.Set) HashMap(java.util.HashMap) TxOutput(bisq.core.dao.blockchain.vo.TxOutput) SecretKey(javax.crypto.SecretKey) WritableBsqBlockChain(bisq.core.dao.blockchain.WritableBsqBlockChain) Proposal(bisq.core.dao.proposal.Proposal) Hash(bisq.common.crypto.Hash) TxOutput(bisq.core.dao.blockchain.vo.TxOutput) HashMap(java.util.HashMap)

Example 5 with Proposal

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);
}
Also used : Proposal(bisq.core.dao.proposal.Proposal) ProposalList(bisq.core.dao.proposal.ProposalList)

Aggregations

Proposal (bisq.core.dao.proposal.Proposal)5 Encryption (bisq.common.crypto.Encryption)1 Hash (bisq.common.crypto.Hash)1 TransactionVerificationException (bisq.core.btc.exceptions.TransactionVerificationException)1 WalletException (bisq.core.btc.exceptions.WalletException)1 BsqWalletService (bisq.core.btc.wallet.BsqWalletService)1 ChangeBelowDustException (bisq.core.btc.wallet.ChangeBelowDustException)1 InsufficientBsqException (bisq.core.btc.wallet.InsufficientBsqException)1 DaoPeriodService (bisq.core.dao.DaoPeriodService)1 BsqBlockChain (bisq.core.dao.blockchain.BsqBlockChain)1 BsqBlockChainChangeDispatcher (bisq.core.dao.blockchain.BsqBlockChainChangeDispatcher)1 ReadableBsqBlockChain (bisq.core.dao.blockchain.ReadableBsqBlockChain)1 WritableBsqBlockChain (bisq.core.dao.blockchain.WritableBsqBlockChain)1 TxOutput (bisq.core.dao.blockchain.vo.TxOutput)1 BsqNode (bisq.core.dao.node.BsqNode)1 ProposalCollectionsService (bisq.core.dao.proposal.ProposalCollectionsService)1 ProposalList (bisq.core.dao.proposal.ProposalList)1 ProposalPayload (bisq.core.dao.proposal.ProposalPayload)1 CompensationAmountException (bisq.core.dao.proposal.compensation.CompensationAmountException)1 Res (bisq.core.locale.Res)1