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());
}
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);
}
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);
}
});
}
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);
}
Aggregations