From db76346cde8ad24c0aedb33166e24b42d493c160 Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Thu, 21 Jan 2021 12:13:05 -0600 Subject: [PATCH] Manual payout tool: prevent absurdly high fee payout - trims whitespace from numeric input fields before parsing - adds percentage display of the tx fee - validates that the tx fee percentage is not higher than 10% --- .../windows/ManualPayoutTxWindow.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/windows/ManualPayoutTxWindow.java b/desktop/src/main/java/bisq/desktop/main/overlays/windows/ManualPayoutTxWindow.java index 72874554570..4e311534099 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/windows/ManualPayoutTxWindow.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/windows/ManualPayoutTxWindow.java @@ -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; @@ -120,6 +121,7 @@ public class ManualPayoutTxWindow extends Overlay { InputTextField buyerPayoutAmount; InputTextField sellerPayoutAmount; InputTextField txFee; + InputTextField txFeePct; InputTextField buyerAddressString; InputTextField sellerAddressString; InputTextField buyerPubKeyAsHex; @@ -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); @@ -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() { @@ -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; @@ -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)); } } @@ -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();