Skip to content

Commit

Permalink
Merge pull request #5099 from jmacxx/bugfix_emerg_payout_tool
Browse files Browse the repository at this point in the history
Manual payout tool: prevent absurdly high fee payout
  • Loading branch information
ripcurlx authored Jan 22, 2021
2 parents 334fbdb + db76346 commit 5b0716e
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.util.GUIUtil;
import bisq.desktop.util.validation.LengthValidator;
import bisq.desktop.util.validation.PercentageNumberValidator;

import bisq.core.btc.exceptions.TransactionVerificationException;
import bisq.core.btc.exceptions.TxBroadcastException;
Expand Down Expand Up @@ -120,6 +121,7 @@ public class ManualPayoutTxWindow extends Overlay<ManualPayoutTxWindow> {
InputTextField buyerPayoutAmount;
InputTextField sellerPayoutAmount;
InputTextField txFee;
InputTextField txFeePct;
InputTextField buyerAddressString;
InputTextField sellerAddressString;
InputTextField buyerPubKeyAsHex;
Expand Down Expand Up @@ -317,7 +319,13 @@ private void addInputsPane() {
sellerPayoutAmount = addInputTextField(inputsGridPane, rowIndexA, "sellerPayoutAmount");
txFee = addInputTextField(inputsGridPane, rowIndexA, "Tx fee");
txFee.setEditable(false);
HBox hBox = new HBox(12, buyerPayoutAmount, sellerPayoutAmount, txFee);
txFeePct = addInputTextField(inputsGridPane, rowIndexA, "Tx fee %");
txFeePct.setEditable(false);
PercentageNumberValidator validator = new PercentageNumberValidator();
validator.setMaxValue(10D);
txFeePct.setValidator(validator);

HBox hBox = new HBox(12, buyerPayoutAmount, sellerPayoutAmount, txFee, txFeePct);
hBox.setAlignment(Pos.BASELINE_LEFT);
hBox.setPrefWidth(800);
inputsGridPane.add(hBox, 0, ++rowIndexA);
Expand Down Expand Up @@ -519,7 +527,8 @@ private boolean validateInputFields() {
buyerAddressString.getText().length() > 0 &&
sellerAddressString.getText().length() > 0 &&
buyerPubKeyAsHex.getText().length() == HEX_PUBKEY_LENGTH &&
sellerPubKeyAsHex.getText().length() == HEX_PUBKEY_LENGTH);
sellerPubKeyAsHex.getText().length() == HEX_PUBKEY_LENGTH &&
txFeePct.getValidator().validate(txFeePct.getText()).isValid);
}

private boolean validateInputFieldsAndSignatures() {
Expand All @@ -530,7 +539,7 @@ private boolean validateInputFieldsAndSignatures() {

private Coin getInputFieldAsCoin(InputTextField inputTextField) {
try {
return Coin.parseCoin(inputTextField.getText());
return Coin.parseCoin(inputTextField.getText().trim());
} catch (RuntimeException ignore) {
}
return Coin.ZERO;
Expand All @@ -544,6 +553,8 @@ private void calculateTxFee() {
.subtract(getInputFieldAsCoin(buyerPayoutAmount))
.subtract(getInputFieldAsCoin(sellerPayoutAmount));
txFee.setText(txFeeValue.toPlainString());
double feePercent = (double) txFeeValue.value / getInputFieldAsCoin(amountInMultisig).value;
txFeePct.setText(String.format("%.2f", feePercent * 100));
}
}

Expand Down Expand Up @@ -717,7 +728,7 @@ private String buildFinalTx(boolean broadcastIt) {
TxBroadcaster.Callback callback = new TxBroadcaster.Callback() {
@Override
public void onSuccess(@Nullable Transaction result) {
log.error("onSuccess");
log.info("onSuccess");
UserThread.execute(() -> {
String txId = result != null ? result.getTxId().toString() : "null";
new Popup().information("Transaction successfully published. Transaction ID: " + txId).show();
Expand Down

0 comments on commit 5b0716e

Please sign in to comment.