mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-02 11:46:11 -04:00
seller state is PAYMENT_RECEIVED or PAYOUT_PUBLISHED after confirming
This commit is contained in:
parent
730bee3e71
commit
2d3043093e
12 changed files with 95 additions and 68 deletions
|
@ -154,21 +154,24 @@ public abstract class Trade implements Tradable, Model {
|
|||
|
||||
|
||||
// #################### Phase PAYMENT_SENT
|
||||
BUYER_CONFIRMED_IN_UI_PAYMENT_INITIATED(Phase.PAYMENT_SENT),
|
||||
BUYER_SENT_PAYMENT_INITIATED_MSG(Phase.PAYMENT_SENT),
|
||||
BUYER_SAW_ARRIVED_PAYMENT_INITIATED_MSG(Phase.PAYMENT_SENT),
|
||||
BUYER_STORED_IN_MAILBOX_PAYMENT_INITIATED_MSG(Phase.PAYMENT_SENT),
|
||||
BUYER_SEND_FAILED_PAYMENT_INITIATED_MSG(Phase.PAYMENT_SENT),
|
||||
BUYER_CONFIRMED_IN_UI_PAYMENT_SENT(Phase.PAYMENT_SENT),
|
||||
BUYER_SENT_PAYMENT_SENT_MSG(Phase.PAYMENT_SENT),
|
||||
BUYER_SAW_ARRIVED_PAYMENT_SENT_MSG(Phase.PAYMENT_SENT),
|
||||
BUYER_STORED_IN_MAILBOX_PAYMENT_SENT_MSG(Phase.PAYMENT_SENT),
|
||||
BUYER_SEND_FAILED_PAYMENT_SENT_MSG(Phase.PAYMENT_SENT),
|
||||
|
||||
SELLER_RECEIVED_PAYMENT_INITIATED_MSG(Phase.PAYMENT_SENT),
|
||||
SELLER_RECEIVED_PAYMENT_SENT_MSG(Phase.PAYMENT_SENT),
|
||||
|
||||
// #################### Phase PAYMENT_RECEIVED
|
||||
// note that this state can also be triggered by auto confirmation feature
|
||||
SELLER_CONFIRMED_IN_UI_PAYMENT_RECEIPT(Phase.PAYMENT_RECEIVED),
|
||||
SELLER_SENT_PAYMENT_RECEIVED_MSG(Phase.PAYMENT_RECEIVED),
|
||||
SELLER_SAW_ARRIVED_PAYMENT_RECEIVED_MSG(Phase.PAYMENT_RECEIVED),
|
||||
SELLER_STORED_IN_MAILBOX_PAYMENT_RECEIVED_MSG(Phase.PAYMENT_RECEIVED),
|
||||
SELLER_SEND_FAILED_PAYMENT_RECEIVED_MSG(Phase.PAYMENT_RECEIVED),
|
||||
|
||||
// #################### Phase PAYOUT_PUBLISHED
|
||||
SELLER_PUBLISHED_PAYOUT_TX(Phase.PAYOUT_PUBLISHED), // TODO (woodser): this enum is over used, like during arbitration
|
||||
|
||||
SELLER_SENT_PAYOUT_TX_PUBLISHED_MSG(Phase.PAYOUT_PUBLISHED),
|
||||
SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG(Phase.PAYOUT_PUBLISHED),
|
||||
SELLER_STORED_IN_MAILBOX_PAYOUT_TX_PUBLISHED_MSG(Phase.PAYOUT_PUBLISHED),
|
||||
|
@ -850,10 +853,10 @@ public abstract class Trade implements Tradable, Model {
|
|||
walletService.closeMultisigWallet(getId());
|
||||
|
||||
// update trade state
|
||||
this.getSelf().setPayoutTxHex(signedPayoutTxHex);
|
||||
this.setPayoutTx(parsedTxSet.getTxs().get(0));
|
||||
this.setPayoutTxId(parsedTxSet.getTxs().get(0).getHash());
|
||||
this.setState(Trade.State.SELLER_PUBLISHED_PAYOUT_TX);
|
||||
getSelf().setPayoutTxHex(signedPayoutTxHex);
|
||||
setPayoutTx(parsedTxSet.getTxs().get(0));
|
||||
setPayoutTxId(parsedTxSet.getTxs().get(0).getHash());
|
||||
setState(isBuyer() ? Trade.State.BUYER_PUBLISHED_PAYOUT_TX : Trade.State.SELLER_PUBLISHED_PAYOUT_TX);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1116,26 +1119,42 @@ public abstract class Trade implements Tradable, Model {
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getter
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public boolean isBuyer() {
|
||||
return offer.getDirection() == Direction.BUY;
|
||||
}
|
||||
|
||||
public boolean isSeller() {
|
||||
return offer.getDirection() == Direction.SELL;
|
||||
}
|
||||
|
||||
public boolean isMaker() {
|
||||
return this instanceof MakerTrade;
|
||||
}
|
||||
|
||||
public boolean isTaker() {
|
||||
return this instanceof TakerTrade;
|
||||
}
|
||||
|
||||
public TradingPeer getSelf() {
|
||||
if (this instanceof MakerTrade) return processModel.getMaker();
|
||||
if (this instanceof TakerTrade) return processModel.getTaker();
|
||||
if (this instanceof ArbitratorTrade) return processModel.getArbitrator();
|
||||
throw new RuntimeException("Trade is not maker, taker, or arbitrator");
|
||||
}
|
||||
|
||||
|
||||
public TradingPeer getMaker() {
|
||||
return processModel.getMaker();
|
||||
}
|
||||
|
||||
|
||||
public TradingPeer getTaker() {
|
||||
return processModel.getTaker();
|
||||
}
|
||||
|
||||
|
||||
public TradingPeer getBuyer() {
|
||||
return offer.getDirection() == Direction.BUY ? processModel.getMaker() : processModel.getTaker();
|
||||
}
|
||||
|
||||
|
||||
public TradingPeer getSeller() {
|
||||
return offer.getDirection() == Direction.BUY ? processModel.getTaker() : processModel.getMaker();
|
||||
}
|
||||
|
|
|
@ -69,8 +69,8 @@ public abstract class BuyerProtocol extends DisputeProtocol {
|
|||
.executeTasks();
|
||||
|
||||
given(anyPhase(Trade.Phase.PAYMENT_SENT, Trade.Phase.PAYMENT_RECEIVED)
|
||||
.anyState(Trade.State.BUYER_STORED_IN_MAILBOX_PAYMENT_INITIATED_MSG,
|
||||
Trade.State.BUYER_SEND_FAILED_PAYMENT_INITIATED_MSG)
|
||||
.anyState(Trade.State.BUYER_STORED_IN_MAILBOX_PAYMENT_SENT_MSG,
|
||||
Trade.State.BUYER_SEND_FAILED_PAYMENT_SENT_MSG)
|
||||
.with(BuyerEvent.STARTUP))
|
||||
.setup(tasks(BuyerSendsPaymentSentMessage.class))
|
||||
.executeTasks();
|
||||
|
@ -151,7 +151,7 @@ public abstract class BuyerProtocol extends DisputeProtocol {
|
|||
errorMessageHandler.handleErrorMessage(errorMessage);
|
||||
handleTaskRunnerFault(event, errorMessage);
|
||||
})))
|
||||
.run(() -> trade.setState(Trade.State.BUYER_CONFIRMED_IN_UI_PAYMENT_INITIATED))
|
||||
.run(() -> trade.setState(Trade.State.BUYER_CONFIRMED_IN_UI_PAYMENT_SENT))
|
||||
.executeTasks();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ public abstract class SellerProtocol extends DisputeProtocol {
|
|||
synchronized (trade) {
|
||||
SellerEvent event = SellerEvent.PAYMENT_RECEIVED;
|
||||
// CountDownLatch latch = new CountDownLatch(1); // TODO (woodser): user countdown latch, but freezes legacy app
|
||||
expect(anyPhase(Trade.Phase.PAYMENT_SENT, Trade.Phase.PAYOUT_PUBLISHED)
|
||||
expect(anyPhase(Trade.Phase.PAYMENT_SENT)
|
||||
.with(event)
|
||||
.preCondition(trade.confirmPermitted()))
|
||||
.setup(tasks(
|
||||
|
|
|
@ -89,8 +89,8 @@ public class BuyerSendsPaymentSentMessage extends SendMailboxMessageTask {
|
|||
|
||||
@Override
|
||||
protected void setStateSent() {
|
||||
if (trade.getState().ordinal() < Trade.State.BUYER_SENT_PAYMENT_INITIATED_MSG.ordinal()) {
|
||||
trade.setStateIfValidTransitionTo(Trade.State.BUYER_SENT_PAYMENT_INITIATED_MSG);
|
||||
if (trade.getState().ordinal() < Trade.State.BUYER_SENT_PAYMENT_SENT_MSG.ordinal()) {
|
||||
trade.setStateIfValidTransitionTo(Trade.State.BUYER_SENT_PAYMENT_SENT_MSG);
|
||||
}
|
||||
|
||||
processModel.getTradeManager().requestPersistence();
|
||||
|
@ -112,7 +112,7 @@ public class BuyerSendsPaymentSentMessage extends SendMailboxMessageTask {
|
|||
|
||||
@Override
|
||||
protected void setStateStoredInMailbox() {
|
||||
trade.setStateIfValidTransitionTo(Trade.State.BUYER_STORED_IN_MAILBOX_PAYMENT_INITIATED_MSG);
|
||||
trade.setStateIfValidTransitionTo(Trade.State.BUYER_STORED_IN_MAILBOX_PAYMENT_SENT_MSG);
|
||||
if (!trade.isPayoutPublished()) {
|
||||
tryToSendAgainLater();
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ public class BuyerSendsPaymentSentMessage extends SendMailboxMessageTask {
|
|||
|
||||
@Override
|
||||
protected void setStateFault() {
|
||||
trade.setStateIfValidTransitionTo(Trade.State.BUYER_SEND_FAILED_PAYMENT_INITIATED_MSG);
|
||||
trade.setStateIfValidTransitionTo(Trade.State.BUYER_SEND_FAILED_PAYMENT_SENT_MSG);
|
||||
if (!trade.isPayoutPublished()) {
|
||||
tryToSendAgainLater();
|
||||
}
|
||||
|
@ -192,8 +192,8 @@ public class BuyerSendsPaymentSentMessage extends SendMailboxMessageTask {
|
|||
private void onMessageStateChange(MessageState newValue) {
|
||||
// Once we receive an ACK from our msg we know the peer has received the msg and we stop.
|
||||
if (newValue == MessageState.ACKNOWLEDGED) {
|
||||
// We treat a ACK like BUYER_SAW_ARRIVED_PAYMENT_INITIATED_MSG
|
||||
trade.setStateIfValidTransitionTo(Trade.State.BUYER_SAW_ARRIVED_PAYMENT_INITIATED_MSG);
|
||||
// We treat a ACK like BUYER_SAW_ARRIVED_PAYMENT_SENT_MSG
|
||||
trade.setStateIfValidTransitionTo(Trade.State.BUYER_SAW_ARRIVED_PAYMENT_SENT_MSG);
|
||||
|
||||
processModel.getTradeManager().requestPersistence();
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public class SellerProcessesPaymentSentMessage extends TradeTask {
|
|||
trade.setCounterCurrencyExtraData(counterCurrencyExtraData);
|
||||
}
|
||||
|
||||
trade.setState(Trade.State.SELLER_RECEIVED_PAYMENT_INITIATED_MSG);
|
||||
trade.setState(Trade.State.SELLER_RECEIVED_PAYMENT_SENT_MSG);
|
||||
|
||||
processModel.getTradeManager().requestPersistence();
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ public class SellerSendsPaymentReceivedMessage extends SendMailboxMessageTask {
|
|||
|
||||
@Override
|
||||
protected void setStateSent() {
|
||||
trade.setState(Trade.State.SELLER_SENT_PAYOUT_TX_PUBLISHED_MSG);
|
||||
trade.setState(trade.getState() == Trade.State.SELLER_PUBLISHED_PAYOUT_TX ? Trade.State.SELLER_SENT_PAYOUT_TX_PUBLISHED_MSG : Trade.State.SELLER_SENT_PAYMENT_RECEIVED_MSG);
|
||||
log.info("Sent SellerReceivedPaymentMessage: tradeId={} at peer {} SignedWitness {}",
|
||||
trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness);
|
||||
processModel.getTradeManager().requestPersistence();
|
||||
|
@ -85,7 +85,7 @@ public class SellerSendsPaymentReceivedMessage extends SendMailboxMessageTask {
|
|||
|
||||
@Override
|
||||
protected void setStateArrived() {
|
||||
trade.setState(Trade.State.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG);
|
||||
trade.setState(trade.getState() == Trade.State.SELLER_PUBLISHED_PAYOUT_TX ? Trade.State.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG : Trade.State.SELLER_SAW_ARRIVED_PAYMENT_RECEIVED_MSG);
|
||||
log.info("SellerReceivedPaymentMessage arrived: tradeId={} at peer {} SignedWitness {}",
|
||||
trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness);
|
||||
processModel.getTradeManager().requestPersistence();
|
||||
|
@ -93,7 +93,7 @@ public class SellerSendsPaymentReceivedMessage extends SendMailboxMessageTask {
|
|||
|
||||
@Override
|
||||
protected void setStateStoredInMailbox() {
|
||||
trade.setState(Trade.State.SELLER_STORED_IN_MAILBOX_PAYOUT_TX_PUBLISHED_MSG);
|
||||
trade.setState(trade.getState() == Trade.State.SELLER_PUBLISHED_PAYOUT_TX ? Trade.State.SELLER_STORED_IN_MAILBOX_PAYOUT_TX_PUBLISHED_MSG : Trade.State.SELLER_STORED_IN_MAILBOX_PAYMENT_RECEIVED_MSG);
|
||||
log.info("SellerReceivedPaymentMessage storedInMailbox: tradeId={} at peer {} SignedWitness {}",
|
||||
trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness);
|
||||
processModel.getTradeManager().requestPersistence();
|
||||
|
@ -101,7 +101,7 @@ public class SellerSendsPaymentReceivedMessage extends SendMailboxMessageTask {
|
|||
|
||||
@Override
|
||||
protected void setStateFault() {
|
||||
trade.setState(Trade.State.SELLER_SEND_FAILED_PAYOUT_TX_PUBLISHED_MSG);
|
||||
trade.setState(trade.getState() == Trade.State.SELLER_PUBLISHED_PAYOUT_TX ? Trade.State.SELLER_SEND_FAILED_PAYOUT_TX_PUBLISHED_MSG : Trade.State.SELLER_SEND_FAILED_PAYMENT_RECEIVED_MSG);
|
||||
log.error("SellerReceivedPaymentMessage failed: tradeId={} at peer {} SignedWitness {}",
|
||||
trade.getId(), trade.getTradingPeerNodeAddress(), signedWitness);
|
||||
processModel.getTradeManager().requestPersistence();
|
||||
|
|
|
@ -207,7 +207,7 @@ public class XmrTxProofService implements AssetTxProofService {
|
|||
if (isExpectedTradeState(trade.getState())) {
|
||||
startRequestsIfValid(trade);
|
||||
} else {
|
||||
// We are expecting SELLER_RECEIVED_PAYMENT_INITIATED_MSG in the future, so listen on changes
|
||||
// We are expecting SELLER_RECEIVED_PAYMENT_SENT_MSG in the future, so listen on changes
|
||||
ChangeListener<Trade.State> tradeStateListener = (observable, oldValue, newValue) -> {
|
||||
if (isExpectedTradeState(newValue)) {
|
||||
ChangeListener<Trade.State> listener = tradeStateListenerMap.remove(trade.getId());
|
||||
|
@ -346,7 +346,7 @@ public class XmrTxProofService implements AssetTxProofService {
|
|||
}
|
||||
|
||||
private boolean isExpectedTradeState(Trade.State newValue) {
|
||||
return newValue == Trade.State.SELLER_RECEIVED_PAYMENT_INITIATED_MSG;
|
||||
return newValue == Trade.State.SELLER_RECEIVED_PAYMENT_SENT_MSG;
|
||||
}
|
||||
|
||||
private boolean is32BitHexStringInValid(String hexString) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue