mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-14 09:25:37 -04:00
use actual security deposits in dispute resolution
This commit is contained in:
parent
9f8bd77c9e
commit
48baa1e602
5 changed files with 39 additions and 29 deletions
|
@ -211,9 +211,9 @@ public class CoreDisputesService {
|
|||
*/
|
||||
public void applyPayoutAmountsToDisputeResult(DisputePayout payout, Dispute dispute, DisputeResult disputeResult, long customWinnerAmount) {
|
||||
Contract contract = dispute.getContract();
|
||||
Offer offer = new Offer(contract.getOfferPayload());
|
||||
Coin buyerSecurityDeposit = offer.getBuyerSecurityDeposit();
|
||||
Coin sellerSecurityDeposit = offer.getSellerSecurityDeposit();
|
||||
Trade trade = tradeManager.getTrade(dispute.getTradeId());
|
||||
Coin buyerSecurityDeposit = trade.getBuyerSecurityDeposit();
|
||||
Coin sellerSecurityDeposit = trade.getSellerSecurityDeposit();
|
||||
Coin tradeAmount = contract.getTradeAmount();
|
||||
if (payout == DisputePayout.BUYER_GETS_TRADE_AMOUNT) {
|
||||
disputeResult.setBuyerPayoutAmount(tradeAmount.add(buyerSecurityDeposit));
|
||||
|
|
|
@ -347,7 +347,7 @@ public class XmrWalletService {
|
|||
MoneroWallet wallet = getWallet();
|
||||
synchronized (wallet) {
|
||||
|
||||
// binary search to maximize security deposit, thereby minimizing potential dust
|
||||
// binary search to maximize security deposit and minimize potential dust
|
||||
MoneroTxWallet tradeTx = null;
|
||||
double appliedTolerance = 0.0; // percent of tolerance to apply, thereby decreasing security deposit
|
||||
double searchDiff = 1.0; // difference for next binary search
|
||||
|
|
|
@ -43,7 +43,6 @@ import bisq.core.trade.Trade;
|
|||
import bisq.core.trade.TradeDataValidation;
|
||||
import bisq.core.trade.TradeManager;
|
||||
import bisq.core.trade.protocol.TradingPeer;
|
||||
import bisq.core.util.ParsingUtils;
|
||||
import bisq.network.p2p.BootstrapListener;
|
||||
import bisq.network.p2p.NodeAddress;
|
||||
import bisq.network.p2p.P2PService;
|
||||
|
@ -740,7 +739,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
|
|||
if (!trade.isPayoutPublished()) {
|
||||
log.info("Arbitrator creating unsigned dispute payout tx for trade {}", trade.getId());
|
||||
try {
|
||||
MoneroTxWallet payoutTx = createDisputePayoutTx(trade, dispute, disputeResult, multisigWallet);
|
||||
MoneroTxWallet payoutTx = createDisputePayoutTx(trade, dispute, disputeResult);
|
||||
trade.setPayoutTx(payoutTx);
|
||||
trade.setPayoutTxHex(payoutTx.getTxSet().getMultisigTxHex());
|
||||
} catch (Exception e) {
|
||||
|
@ -829,10 +828,10 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
|
|||
// Utils
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private MoneroTxWallet createDisputePayoutTx(Trade trade, Dispute dispute, DisputeResult disputeResult, MoneroWallet multisigWallet) {
|
||||
private MoneroTxWallet createDisputePayoutTx(Trade trade, Dispute dispute, DisputeResult disputeResult) {
|
||||
|
||||
// multisig wallet must be synced
|
||||
if (multisigWallet.isMultisigImportNeeded()) throw new RuntimeException("Arbitrator's wallet needs updated multisig hex to create payout tx which means a trader must have already broadcast the payout tx for trade " + dispute.getTradeId());
|
||||
// trade wallet must be synced
|
||||
if (trade.getWallet().isMultisigImportNeeded()) throw new RuntimeException("Arbitrator's wallet needs updated multisig hex to create payout tx which means a trader must have already broadcast the payout tx for trade " + dispute.getTradeId());
|
||||
|
||||
// collect winner and loser payout address and amounts
|
||||
Contract contract = dispute.getContract();
|
||||
|
@ -847,7 +846,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
|
|||
MoneroTxConfig txConfig = new MoneroTxConfig().setAccountIndex(0).setRelay(false);
|
||||
if (winnerPayoutAmount.compareTo(BigInteger.ZERO) > 0) txConfig.addDestination(winnerPayoutAddress, winnerPayoutAmount.multiply(BigInteger.valueOf(9)).divide(BigInteger.valueOf(10))); // reduce payment amount to get fee of similar tx
|
||||
if (loserPayoutAmount.compareTo(BigInteger.ZERO) > 0) txConfig.addDestination(loserPayoutAddress, loserPayoutAmount.multiply(BigInteger.valueOf(9)).divide(BigInteger.valueOf(10)));
|
||||
MoneroTxWallet feeEstimateTx = multisigWallet.createTx(txConfig);
|
||||
MoneroTxWallet feeEstimateTx = trade.getWallet().createTx(txConfig);
|
||||
|
||||
// create payout tx by increasing estimated fee until successful
|
||||
MoneroTxWallet payoutTx = null;
|
||||
|
@ -862,7 +861,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
|
|||
}
|
||||
numAttempts++;
|
||||
try {
|
||||
payoutTx = multisigWallet.createTx(txConfig);
|
||||
payoutTx = trade.getWallet().createTx(txConfig);
|
||||
} catch (MoneroError e) {
|
||||
// exception expected // TODO: better way of estimating fee?
|
||||
}
|
||||
|
@ -871,7 +870,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
|
|||
log.info("Dispute payout transaction generated on attempt {}", numAttempts);
|
||||
|
||||
// save updated multisig hex
|
||||
trade.getSelf().setUpdatedMultisigHex(multisigWallet.exportMultisigHex());
|
||||
trade.getSelf().setUpdatedMultisigHex(trade.getWallet().exportMultisigHex());
|
||||
return payoutTx;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,6 +67,7 @@ import javafx.beans.property.StringProperty;
|
|||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.time.Clock;
|
||||
import java.util.ArrayList;
|
||||
|
@ -887,7 +888,7 @@ public abstract class Trade implements Tradable, Model {
|
|||
// by mediators and we keep the confirm disabled to avoid that the seller can complete the trade
|
||||
// without the penalty.
|
||||
long payoutAmountFromMediation = processModel.getSellerPayoutAmountFromMediation();
|
||||
long normalPayoutAmount = offer.getSellerSecurityDeposit().value;
|
||||
long normalPayoutAmount = getSellerSecurityDeposit().value;
|
||||
return payoutAmountFromMediation < normalPayoutAmount;
|
||||
}
|
||||
|
||||
|
@ -1361,6 +1362,14 @@ public abstract class Trade implements Tradable, Model {
|
|||
return offer.getMakerFee();
|
||||
}
|
||||
|
||||
public Coin getBuyerSecurityDeposit() {
|
||||
return HavenoUtils.atomicUnitsToCoin(getWallet().getTx(this.getBuyer().getDepositTxHash()).getIncomingAmount());
|
||||
}
|
||||
|
||||
public Coin getSellerSecurityDeposit() {
|
||||
return HavenoUtils.atomicUnitsToCoin(getWallet().getTx(this.getSeller().getDepositTxHash()).getIncomingAmount()).subtract(getAmount());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MoneroTxWallet getPayoutTx() {
|
||||
if (payoutTx == null)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue