Changes from review of bond confiscation PR

This commit is contained in:
Manfred Karrer 2018-07-22 00:12:20 +02:00
parent 86c3f248eb
commit 68e2389c30
No known key found for this signature in database
GPG Key ID: 401250966A6B2C46
3 changed files with 28 additions and 21 deletions

View File

@ -44,6 +44,8 @@ import bisq.core.util.validation.StringValidator;
import bisq.network.p2p.P2PService;
import bisq.common.util.Utilities;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.InsufficientMoneyException;
@ -60,6 +62,7 @@ import javafx.collections.FXCollections;
import javafx.util.StringConverter;
import java.util.Arrays;
import java.util.Optional;
import static bisq.desktop.util.FormBuilder.addButtonAfterGroup;
import static bisq.desktop.util.FormBuilder.addLabelComboBox;
@ -153,7 +156,10 @@ public class LockupView extends ActivatableView<GridPane, Void> implements BsqBa
bondIdInputTextField = addLabelInputTextField(root, ++gridRow, Res.get("dao.bonding.lock.bondId"), Layout.GRID_GAP).second;
bondIdInputTextField.setPromptText(Res.get("dao.bonding.lock.setBondId"));
bondIdInputTextField.setValidator(bondIdValidator);
// TODO atm it does not make sense to validate as we dont use real data
// data should get derived anyway sfrom human readable sources
//bondIdInputTextField.setValidator(bondIdValidator);
lockupButton = addButtonAfterGroup(root, ++gridRow, Res.get("dao.bonding.lock.lockupButton"));
lockupButton.setOnAction((event) -> {
@ -161,12 +167,12 @@ public class LockupView extends ActivatableView<GridPane, Void> implements BsqBa
Coin lockupAmount = bsqFormatter.parseToCoin(amountInputTextField.getText());
int lockupTime = Integer.parseInt(timeInputTextField.getText());
LockupType type = lockupTypeComboBox.getValue();
// TODO get hash of something
// byte[] bytes = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
byte[] bytes = bondIdInputTextField.getText().getBytes();
if (type != LockupType.BONDED_ROLE)
bytes = null;
final byte[] hash = bytes;
//TODO use mapping to human readable input
Optional<byte[]> hashOfBondId;
if (type == LockupType.BONDED_ROLE)
hashOfBondId = Optional.of(Utilities.decodeFromHex(bondIdInputTextField.getText()));
else
hashOfBondId = Optional.empty();
new Popup<>().headLine(Res.get("dao.bonding.lock.sendFunds.headline"))
.confirmation(Res.get("dao.bonding.lock.sendFunds.details",
@ -178,7 +184,7 @@ public class LockupView extends ActivatableView<GridPane, Void> implements BsqBa
daoFacade.publishLockupTx(lockupAmount,
lockupTime,
type,
hash,
hashOfBondId,
() -> {
new Popup<>().feedback(Res.get("dao.tx.published.success")).show();
},

View File

@ -86,6 +86,7 @@ public class ProposalDisplay {
public InputTextField requestedBsqTextField, bsqAddressTextField, paramValueTextField;
@Nullable
public ComboBox<Param> paramComboBox;
@Nullable
public ComboBox<byte[]> confiscateBondComboBox;
@Getter
private int gridRow;
@ -175,13 +176,13 @@ public class ProposalDisplay {
requestedBsqTextField = addLabelInputTextField(gridPane, ++gridRow, Res.get("dao.proposal.display.requestedBsq")).second;
BsqValidator bsqValidator = new BsqValidator(bsqFormatter);
bsqValidator.setMinValue(CompensationConsensus.getMinCompensationRequestAmount());
checkNotNull(requestedBsqTextField, "requestedBsqTextField must no tbe null");
checkNotNull(requestedBsqTextField, "requestedBsqTextField must not be null");
requestedBsqTextField.setValidator(bsqValidator);
// TODO validator, addressTF
if (showDetails) {
bsqAddressTextField = addLabelInputTextField(gridPane, ++gridRow,
Res.get("dao.proposal.display.bsqAddress")).second;
checkNotNull(bsqAddressTextField, "bsqAddressTextField must no tbe null");
checkNotNull(bsqAddressTextField, "bsqAddressTextField must not be null");
bsqAddressTextField.setText("B" + bsqWalletService.getUnusedAddress().toBase58());
bsqAddressTextField.setValidator(new BsqAddressValidator(bsqFormatter));
}
@ -189,9 +190,9 @@ public class ProposalDisplay {
case GENERIC:
break;
case CHANGE_PARAM:
checkNotNull(gridPane, "gridPane must no tbe null");
checkNotNull(gridPane, "gridPane must not be null");
paramComboBox = addLabelComboBox(gridPane, ++gridRow, Res.get("dao.proposal.display.paramComboBox.label")).second;
checkNotNull(paramComboBox, "paramComboBox must no tbe null");
checkNotNull(paramComboBox, "paramComboBox must not be null");
paramComboBox.setItems(FXCollections.observableArrayList(Param.values()));
paramComboBox.setConverter(new StringConverter<Param>() {
@Override
@ -211,13 +212,13 @@ public class ProposalDisplay {
case CONFISCATE_BOND:
confiscateBondComboBox = addLabelComboBox(gridPane, ++gridRow,
Res.get("dao.proposal.display.confiscateBondComboBox.label")).second;
ObservableList<byte[]> confiscatableBonds =
ObservableList<byte[]> lockupAndUnlockingBondIds =
FXCollections.observableArrayList(daoFacade.getLockupAndUnlockingBondIds());
// confiscatableBonds.addAll("bond1", "bond2", "bond3");
confiscateBondComboBox.setItems(confiscatableBonds);
confiscateBondComboBox.setItems(lockupAndUnlockingBondIds);
confiscateBondComboBox.setConverter(new StringConverter<byte[]>() {
@Override
public String toString(byte[] id) {
//TODO map to some human readable data source
return Utilities.bytesAsHexString(id);
}
@ -253,7 +254,7 @@ public class ProposalDisplay {
linkHyperlinkWithIcon.setOnAction(e -> GUIUtil.openWebPage(proposal.getLink()));
if (proposal instanceof CompensationProposal) {
CompensationProposal compensationProposal = (CompensationProposal) proposal;
checkNotNull(requestedBsqTextField, "requestedBsqTextField must no tbe null");
checkNotNull(requestedBsqTextField, "requestedBsqTextField must not be null");
requestedBsqTextField.setText(bsqFormatter.formatCoinWithCode(compensationProposal.getRequestedBsq()));
if (bsqAddressTextField != null)
bsqAddressTextField.setText(compensationProposal.getBsqAddress());
@ -261,12 +262,12 @@ public class ProposalDisplay {
ChangeParamProposal changeParamProposal = (ChangeParamProposal) proposal;
checkNotNull(paramComboBox, "paramComboBox must not be null");
paramComboBox.getSelectionModel().select(changeParamProposal.getParam());
checkNotNull(paramValueTextField, "paramValueTextField must no tbe null");
checkNotNull(paramValueTextField, "paramValueTextField must not be null");
paramValueTextField.setText(String.valueOf(changeParamProposal.getParamValue()));
} else if (proposal instanceof ConfiscateBondProposal) {
ConfiscateBondProposal confiscateBondProposal = (ConfiscateBondProposal) proposal;
checkNotNull(confiscateBondComboBox, "confiscateBondComboBox must not be null");
confiscateBondComboBox.getSelectionModel().select(confiscateBondProposal.getBondId());
confiscateBondComboBox.getSelectionModel().select(confiscateBondProposal.getHashOfBondId());
}
int chainHeight;
if (txIdTextField != null) {

View File

@ -283,15 +283,15 @@ public class MakeProposalView extends ActivatableView<GridPane, Void> implements
//TODO
throw new RuntimeException("Not implemented yet");
case CONFISCATE_BOND:
byte[] bondId = proposalDisplay.confiscateBondComboBox.getSelectionModel().getSelectedItem();
if (bondId == null || bondId.length == 0)
byte[] hashOfBondId = proposalDisplay.confiscateBondComboBox.getSelectionModel().getSelectedItem();
if (hashOfBondId == null || hashOfBondId.length == 0)
throw new ValidationException("Invalid bond id, null or zero length");
return daoFacade.getConfiscateBondProposalWithTransaction(proposalDisplay.nameTextField.getText(),
proposalDisplay.titleTextField.getText(),
proposalDisplay.descriptionTextArea.getText(),
proposalDisplay.linkInputTextField.getText(),
bondId);
hashOfBondId);
default:
final String msg = "Undefined ProposalType " + selectedProposalType;
log.error(msg);