mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-27 08:19:41 -05:00
stop trade protocol if timeout while creating reserve or deposit tx
This commit is contained in:
parent
db12f1c2cb
commit
7eabde63f3
@ -58,8 +58,7 @@ public class MakerReserveOfferFunds extends Task<PlaceOfferModel> {
|
|||||||
Integer preferredSubaddressIndex = fundingEntry == null ? null : fundingEntry.getSubaddressIndex();
|
Integer preferredSubaddressIndex = fundingEntry == null ? null : fundingEntry.getSubaddressIndex();
|
||||||
MoneroTxWallet reserveTx = model.getXmrWalletService().createReserveTx(makerFee, sendAmount, securityDeposit, returnAddress, model.getOpenOffer().isReserveExactAmount(), preferredSubaddressIndex);
|
MoneroTxWallet reserveTx = model.getXmrWalletService().createReserveTx(makerFee, sendAmount, securityDeposit, returnAddress, model.getOpenOffer().isReserveExactAmount(), preferredSubaddressIndex);
|
||||||
|
|
||||||
// check for error in case creating reserve tx exceeded timeout
|
// check for error in case creating reserve tx exceeded timeout // TODO: better way?
|
||||||
// TODO: better way?
|
|
||||||
if (!model.getXmrWalletService().getAddressEntry(offer.getId(), XmrAddressEntry.Context.TRADE_PAYOUT).isPresent()) {
|
if (!model.getXmrWalletService().getAddressEntry(offer.getId(), XmrAddressEntry.Context.TRADE_PAYOUT).isPresent()) {
|
||||||
throw new RuntimeException("An error has occurred posting offer " + offer.getId() + " causing its subaddress entry to be deleted");
|
throw new RuntimeException("An error has occurred posting offer " + offer.getId() + " causing its subaddress entry to be deleted");
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import haveno.core.trade.MakerTrade;
|
|||||||
import haveno.core.trade.Trade;
|
import haveno.core.trade.Trade;
|
||||||
import haveno.core.trade.Trade.State;
|
import haveno.core.trade.Trade.State;
|
||||||
import haveno.core.trade.messages.SignContractRequest;
|
import haveno.core.trade.messages.SignContractRequest;
|
||||||
|
import haveno.core.trade.protocol.TradeProtocol;
|
||||||
import haveno.core.xmr.model.XmrAddressEntry;
|
import haveno.core.xmr.model.XmrAddressEntry;
|
||||||
import haveno.network.p2p.SendDirectMessageListener;
|
import haveno.network.p2p.SendDirectMessageListener;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -85,6 +86,14 @@ public class MaybeSendSignContractRequest extends TradeTask {
|
|||||||
}
|
}
|
||||||
MoneroTxWallet depositTx = trade.getXmrWalletService().createDepositTx(trade, reserveExactAmount, subaddressIndex);
|
MoneroTxWallet depositTx = trade.getXmrWalletService().createDepositTx(trade, reserveExactAmount, subaddressIndex);
|
||||||
|
|
||||||
|
// check if trade still exists
|
||||||
|
if (!processModel.getTradeManager().hasOpenTrade(trade)) {
|
||||||
|
throw new RuntimeException("Trade protocol has timed out while creating reserve tx, tradeId=" + trade.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset protocol timeout
|
||||||
|
trade.getProtocol().startTimeout(TradeProtocol.TRADE_TIMEOUT);
|
||||||
|
|
||||||
// collect reserved key images
|
// collect reserved key images
|
||||||
List<String> reservedKeyImages = new ArrayList<String>();
|
List<String> reservedKeyImages = new ArrayList<String>();
|
||||||
for (MoneroOutput input : depositTx.getInputs()) reservedKeyImages.add(input.getKeyImage().getHex());
|
for (MoneroOutput input : depositTx.getInputs()) reservedKeyImages.add(input.getKeyImage().getHex());
|
||||||
|
@ -47,15 +47,15 @@ public class TakerReserveTradeFunds extends TradeTask {
|
|||||||
String returnAddress = model.getXmrWalletService().getOrCreateAddressEntry(trade.getOffer().getId(), XmrAddressEntry.Context.TRADE_PAYOUT).getAddressString();
|
String returnAddress = model.getXmrWalletService().getOrCreateAddressEntry(trade.getOffer().getId(), XmrAddressEntry.Context.TRADE_PAYOUT).getAddressString();
|
||||||
MoneroTxWallet reserveTx = model.getXmrWalletService().createReserveTx(takerFee, sendAmount, securityDeposit, returnAddress, false, null);
|
MoneroTxWallet reserveTx = model.getXmrWalletService().createReserveTx(takerFee, sendAmount, securityDeposit, returnAddress, false, null);
|
||||||
|
|
||||||
|
// check if trade still exists
|
||||||
|
if (!processModel.getTradeManager().hasOpenTrade(trade)) {
|
||||||
|
throw new RuntimeException("Trade protocol has timed out while creating reserve tx, tradeId=" + trade.getId());
|
||||||
|
}
|
||||||
|
|
||||||
// collect reserved key images
|
// collect reserved key images
|
||||||
List<String> reservedKeyImages = new ArrayList<String>();
|
List<String> reservedKeyImages = new ArrayList<String>();
|
||||||
for (MoneroOutput input : reserveTx.getInputs()) reservedKeyImages.add(input.getKeyImage().getHex());
|
for (MoneroOutput input : reserveTx.getInputs()) reservedKeyImages.add(input.getKeyImage().getHex());
|
||||||
|
|
||||||
// check if trade still exists
|
|
||||||
if (!processModel.getTradeManager().hasOpenTrade(trade)) {
|
|
||||||
throw new RuntimeException("Trade protocol no longer exists after creating reserve tx, tradeId=" + trade.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset protocol timeout
|
// reset protocol timeout
|
||||||
trade.getProtocol().startTimeout(TradeProtocol.TRADE_TIMEOUT);
|
trade.getProtocol().startTimeout(TradeProtocol.TRADE_TIMEOUT);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user