Let proposal domain handle all its relevant use cases

- Previously we wrapped by default a proposal into a ballot and used that in the UI.
We changed that so in the proposal phase there is only the proposal used. Once we enter the blind vote phase we move to ballot representation.
- We also changed that the proposals for the append-only data store gets filled by the proposal domain once entering the blind vote phase.
- We moved also the publishing, removal and republishing to the myProposalListService.
This commit is contained in:
Manfred Karrer 2018-04-30 12:28:22 -05:00
parent 7951fc557b
commit 2705e68dc8
No known key found for this signature in database
GPG key ID: 401250966A6B2C46
6 changed files with 67 additions and 57 deletions

View file

@ -191,14 +191,14 @@ public abstract class BaseProposalView extends ActivatableView<GridPane, Void> {
proposalDisplayView.setManaged(false);
}
protected void showProposalDisplay(Ballot ballot) {
protected void showProposalDisplay(Proposal proposal) {
proposalDisplayView.setVisible(true);
proposalDisplayView.setManaged(true);
proposalDisplay.createAllFields(Res.get("dao.proposal.selectedProposal"), 0, 0, ballot.getType(),
proposalDisplay.createAllFields(Res.get("dao.proposal.selectedProposal"), 0, 0, proposal.getType(),
false, false);
proposalDisplay.setEditable(false);
proposalDisplay.applyProposalPayload(ballot.getProposal());
proposalDisplay.applyProposalPayload(proposal);
}
@ -209,7 +209,7 @@ public abstract class BaseProposalView extends ActivatableView<GridPane, Void> {
protected void onSelectProposal(ProposalListItem item) {
selectedProposalListItem = item;
if (item != null)
showProposalDisplay(item.getBallot());
showProposalDisplay(item.getProposal());
else
hideProposalDisplay();
}
@ -228,11 +228,11 @@ public abstract class BaseProposalView extends ActivatableView<GridPane, Void> {
abstract protected void updateProposalList();
protected void doUpdateProposalList(List<Ballot> list) {
protected void doUpdateProposalList(List<Proposal> list) {
proposalListItems.forEach(ProposalListItem::cleanup);
proposalListItems.clear();
proposalListItems.setAll(list.stream()
.map(ballot -> new ProposalListItem(ballot,
.map(proposal -> new ProposalListItem(proposal,
daoFacade,
bsqWalletService,
bsqFormatter))
@ -273,14 +273,14 @@ public abstract class BaseProposalView extends ActivatableView<GridPane, Void> {
public void updateItem(final ProposalListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
setText(bsqFormatter.formatDateTime(item.getBallot().getProposal().getCreationDate()));
setText(bsqFormatter.formatDateTime(item.getProposal().getCreationDate()));
else
setText("");
}
};
}
});
dateColumn.setComparator(Comparator.comparing(o3 -> o3.getBallot().getProposal().getCreationDate()));
dateColumn.setComparator(Comparator.comparing(o3 -> o3.getProposal().getCreationDate()));
dateColumn.setSortType(TableColumn.SortType.DESCENDING);
tableView.getColumns().add(dateColumn);
tableView.getSortOrder().add(dateColumn);
@ -298,14 +298,14 @@ public abstract class BaseProposalView extends ActivatableView<GridPane, Void> {
public void updateItem(final ProposalListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
setText(item.getBallot().getProposal().getName());
setText(item.getProposal().getName());
else
setText("");
}
};
}
});
nameColumn.setComparator(Comparator.comparing(o2 -> o2.getBallot().getProposal().getName()));
nameColumn.setComparator(Comparator.comparing(o2 -> o2.getProposal().getName()));
tableView.getColumns().add(nameColumn);
TableColumn<ProposalListItem, ProposalListItem> titleColumn = new AutoTooltipTableColumn<>(Res.get("dao.proposal.title"));
@ -322,14 +322,14 @@ public abstract class BaseProposalView extends ActivatableView<GridPane, Void> {
public void updateItem(final ProposalListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
setText(item.getBallot().getProposal().getTitle());
setText(item.getProposal().getTitle());
else
setText("");
}
};
}
});
titleColumn.setComparator(Comparator.comparing(o2 -> o2.getBallot().getProposal().getTitle()));
titleColumn.setComparator(Comparator.comparing(o2 -> o2.getProposal().getTitle()));
tableView.getColumns().add(titleColumn);
TableColumn<ProposalListItem, ProposalListItem> uidColumn = new AutoTooltipTableColumn<>(Res.get("shared.id"));
@ -348,8 +348,7 @@ public abstract class BaseProposalView extends ActivatableView<GridPane, Void> {
public void updateItem(final ProposalListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
final Ballot ballot = item.getBallot();
final Proposal proposal = ballot.getProposal();
final Proposal proposal = item.getProposal();
field = new HyperlinkWithIcon(proposal.getShortId());
field.setOnAction(event -> {
new ProposalDetailsWindow(bsqFormatter, bsqWalletService, proposal).show();
@ -365,7 +364,7 @@ public abstract class BaseProposalView extends ActivatableView<GridPane, Void> {
};
}
});
uidColumn.setComparator(Comparator.comparing(o -> o.getBallot().getUid()));
uidColumn.setComparator(Comparator.comparing(o -> o.getProposal().getUid()));
tableView.getColumns().add(uidColumn);
}

View file

@ -24,12 +24,11 @@ import bisq.desktop.util.BsqFormatter;
import bisq.core.btc.listeners.TxConfidenceListener;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.dao.DaoFacade;
import bisq.core.dao.state.period.DaoPhase;
import bisq.core.dao.state.BlockListener;
import bisq.core.dao.state.blockchain.Block;
import bisq.core.dao.state.blockchain.Tx;
import bisq.core.dao.voting.ballot.Ballot;
import bisq.core.dao.voting.ballot.vote.BooleanVote;
import bisq.core.dao.state.period.DaoPhase;
import bisq.core.dao.voting.ballot.proposal.Proposal;
import bisq.core.dao.voting.ballot.vote.Vote;
import bisq.core.locale.Res;
@ -55,7 +54,7 @@ import lombok.extern.slf4j.Slf4j;
@EqualsAndHashCode
public class ProposalListItem implements BlockListener {
@Getter
private final Ballot ballot;
private final Proposal proposal;
private final DaoFacade daoFacade;
private final BsqWalletService bsqWalletService;
private final BsqFormatter bsqFormatter;
@ -76,11 +75,11 @@ public class ProposalListItem implements BlockListener {
private Runnable onRemoveHandler;
private Node actionNode;
ProposalListItem(Ballot ballot,
ProposalListItem(Proposal proposal,
DaoFacade daoFacade,
BsqWalletService bsqWalletService,
BsqFormatter bsqFormatter) {
this.ballot = ballot;
this.proposal = proposal;
this.daoFacade = daoFacade;
this.bsqWalletService = bsqWalletService;
this.bsqFormatter = bsqFormatter;
@ -104,7 +103,8 @@ public class ProposalListItem implements BlockListener {
daoFacade.addBlockListener(this);
phaseChangeListener = (observable, oldValue, newValue) -> {
applyState(newValue, ballot.getVote());
//TODO
//applyState(newValue, proposal.getVote());
};
voteResultChangeListener = (observable, oldValue, newValue) -> {
@ -112,7 +112,9 @@ public class ProposalListItem implements BlockListener {
};
daoFacade.phaseProperty().addListener(phaseChangeListener);
ballot.getVoteResultProperty().addListener(voteResultChangeListener);
//TODO
//proposal.getVoteResultProperty().addListener(voteResultChangeListener);
}
public void applyState(DaoPhase.Phase phase, Vote vote) {
@ -125,7 +127,7 @@ public class ProposalListItem implements BlockListener {
log.error("invalid state UNDEFINED");
break;
case PROPOSAL:
if (daoFacade.isMyProposal(ballot.getProposal())) {
if (daoFacade.isMyProposal(proposal)) {
actionButtonIconView.setVisible(actionButton.isVisible());
actionButton.setText(Res.get("shared.remove"));
actionButton.setGraphic(actionButtonIconView);
@ -142,7 +144,9 @@ public class ProposalListItem implements BlockListener {
case BLIND_VOTE:
actionNode = actionButtonIconView;
actionButton.setVisible(false);
if (ballot.getVote() != null) {
//TODO
/*if (proposal.getVote() != null) {
actionButtonIconView.setVisible(true);
if (vote instanceof BooleanVote) {
if (((BooleanVote) vote).isAccepted()) {
@ -155,7 +159,8 @@ public class ProposalListItem implements BlockListener {
}
} else {
actionButtonIconView.setVisible(false);
}
}*/
break;
case BREAK2:
break;
@ -191,7 +196,7 @@ public class ProposalListItem implements BlockListener {
// TODO reuse from other item
private void setupConfidence() {
final String txId = ballot.getProposal().getTxId();
final String txId = proposal.getTxId();
Optional<Tx> optionalTx = daoFacade.getTx(txId);
if (optionalTx.isPresent()) {
Tx tx = optionalTx.get();
@ -240,7 +245,9 @@ public class ProposalListItem implements BlockListener {
bsqWalletService.removeTxConfidenceListener(txConfidenceListener);
daoFacade.phaseProperty().removeListener(phaseChangeListener);
ballot.getVoteResultProperty().removeListener(voteResultChangeListener);
//TODO
// proposal.getVoteResultProperty().removeListener(voteResultChangeListener);
}
private void updateConfidence(TransactionConfidence.ConfidenceType confidenceType, int depthInBlocks, int numBroadcastPeers) {

View file

@ -35,8 +35,7 @@ import bisq.core.btc.wallet.BsqBalanceListener;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.dao.DaoFacade;
import bisq.core.dao.state.period.DaoPhase;
import bisq.core.dao.voting.ballot.Ballot;
import bisq.core.dao.voting.ballot.vote.BooleanVote;
import bisq.core.dao.voting.ballot.proposal.Proposal;
import bisq.core.locale.Res;
import bisq.common.util.Tuple2;
@ -226,17 +225,21 @@ public class ActiveProposalsView extends BaseProposalView implements BsqBalanceL
}
private void onAccept() {
daoFacade.setVote(selectedProposalListItem.getBallot(), new BooleanVote(true));
//TODO
// daoFacade.setVote(selectedProposalListItem.getProposal(), new BooleanVote(true));
updateStateAfterVote();
}
private void onReject() {
daoFacade.setVote(selectedProposalListItem.getBallot(), new BooleanVote(false));
//TODO
// daoFacade.setVote(selectedProposalListItem.getProposal(), new BooleanVote(false));
updateStateAfterVote();
}
private void onCancelVote() {
daoFacade.setVote(selectedProposalListItem.getBallot(), null);
//TODO
// daoFacade.setVote(selectedProposalListItem.getProposal(), null);
updateStateAfterVote();
}
@ -253,10 +256,10 @@ public class ActiveProposalsView extends BaseProposalView implements BsqBalanceL
removeButton = null;
}
if (selectedProposalListItem != null && proposalDisplay != null) {
final Ballot ballot = selectedProposalListItem.getBallot();
final Proposal proposal = selectedProposalListItem.getProposal();
switch (phase) {
case PROPOSAL:
if (daoFacade.isMyProposal(ballot.getProposal())) {
if (daoFacade.isMyProposal(proposal)) {
if (removeButton == null) {
removeButton = addButtonAfterGroup(detailsGridPane, proposalDisplay.incrementAndGetGridRow(), Res.get("dao.proposal.active.remove"));
removeButton.setOnAction(event -> onRemove());
@ -316,7 +319,7 @@ public class ActiveProposalsView extends BaseProposalView implements BsqBalanceL
@Override
protected void updateProposalList() {
doUpdateProposalList(daoFacade.getActiveOrMyUnconfirmedBallots());
doUpdateProposalList(daoFacade.getActiveOrMyUnconfirmedProposals());
}
private void updateStateAfterVote() {
@ -332,8 +335,8 @@ public class ActiveProposalsView extends BaseProposalView implements BsqBalanceL
}
private void onRemove() {
final Ballot ballot = selectedProposalListItem.getBallot();
if (daoFacade.removeBallot(ballot)) {
final Proposal proposal = selectedProposalListItem.getProposal();
if (daoFacade.removeMyProposal(proposal)) {
hideProposalDisplay();
} else {
new Popup<>().warning(Res.get("dao.proposal.active.remove.failed")).show();
@ -378,7 +381,8 @@ public class ActiveProposalsView extends BaseProposalView implements BsqBalanceL
ActiveProposalsView.this.selectedProposalListItem = item;
ActiveProposalsView.this.onRemove();
});
item.applyState(currentPhase, item.getBallot().getVoteResultProperty().get());
//TODO
// item.applyState(currentPhase, item.getProposal().getVoteResultProperty().get());
}
} else {
setGraphic(null);

View file

@ -65,7 +65,7 @@ public class ClosedProposalsView extends BaseProposalView {
@Override
protected void updateProposalList() {
doUpdateProposalList(daoFacade.getClosedBallots());
doUpdateProposalList(daoFacade.getClosedProposals());
}
}

View file

@ -33,10 +33,10 @@ import bisq.core.btc.wallet.InsufficientBsqException;
import bisq.core.btc.wallet.WalletsSetup;
import bisq.core.dao.DaoFacade;
import bisq.core.dao.voting.ValidationException;
import bisq.core.dao.voting.ballot.Ballot;
import bisq.core.dao.voting.ballot.BallotWithTransaction;
import bisq.core.dao.voting.ballot.proposal.Proposal;
import bisq.core.dao.voting.ballot.proposal.ProposalConsensus;
import bisq.core.dao.voting.ballot.proposal.ProposalType;
import bisq.core.dao.voting.ballot.proposal.ProposalWithTransaction;
import bisq.core.locale.Res;
import bisq.core.provider.fee.FeeService;
@ -147,16 +147,16 @@ public class MakeProposalView extends ActivatableView<GridPane, Void> {
createButton.setOnAction(null);
}
private void publishProposalAndStoreBallot(ProposalType type) {
private void publishMyProposal(ProposalType type) {
try {
final BallotWithTransaction ballotWithTransaction = getBallotWithTransaction(type);
Ballot ballot = ballotWithTransaction.getBallot();
final ProposalWithTransaction ballotWithTransaction = getBallotWithTransaction(type);
Proposal proposal = ballotWithTransaction.getProposal();
Transaction transaction = ballotWithTransaction.getTransaction();
Coin miningFee = transaction.getFee();
int txSize = transaction.bitcoinSerialize().length;
final Coin fee = daoFacade.getProposalFee();
GUIUtil.showBsqFeeInfoPopup(fee, miningFee, txSize, bsqFormatter, btcFormatter,
Res.get("dao.proposal"), () -> publishProposalAndStoreBallot(ballot, transaction));
Res.get("dao.proposal"), () -> doPublishMyProposal(proposal, transaction));
} catch (InsufficientMoneyException e) {
BSFormatter formatter = e instanceof InsufficientBsqException ? bsqFormatter : btcFormatter;
@ -178,8 +178,8 @@ public class MakeProposalView extends ActivatableView<GridPane, Void> {
}
}
private void publishProposalAndStoreBallot(Ballot ballot, Transaction transaction) {
daoFacade.publishBallot(ballot,
private void doPublishMyProposal(Proposal proposal, Transaction transaction) {
daoFacade.publishMyProposal(proposal,
transaction,
() -> {
proposalDisplay.clearForm();
@ -189,7 +189,7 @@ public class MakeProposalView extends ActivatableView<GridPane, Void> {
errorMessage -> new Popup<>().warning(errorMessage).show());
}
private BallotWithTransaction getBallotWithTransaction(ProposalType type)
private ProposalWithTransaction getBallotWithTransaction(ProposalType type)
throws InsufficientMoneyException, TransactionVerificationException, ValidationException,
WalletException, IOException {
@ -197,7 +197,7 @@ public class MakeProposalView extends ActivatableView<GridPane, Void> {
switch (type) {
case COMPENSATION_REQUEST:
return daoFacade.getCompensationBallotWithTransaction(proposalDisplay.nameTextField.getText(),
return daoFacade.getCompensationProposalWithTransaction(proposalDisplay.nameTextField.getText(),
proposalDisplay.titleTextField.getText(),
proposalDisplay.descriptionTextArea.getText(),
proposalDisplay.linkInputTextField.getText(),
@ -246,7 +246,7 @@ public class MakeProposalView extends ActivatableView<GridPane, Void> {
createButton.setOnAction(event -> {
// TODO break up in methods
if (GUIUtil.isReadyForTxBroadcast(p2PService, walletsSetup)) {
publishProposalAndStoreBallot(selectedProposalType);
publishMyProposal(selectedProposalType);
} else {
GUIUtil.showNotReadyForTxBroadcastPopups(p2PService, walletsSetup);
}

View file

@ -32,8 +32,6 @@ import bisq.desktop.util.Layout;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.dao.DaoFacade;
import bisq.core.dao.voting.ballot.BallotList;
import bisq.core.dao.voting.ballot.vote.BooleanVote;
import bisq.core.dao.voting.ballot.vote.Vote;
import bisq.core.locale.Res;
import bisq.core.user.Preferences;
@ -178,8 +176,9 @@ public class MyVotesView extends BaseProposalView {
@Override
protected void updateProposalList() {
if (selectedVoteListItem != null)
doUpdateProposalList(selectedVoteListItem.getMyVote().getBallotList().getList());
//TODO
//if (selectedVoteListItem != null)
// doUpdateProposalList(selectedVoteListItem.getMyVote().getBallotList().getList());
}
@ -363,7 +362,8 @@ public class MyVotesView extends BaseProposalView {
if (item != null && !empty) {
actionButtonIconView = new ImageView();
Vote vote = item.getBallot().getVote();
//TODO
/* Vote vote = item.getProposal().getVote();
if (vote instanceof BooleanVote) {
if (((BooleanVote) vote).isAccepted()) {
actionButtonIconView.setId("accepted");
@ -372,7 +372,7 @@ public class MyVotesView extends BaseProposalView {
}
} else {
//TODO
}
}*/
setGraphic(actionButtonIconView);
} else {