seller publishes trade statistic on deposit response

This commit is contained in:
woodser 2023-05-15 12:03:10 -04:00
parent a2c2f670da
commit 66d3a23ec2
4 changed files with 51 additions and 39 deletions

View File

@ -145,7 +145,7 @@ arbitrator-desktop-local:
--apiPassword=apitest \ --apiPassword=apitest \
--apiPort=9998 --apiPort=9998
arbitrator-desktop2-local: arbitrator2-desktop-local:
# Arbitrator needs to be registered before making trades # Arbitrator needs to be registered before making trades
./haveno-desktop$(APP_EXT) \ ./haveno-desktop$(APP_EXT) \
--baseCurrencyNetwork=XMR_LOCAL \ --baseCurrencyNetwork=XMR_LOCAL \

View File

@ -1071,7 +1071,8 @@ public abstract class Trade implements Tradable, Model {
if (depositId == null) return null; if (depositId == null) return null;
try { try {
if (trader.getDepositTx() == null || !trader.getDepositTx().isConfirmed()) { if (trader.getDepositTx() == null || !trader.getDepositTx().isConfirmed()) {
trader.setDepositTx(getDepositTxFromWalletOrDaemon(depositId)); MoneroTx depositTx = getDepositTxFromWalletOrDaemon(depositId);
if (depositTx != null) trader.setDepositTx(depositTx);
} }
return trader.getDepositTx(); return trader.getDepositTx();
} catch (MoneroError e) { } catch (MoneroError e) {
@ -1801,8 +1802,8 @@ public abstract class Trade implements Tradable, Model {
if (tx.getHash().equals(processModel.getMaker().getDepositTxHash())) makerDepositTx = tx; if (tx.getHash().equals(processModel.getMaker().getDepositTxHash())) makerDepositTx = tx;
if (tx.getHash().equals(processModel.getTaker().getDepositTxHash())) takerDepositTx = tx; if (tx.getHash().equals(processModel.getTaker().getDepositTxHash())) takerDepositTx = tx;
} }
getMaker().setDepositTx(makerDepositTx); if (makerDepositTx != null) getMaker().setDepositTx(makerDepositTx);
getTaker().setDepositTx(takerDepositTx); if (takerDepositTx != null) getTaker().setDepositTx(takerDepositTx);
// skip if deposit txs not seen // skip if deposit txs not seen
if (makerDepositTx == null || takerDepositTx == null) return; if (makerDepositTx == null || takerDepositTx == null) return;

View File

@ -52,6 +52,7 @@ import haveno.core.trade.protocol.tasks.ProcessPaymentSentMessage;
import haveno.core.trade.protocol.tasks.ProcessSignContractRequest; import haveno.core.trade.protocol.tasks.ProcessSignContractRequest;
import haveno.core.trade.protocol.tasks.ProcessSignContractResponse; import haveno.core.trade.protocol.tasks.ProcessSignContractResponse;
import haveno.core.trade.protocol.tasks.RemoveOffer; import haveno.core.trade.protocol.tasks.RemoveOffer;
import haveno.core.trade.protocol.tasks.SellerPublishTradeStatistics;
import haveno.core.trade.protocol.tasks.MaybeResendDisputeClosedMessageWithPayout; import haveno.core.trade.protocol.tasks.MaybeResendDisputeClosedMessageWithPayout;
import haveno.core.trade.protocol.tasks.TradeTask; import haveno.core.trade.protocol.tasks.TradeTask;
import haveno.core.trade.protocol.tasks.VerifyPeersAccountAgeWitness; import haveno.core.trade.protocol.tasks.VerifyPeersAccountAgeWitness;
@ -418,11 +419,11 @@ public abstract class TradeProtocol implements DecryptedDirectMessageListener, D
processModel.setTradeMessage(response); processModel.setTradeMessage(response);
expect(anyState(Trade.State.SENT_PUBLISH_DEPOSIT_TX_REQUEST, Trade.State.SAW_ARRIVED_PUBLISH_DEPOSIT_TX_REQUEST, Trade.State.ARBITRATOR_PUBLISHED_DEPOSIT_TXS, Trade.State.DEPOSIT_TXS_SEEN_IN_NETWORK) expect(anyState(Trade.State.SENT_PUBLISH_DEPOSIT_TX_REQUEST, Trade.State.SAW_ARRIVED_PUBLISH_DEPOSIT_TX_REQUEST, Trade.State.ARBITRATOR_PUBLISHED_DEPOSIT_TXS, Trade.State.DEPOSIT_TXS_SEEN_IN_NETWORK)
.with(response) .with(response)
.from(sender)) // TODO (woodser): ensure this asserts sender == response.getSenderNodeAddress() .from(sender))
.setup(tasks( .setup(tasks(
// TODO (woodser): validate request
ProcessDepositResponse.class, ProcessDepositResponse.class,
RemoveOffer.class) RemoveOffer.class,
SellerPublishTradeStatistics.class)
.using(new TradeTaskRunner(trade, .using(new TradeTaskRunner(trade,
() -> { () -> {
stopTimeout(); stopTimeout();

View File

@ -17,10 +17,16 @@
package haveno.core.trade.protocol.tasks; package haveno.core.trade.protocol.tasks;
import haveno.common.app.Capability;
import haveno.common.taskrunner.TaskRunner; import haveno.common.taskrunner.TaskRunner;
import haveno.core.trade.SellerTrade;
import haveno.core.trade.Trade; import haveno.core.trade.Trade;
import haveno.core.trade.statistics.TradeStatistics3;
import haveno.network.p2p.network.TorNetworkNode;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import static com.google.common.base.Preconditions.checkNotNull;
@Slf4j @Slf4j
public class SellerPublishTradeStatistics extends TradeTask { public class SellerPublishTradeStatistics extends TradeTask {
public SellerPublishTradeStatistics(TaskRunner<Trade> taskHandler, Trade trade) { public SellerPublishTradeStatistics(TaskRunner<Trade> taskHandler, Trade trade) {
@ -29,37 +35,41 @@ public class SellerPublishTradeStatistics extends TradeTask {
@Override @Override
protected void run() { protected void run() {
throw new RuntimeException("SellerPublishesTradeStatistics needs updated for XMR"); try {
// try { runInterceptHook();
// runInterceptHook();
// // skip if not seller
// checkNotNull(trade.getDepositTx()); if (!(trade instanceof SellerTrade)) {
// complete();
// processModel.getP2PService().findPeersCapabilities(trade.getTradePeer().getNodeAddress()) return;
// .filter(capabilities -> capabilities.containsAll(Capability.TRADE_STATISTICS_3)) }
// .ifPresentOrElse(capabilities -> {
// // Our peer has updated, so as we are the seller we will publish the trade statistics. checkNotNull(trade.getSeller().getDepositTx());
// // The peer as buyer does not publish anymore with v.1.4.0 (where Capability.TRADE_STATISTICS_3 was added) processModel.getP2PService().findPeersCapabilities(trade.getTradePeer().getNodeAddress())
// .filter(capabilities -> capabilities.containsAll(Capability.TRADE_STATISTICS_3))
// String referralId = processModel.getReferralIdService().getOptionalReferralId().orElse(null); .ifPresentOrElse(capabilities -> {
// boolean isTorNetworkNode = model.getProcessModel().getP2PService().getNetworkNode() instanceof TorNetworkNode; // Our peer has updated, so as we are the seller we will publish the trade statistics.
// TradeStatistics3 tradeStatistics = TradeStatistics3.from(trade, referralId, isTorNetworkNode); // The peer as buyer does not publish anymore with v.1.4.0 (where Capability.TRADE_STATISTICS_3 was added)
// if (tradeStatistics.isValid()) {
// log.info("Publishing trade statistics"); String referralId = processModel.getReferralIdService().getOptionalReferralId().orElse(null);
// processModel.getP2PService().addPersistableNetworkPayload(tradeStatistics, true); boolean isTorNetworkNode = model.getProcessModel().getP2PService().getNetworkNode() instanceof TorNetworkNode;
// } else { TradeStatistics3 tradeStatistics = TradeStatistics3.from(trade, referralId, isTorNetworkNode);
// log.warn("Trade statistics are invalid. We do not publish. {}", tradeStatistics); if (tradeStatistics.isValid()) {
// } log.info("Publishing trade statistics");
// processModel.getP2PService().addPersistableNetworkPayload(tradeStatistics, true);
// complete(); } else {
// }, log.warn("Trade statistics are invalid. We do not publish. {}", tradeStatistics);
// () -> { }
// log.info("Our peer does not has updated yet, so they will publish the trade statistics. " +
// "To avoid duplicates we do not publish from our side."); complete();
// complete(); },
// }); () -> {
// } catch (Throwable t) { log.info("Our peer does not has updated yet, so they will publish the trade statistics. " +
// failed(t); "To avoid duplicates we do not publish from our side.");
// } complete();
});
} catch (Throwable t) {
failed(t);
}
} }
} }