mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-22 11:39:29 +00:00
add mining fee padding to maker and taker reserve txs
This commit is contained in:
parent
2f1f1a788b
commit
54eee73c04
3 changed files with 26 additions and 10 deletions
|
@ -233,7 +233,6 @@ public class XmrWalletService {
|
|||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the reserve tx and freeze its inputs. The deposit amount is returned
|
||||
|
@ -244,7 +243,7 @@ public class XmrWalletService {
|
|||
* @param depositAmount the amount needed for the trade minus the trade fee
|
||||
* @return a transaction to reserve a trade
|
||||
*/
|
||||
public MoneroTxWallet createReserveTx(BigInteger tradeFee, String returnAddress, BigInteger depositAmount) {
|
||||
public MoneroTxWallet createReserveTx(BigInteger tradeFee, String returnAddress, BigInteger depositAmount, boolean freezeInputs) {
|
||||
MoneroWallet wallet = getWallet();
|
||||
synchronized (wallet) {
|
||||
|
||||
|
@ -262,8 +261,10 @@ public class XmrWalletService {
|
|||
.addDestination(returnAddress, depositAmount.add(miningFee.multiply(BigInteger.valueOf(3l))))); // add thrice the mining fee // TODO (woodser): really require more funds on top of security deposit?
|
||||
|
||||
// freeze inputs
|
||||
for (MoneroOutput input : reserveTx.getInputs()) {
|
||||
wallet.freezeOutput(input.getKeyImage().getHex());
|
||||
if (freezeInputs) {
|
||||
for (MoneroOutput input : reserveTx.getInputs()) {
|
||||
wallet.freezeOutput(input.getKeyImage().getHex());
|
||||
}
|
||||
}
|
||||
|
||||
return reserveTx;
|
||||
|
@ -343,7 +344,7 @@ public class XmrWalletService {
|
|||
if (!check.getReceivedAmount().equals(tradeFee)) throw new RuntimeException("Trade fee is incorrect amount, expected " + tradeFee + " but was " + check.getReceivedAmount());
|
||||
|
||||
// verify mining fee
|
||||
BigInteger feeEstimate = daemon.getFeeEstimate().multiply(BigInteger.valueOf(txHex.length())); // TODO (woodser): fee estimates are too high, use more accurate estimate
|
||||
BigInteger feeEstimate = getFeeEstimate(txHex);
|
||||
BigInteger feeThreshold = feeEstimate.multiply(BigInteger.valueOf(1l)).divide(BigInteger.valueOf(2l)); // must be at least 50% of estimated fee
|
||||
tx = daemon.getTx(txHash);
|
||||
if (tx.getFee().compareTo(feeThreshold) < 0) {
|
||||
|
@ -366,6 +367,11 @@ public class XmrWalletService {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO (woodser): fee estimates are too high, use more accurate estimate
|
||||
public BigInteger getFeeEstimate(String txHex) {
|
||||
return getDaemon().getFeeEstimate().multiply(BigInteger.valueOf(txHex.length()));
|
||||
}
|
||||
|
||||
public void shutDown() {
|
||||
closeAllWallets();
|
||||
}
|
||||
|
|
|
@ -43,11 +43,16 @@ public class MakerReservesOfferFunds extends Task<PlaceOfferModel> {
|
|||
try {
|
||||
runInterceptHook();
|
||||
|
||||
// freeze offer funds and get reserve tx
|
||||
// create tx to estimate fee
|
||||
String returnAddress = model.getXmrWalletService().getOrCreateAddressEntry(offer.getId(), XmrAddressEntry.Context.TRADE_PAYOUT).getAddressString();
|
||||
BigInteger makerFee = ParsingUtils.coinToAtomicUnits(offer.getMakerFee());
|
||||
BigInteger depositAmount = ParsingUtils.coinToAtomicUnits(model.getReservedFundsForOffer());
|
||||
MoneroTxWallet reserveTx = model.getXmrWalletService().createReserveTx(makerFee, returnAddress, depositAmount);
|
||||
MoneroTxWallet feeEstimateTx = model.getXmrWalletService().createReserveTx(makerFee, returnAddress, depositAmount, false);
|
||||
|
||||
// create reserve tx and freeze inputs
|
||||
BigInteger feeEstimate = model.getXmrWalletService().getFeeEstimate(feeEstimateTx.getFullHex());
|
||||
depositAmount = depositAmount.add(feeEstimate.multiply(BigInteger.valueOf(3)));
|
||||
MoneroTxWallet reserveTx = model.getXmrWalletService().createReserveTx(makerFee, returnAddress, depositAmount, true);
|
||||
|
||||
// collect reserved key images // TODO (woodser): switch to proof of reserve?
|
||||
List<String> reservedKeyImages = new ArrayList<String>();
|
||||
|
|
|
@ -39,12 +39,17 @@ public class TakerReservesTradeFunds extends TradeTask {
|
|||
try {
|
||||
runInterceptHook();
|
||||
|
||||
// freeze trade funds and get reserve tx
|
||||
// create tx to estimate fee
|
||||
String returnAddress = model.getXmrWalletService().getOrCreateAddressEntry(trade.getOffer().getId(), XmrAddressEntry.Context.TRADE_PAYOUT).getAddressString();
|
||||
BigInteger takerFee = ParsingUtils.coinToAtomicUnits(trade.getTakerFee());
|
||||
BigInteger depositAmount = ParsingUtils.centinerosToAtomicUnits(processModel.getFundsNeededForTradeAsLong());
|
||||
MoneroTxWallet reserveTx = model.getXmrWalletService().createReserveTx(takerFee, returnAddress, depositAmount);
|
||||
|
||||
MoneroTxWallet feeEstimateTx = model.getXmrWalletService().createReserveTx(takerFee, returnAddress, depositAmount, false);
|
||||
|
||||
// create reserve tx and freeze inputs
|
||||
BigInteger feeEstimate = model.getXmrWalletService().getFeeEstimate(feeEstimateTx.getFullHex());
|
||||
depositAmount = depositAmount.add(feeEstimate.multiply(BigInteger.valueOf(3)));
|
||||
MoneroTxWallet reserveTx = model.getXmrWalletService().createReserveTx(takerFee, returnAddress, depositAmount, true);
|
||||
|
||||
// collect reserved key images // TODO (woodser): switch to proof of reserve?
|
||||
List<String> reservedKeyImages = new ArrayList<String>();
|
||||
for (MoneroOutput input : reserveTx.getInputs()) reservedKeyImages.add(input.getKeyImage().getHex());
|
||||
|
|
Loading…
Reference in a new issue