mirror of
https://github.com/retoaccess1/haveno-reto.git
synced 2024-12-12 12:53:32 +01:00
synchronize on lock to prepare payment sent or received
This commit is contained in:
parent
5c4fa7a53f
commit
6db4812f06
@ -36,6 +36,7 @@ package haveno.core.trade.protocol.tasks;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import haveno.common.taskrunner.TaskRunner;
|
||||
import haveno.core.trade.HavenoUtils;
|
||||
import haveno.core.trade.Trade;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import monero.wallet.MoneroWallet;
|
||||
@ -79,15 +80,21 @@ public class BuyerPreparePaymentSentMessage extends TradeTask {
|
||||
// create payout tx if we have seller's updated multisig hex
|
||||
if (trade.getSeller().getUpdatedMultisigHex() != null) {
|
||||
|
||||
// import multisig hex
|
||||
trade.importMultisigHex();
|
||||
// synchronize on lock for wallet operations
|
||||
synchronized (trade.getWalletLock()) {
|
||||
synchronized (HavenoUtils.getWalletFunctionLock()) {
|
||||
|
||||
// create payout tx
|
||||
log.info("Buyer creating unsigned payout tx for {} {} ", trade.getClass().getSimpleName(), trade.getShortId());
|
||||
MoneroTxWallet payoutTx = trade.createPayoutTx();
|
||||
trade.updatePayout(payoutTx);
|
||||
trade.getSelf().setUnsignedPayoutTxHex(payoutTx.getTxSet().getMultisigTxHex());
|
||||
trade.requestPersistence();
|
||||
// import multisig hex
|
||||
trade.importMultisigHex();
|
||||
|
||||
// create payout tx
|
||||
log.info("Buyer creating unsigned payout tx for {} {} ", trade.getClass().getSimpleName(), trade.getShortId());
|
||||
MoneroTxWallet payoutTx = trade.createPayoutTx();
|
||||
trade.updatePayout(payoutTx);
|
||||
trade.getSelf().setUnsignedPayoutTxHex(payoutTx.getTxSet().getMultisigTxHex());
|
||||
trade.requestPersistence();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
complete();
|
||||
|
@ -19,6 +19,7 @@ package haveno.core.trade.protocol.tasks;
|
||||
|
||||
import haveno.common.taskrunner.TaskRunner;
|
||||
import haveno.core.support.dispute.Dispute;
|
||||
import haveno.core.trade.HavenoUtils;
|
||||
import haveno.core.trade.Trade;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import monero.wallet.model.MoneroTxWallet;
|
||||
@ -49,34 +50,40 @@ public class SellerPreparePaymentReceivedMessage extends TradeTask {
|
||||
trade.setPayoutTxHex(null);
|
||||
}
|
||||
|
||||
// import multisig hex unless already signed
|
||||
if (trade.getPayoutTxHex() == null) {
|
||||
trade.importMultisigHex();
|
||||
}
|
||||
// synchronize on lock for wallet operations
|
||||
synchronized (trade.getWalletLock()) {
|
||||
synchronized (HavenoUtils.getWalletFunctionLock()) {
|
||||
|
||||
// verify, sign, and publish payout tx if given
|
||||
if (trade.getBuyer().getPaymentSentMessage().getPayoutTxHex() != null) {
|
||||
try {
|
||||
// import multisig hex unless already signed
|
||||
if (trade.getPayoutTxHex() == null) {
|
||||
log.info("Seller verifying, signing, and publishing payout tx for trade {}", trade.getId());
|
||||
trade.processPayoutTx(trade.getBuyer().getPaymentSentMessage().getPayoutTxHex(), true, true);
|
||||
} else {
|
||||
log.warn("Seller publishing previously signed payout tx for trade {}", trade.getId());
|
||||
trade.processPayoutTx(trade.getPayoutTxHex(), false, true);
|
||||
trade.importMultisigHex();
|
||||
}
|
||||
|
||||
// verify, sign, and publish payout tx if given
|
||||
if (trade.getBuyer().getPaymentSentMessage().getPayoutTxHex() != null) {
|
||||
try {
|
||||
if (trade.getPayoutTxHex() == null) {
|
||||
log.info("Seller verifying, signing, and publishing payout tx for trade {}", trade.getId());
|
||||
trade.processPayoutTx(trade.getBuyer().getPaymentSentMessage().getPayoutTxHex(), true, true);
|
||||
} else {
|
||||
log.warn("Seller publishing previously signed payout tx for trade {}", trade.getId());
|
||||
trade.processPayoutTx(trade.getPayoutTxHex(), false, true);
|
||||
}
|
||||
} catch (IllegalArgumentException | IllegalStateException e) {
|
||||
log.warn("Illegal state or argument verifying, signing, and publishing payout tx for {} {}. Creating new unsigned payout tx. error={}. ", trade.getClass().getSimpleName(), trade.getId(), e.getMessage(), e);
|
||||
createUnsignedPayoutTx();
|
||||
} catch (Exception e) {
|
||||
log.warn("Error verifying, signing, and publishing payout tx for trade {}: {}", trade.getId(), e.getMessage(), e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise create unsigned payout tx
|
||||
else if (trade.getSelf().getUnsignedPayoutTxHex() == null) {
|
||||
createUnsignedPayoutTx();
|
||||
}
|
||||
} catch (IllegalArgumentException | IllegalStateException e) {
|
||||
log.warn("Illegal state or argument verifying, signing, and publishing payout tx for {} {}: {}. Creating new unsigned payout tx", trade.getClass().getSimpleName(), trade.getId(), e.getMessage(), e);
|
||||
createUnsignedPayoutTx();
|
||||
} catch (Exception e) {
|
||||
log.warn("Error verifying, signing, and publishing payout tx for trade {}: {}", trade.getId(), e.getMessage(), e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise create unsigned payout tx
|
||||
else if (trade.getSelf().getUnsignedPayoutTxHex() == null) {
|
||||
createUnsignedPayoutTx();
|
||||
}
|
||||
} else if (trade.getArbitrator().getPaymentReceivedMessage().getSignedPayoutTxHex() != null && !trade.isPayoutPublished()) {
|
||||
|
||||
// republish payout tx from previous message
|
||||
|
Loading…
Reference in New Issue
Block a user