Search in sources :

Example 1 with ProposalList

use of bisq.core.dao.proposal.ProposalList in project bisq-core by bisq-network.

the class IssuanceService method getRevealedVotes.

private Set<RevealedVote> getRevealedVotes(Map<String, SecretKey> secretKeysByTxIdMap, Set<BlindVoteWithRevealTxId> blindVoteWithRevealTxIdSet) {
    return blindVoteWithRevealTxIdSet.stream().map(blindVoteWithRevealTxId -> {
        try {
            // TODO check if cloning here is needed (we might want to keep the blindVote separated from the
            // blindVoteList to the RevealedVote...)
            final BlindVote blindVote = BlindVote.clone(blindVoteWithRevealTxId.getBlindVote());
            final byte[] encryptedProposalList = blindVote.getEncryptedProposalList();
            final SecretKey secretKey = secretKeysByTxIdMap.get(blindVoteWithRevealTxId.getTxId());
            final byte[] decrypted = Encryption.decrypt(encryptedProposalList, secretKey);
            // TODO move to ProposalList
            final PB.PersistableEnvelope envelope = PB.PersistableEnvelope.parseFrom(decrypted);
            ProposalList proposalList = ProposalList.fromProto(envelope.getProposalList());
            return new RevealedVote(proposalList, blindVote);
        } catch (CryptoException e) {
            e.printStackTrace();
            return null;
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
            return null;
        }
    }).filter(Objects::nonNull).collect(Collectors.toSet());
}
Also used : SecretKey(javax.crypto.SecretKey) PB(io.bisq.generated.protobuffer.PB) RevealedVote(bisq.core.dao.vote.RevealedVote) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) CryptoException(bisq.common.crypto.CryptoException) BlindVote(bisq.core.dao.vote.BlindVote) ProposalList(bisq.core.dao.proposal.ProposalList)

Example 2 with ProposalList

use of bisq.core.dao.proposal.ProposalList in project bisq-desktop by bisq-network.

the class MyVotesView method createVoteColumns.

// /////////////////////////////////////////////////////////////////////////////////////////
// TableColumns
// /////////////////////////////////////////////////////////////////////////////////////////
private void createVoteColumns(TableView<VoteListItem> tableView) {
    TableColumn<VoteListItem, VoteListItem> dateColumn = new AutoTooltipTableColumn<VoteListItem, VoteListItem>(Res.get("shared.dateTime")) {

        {
            setMinWidth(190);
            setMaxWidth(190);
        }
    };
    dateColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
    dateColumn.setCellFactory(new Callback<TableColumn<VoteListItem, VoteListItem>, TableCell<VoteListItem, VoteListItem>>() {

        @Override
        public TableCell<VoteListItem, VoteListItem> call(TableColumn<VoteListItem, VoteListItem> column) {
            return new TableCell<VoteListItem, VoteListItem>() {

                @Override
                public void updateItem(final VoteListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null)
                        setText(bsqFormatter.formatDateTime(new Date(item.getMyVote().getDate())));
                    else
                        setText("");
                }
            };
        }
    });
    dateColumn.setComparator(Comparator.comparing(o3 -> o3.getMyVote().getDate()));
    dateColumn.setSortType(TableColumn.SortType.DESCENDING);
    tableView.getColumns().add(dateColumn);
    tableView.getSortOrder().add(dateColumn);
    TableColumn<VoteListItem, VoteListItem> proposalListColumn = new AutoTooltipTableColumn<>(Res.get("dao.proposal.myVotes.proposalList"));
    proposalListColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
    proposalListColumn.setCellFactory(new Callback<TableColumn<VoteListItem, VoteListItem>, TableCell<VoteListItem, VoteListItem>>() {

        @Override
        public TableCell<VoteListItem, VoteListItem> call(TableColumn<VoteListItem, VoteListItem> column) {
            return new TableCell<VoteListItem, VoteListItem>() {

                @Override
                public void updateItem(final VoteListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        ProposalList proposalList = item.getMyVote().getProposalList();
                        HyperlinkWithIcon field = new HyperlinkWithIcon(Res.get("dao.proposal.myVotes.showProposalList"), AwesomeIcon.INFO_SIGN);
                        field.setOnAction(event -> onShowProposalList(proposalList));
                        field.setTooltip(new Tooltip(Res.get("dao.proposal.myVotes.tooltip.showProposalList")));
                        setGraphic(field);
                    } else {
                        setGraphic(null);
                    }
                }
            };
        }
    });
    proposalListColumn.setSortable(false);
    tableView.getColumns().add(proposalListColumn);
    TableColumn<VoteListItem, VoteListItem> stakeColumn = new AutoTooltipTableColumn<>(Res.get("dao.proposal.votes.stake"));
    stakeColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
    stakeColumn.setCellFactory(new Callback<TableColumn<VoteListItem, VoteListItem>, TableCell<VoteListItem, VoteListItem>>() {

        @Override
        public TableCell<VoteListItem, VoteListItem> call(TableColumn<VoteListItem, VoteListItem> column) {
            return new TableCell<VoteListItem, VoteListItem>() {

                @Override
                public void updateItem(final VoteListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        textProperty().bind(item.getStakeAsStringProperty());
                    } else {
                        textProperty().unbind();
                        setText("");
                    }
                }
            };
        }
    });
    stakeColumn.setComparator(Comparator.comparing(VoteListItem::getStake));
    tableView.getColumns().add(stakeColumn);
    TableColumn<VoteListItem, VoteListItem> txColumn = new AutoTooltipTableColumn<>(Res.get("dao.proposal.myVotes.tx"));
    txColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
    txColumn.setCellFactory(new Callback<TableColumn<VoteListItem, VoteListItem>, TableCell<VoteListItem, VoteListItem>>() {

        @Override
        public TableCell<VoteListItem, VoteListItem> call(TableColumn<VoteListItem, VoteListItem> column) {
            return new TableCell<VoteListItem, VoteListItem>() {

                @Override
                public void updateItem(final VoteListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        String txId = item.getMyVote().getTxId();
                        HyperlinkWithIcon hyperlinkWithIcon = new HyperlinkWithIcon(txId, AwesomeIcon.EXTERNAL_LINK);
                        hyperlinkWithIcon.setOnAction(event -> {
                            if (txId != null)
                                GUIUtil.openWebPage(preferences.getBlockChainExplorer().txUrl + txId);
                        });
                        hyperlinkWithIcon.setTooltip(new Tooltip(Res.get("tooltip.openBlockchainForTx", txId)));
                        setGraphic(hyperlinkWithIcon);
                    } else {
                        setGraphic(null);
                    }
                }
            };
        }
    });
    txColumn.setComparator(Comparator.comparing(o2 -> o2.getMyVote().getBlindVote().getTxId()));
    tableView.getColumns().add(txColumn);
    TableColumn<VoteListItem, VoteListItem> confidenceColumn = new TableColumn<>(Res.get("shared.confirmations"));
    confidenceColumn.setMinWidth(130);
    confidenceColumn.setMaxWidth(confidenceColumn.getMinWidth());
    confidenceColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
    confidenceColumn.setCellFactory(new Callback<TableColumn<VoteListItem, VoteListItem>, TableCell<VoteListItem, VoteListItem>>() {

        @Override
        public TableCell<VoteListItem, VoteListItem> call(TableColumn<VoteListItem, VoteListItem> column) {
            return new TableCell<VoteListItem, VoteListItem>() {

                @Override
                public void updateItem(final VoteListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        setGraphic(item.getTxConfidenceIndicator());
                    } else {
                        setGraphic(null);
                    }
                }
            };
        }
    });
    confidenceColumn.setComparator(Comparator.comparing(VoteListItem::getConfirmations));
    tableView.getColumns().add(confidenceColumn);
}
Also used : TableGroupHeadline(bisq.desktop.components.TableGroupHeadline) GUIUtil(bisq.desktop.util.GUIUtil) BsqBlockChainChangeDispatcher(bisq.core.dao.blockchain.BsqBlockChainChangeDispatcher) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) Date(java.util.Date) ReadableBsqBlockChain(bisq.core.dao.blockchain.ReadableBsqBlockChain) FXCollections(javafx.collections.FXCollections) Layout(bisq.desktop.util.Layout) BsqNodeProvider(bisq.core.dao.node.BsqNodeProvider) FxmlView(bisq.desktop.common.view.FxmlView) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) TableCell(javafx.scene.control.TableCell) Insets(javafx.geometry.Insets) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ProposalListItem(bisq.desktop.main.dao.proposal.ProposalListItem) Res(bisq.core.locale.Res) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) VoteService(bisq.core.dao.vote.VoteService) 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) VoteResult(bisq.core.dao.vote.VoteResult) 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) BaseProposalView(bisq.desktop.main.dao.proposal.BaseProposalView) List(java.util.List) EasyBind(org.fxmisc.easybind.EasyBind) ImageView(javafx.scene.image.ImageView) ProposalList(bisq.core.dao.proposal.ProposalList) Preferences(bisq.core.user.Preferences) BooleanVoteResult(bisq.core.dao.vote.BooleanVoteResult) ObservableList(javafx.collections.ObservableList) AwesomeIcon(de.jensd.fx.fontawesome.AwesomeIcon) 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) Date(java.util.Date) TableCell(javafx.scene.control.TableCell) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) ProposalList(bisq.core.dao.proposal.ProposalList)

Example 3 with ProposalList

use of bisq.core.dao.proposal.ProposalList in project bisq-core by bisq-network.

the class VoteService method publishBlindVote.

// TODO consolidate exceptions
public void publishBlindVote(Coin stake, FutureCallback<Transaction> callback) throws CryptoException, InsufficientMoneyException, ChangeBelowDustException, WalletException, TransactionVerificationException, InvalidProtocolBufferException {
    ProposalList proposalList = getClonedProposalList(proposalCollectionsService.getActiveProposals());
    SecretKey secretKey = VoteConsensus.getSecretKey();
    byte[] encryptedProposalList = getEncryptedVoteList(proposalList, secretKey);
    byte[] opReturnData = VoteConsensus.getOpReturnDataForBlindVote(encryptedProposalList);
    final Transaction blindVoteTx = getBlindVoteTx(stake, opReturnData);
    BlindVote blindVote = new BlindVote(encryptedProposalList, blindVoteTx.getHashAsString(), stake.value, signaturePubKey);
    publishTx(blindVoteTx, new FutureCallback<Transaction>() {

        @Override
        public void onSuccess(@Nullable Transaction result) {
            addBlindVoteToP2PNetwork(blindVote);
            if (!blindVoteList.contains(blindVote)) {
                blindVoteList.add(blindVote);
                blindVoteListStorage.queueUpForSave(new BlindVoteList(blindVoteList), 100);
            }
            MyVote myVote = new MyVote(proposalList, Utils.HEX.encode(secretKey.getEncoded()), blindVote);
            myVotesList.add(myVote);
            myVoteListStorage.queueUpForSave(new MyVoteList(myVotesList), 100);
            callback.onSuccess(result);
        }

        @Override
        public void onFailure(@NotNull Throwable t) {
            callback.onFailure(t);
        }
    });
}
Also used : SecretKey(javax.crypto.SecretKey) Transaction(org.bitcoinj.core.Transaction) ProposalList(bisq.core.dao.proposal.ProposalList)

Example 4 with ProposalList

use of bisq.core.dao.proposal.ProposalList 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

ProposalList (bisq.core.dao.proposal.ProposalList)4 CryptoException (bisq.common.crypto.CryptoException)1 BsqWalletService (bisq.core.btc.wallet.BsqWalletService)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 BsqNodeProvider (bisq.core.dao.node.BsqNodeProvider)1 Proposal (bisq.core.dao.proposal.Proposal)1 ProposalCollectionsService (bisq.core.dao.proposal.ProposalCollectionsService)1 BlindVote (bisq.core.dao.vote.BlindVote)1 BooleanVoteResult (bisq.core.dao.vote.BooleanVoteResult)1 RevealedVote (bisq.core.dao.vote.RevealedVote)1 VoteResult (bisq.core.dao.vote.VoteResult)1 VoteService (bisq.core.dao.vote.VoteService)1 Res (bisq.core.locale.Res)1 Preferences (bisq.core.user.Preferences)1 FxmlView (bisq.desktop.common.view.FxmlView)1 AutoTooltipLabel (bisq.desktop.components.AutoTooltipLabel)1 AutoTooltipTableColumn (bisq.desktop.components.AutoTooltipTableColumn)1