mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-05-15 13:02:20 -04:00
fix validation
This commit is contained in:
parent
2cd3a5bae4
commit
daecafa3c1
2 changed files with 12 additions and 19 deletions
|
@ -2,14 +2,14 @@ package io.bitsquare.trade.protocol.createoffer;
|
||||||
|
|
||||||
import com.google.bitcoin.core.Transaction;
|
import com.google.bitcoin.core.Transaction;
|
||||||
import io.bitsquare.btc.WalletFacade;
|
import io.bitsquare.btc.WalletFacade;
|
||||||
import io.bitsquare.trade.protocol.createoffer.tasks.BroadCastOfferFeeTx;
|
|
||||||
import io.bitsquare.trade.protocol.createoffer.tasks.CreateOfferFeeTx;
|
|
||||||
import io.bitsquare.msg.MessageFacade;
|
import io.bitsquare.msg.MessageFacade;
|
||||||
import io.bitsquare.trade.protocol.createoffer.tasks.PublishOfferToDHT;
|
|
||||||
import io.bitsquare.storage.Persistence;
|
import io.bitsquare.storage.Persistence;
|
||||||
import io.bitsquare.trade.Offer;
|
import io.bitsquare.trade.Offer;
|
||||||
import io.bitsquare.trade.handlers.FaultHandler;
|
import io.bitsquare.trade.handlers.FaultHandler;
|
||||||
import io.bitsquare.trade.handlers.TransactionResultHandler;
|
import io.bitsquare.trade.handlers.TransactionResultHandler;
|
||||||
|
import io.bitsquare.trade.protocol.createoffer.tasks.BroadCastOfferFeeTx;
|
||||||
|
import io.bitsquare.trade.protocol.createoffer.tasks.CreateOfferFeeTx;
|
||||||
|
import io.bitsquare.trade.protocol.createoffer.tasks.PublishOfferToDHT;
|
||||||
import io.bitsquare.trade.protocol.createoffer.tasks.ValidateOffer;
|
import io.bitsquare.trade.protocol.createoffer.tasks.ValidateOffer;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
@ -44,7 +44,7 @@ public class CreateOfferCoordinator
|
||||||
|
|
||||||
private final Persistence persistence;
|
private final Persistence persistence;
|
||||||
private State state;
|
private State state;
|
||||||
//TODO use tx id and make Transaction transient
|
//TODO use tx id
|
||||||
Transaction transaction;
|
Transaction transaction;
|
||||||
|
|
||||||
Model(Persistence persistence)
|
Model(Persistence persistence)
|
||||||
|
@ -62,7 +62,7 @@ public class CreateOfferCoordinator
|
||||||
this.state = state;
|
this.state = state;
|
||||||
|
|
||||||
//TODO will have performance issues, but could be handled inside the persistence solution (queue up save requests and exec. them on dedicated thread)
|
//TODO will have performance issues, but could be handled inside the persistence solution (queue up save requests and exec. them on dedicated thread)
|
||||||
persistence.write(this);
|
persistence.write(this, "state", state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,17 +115,12 @@ public class CreateOfferCoordinator
|
||||||
private void onOfferFeeTxBroadCasted()
|
private void onOfferFeeTxBroadCasted()
|
||||||
{
|
{
|
||||||
model.setState(State.OFFER_FEE_BROAD_CASTED);
|
model.setState(State.OFFER_FEE_BROAD_CASTED);
|
||||||
|
|
||||||
PublishOfferToDHT.run(this::onOfferPublishedToDHT, this::onFailed, messageFacade, offer);
|
PublishOfferToDHT.run(this::onOfferPublishedToDHT, this::onFailed, messageFacade, offer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onOfferPublishedToDHT()
|
private void onOfferPublishedToDHT()
|
||||||
{
|
{
|
||||||
model.setState(State.OFFER_PUBLISHED_TO_DHT);
|
model.setState(State.OFFER_PUBLISHED_TO_DHT);
|
||||||
// TODO
|
|
||||||
//orderBookListeners.stream().forEach(listener -> listener.onOfferAdded(data, future.isSuccess()));
|
|
||||||
|
|
||||||
|
|
||||||
resultHandler.onResult(model.transaction);
|
resultHandler.onResult(model.transaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,23 +141,22 @@ public class CreateOfferCoordinator
|
||||||
{
|
{
|
||||||
case INITED:
|
case INITED:
|
||||||
case STARTED:
|
case STARTED:
|
||||||
// no need for recover, just call start
|
|
||||||
break;
|
|
||||||
case VALIDATED:
|
case VALIDATED:
|
||||||
onOfferValidated();
|
|
||||||
break;
|
|
||||||
case OFFER_FEE_TX_CREATED:
|
case OFFER_FEE_TX_CREATED:
|
||||||
onOfferFeeTxCreated(model.transaction);
|
// we start over again, no critical and expensive work done yet
|
||||||
|
start();
|
||||||
break;
|
break;
|
||||||
case OFFER_FEE_BROAD_CASTED:
|
case OFFER_FEE_BROAD_CASTED:
|
||||||
onOfferFeeTxBroadCasted();
|
// actually the only replay case here, tx publish was successful but storage to dht failed.
|
||||||
|
// Republish the offer to DHT
|
||||||
|
PublishOfferToDHT.run(this::onOfferPublishedToDHT, this::onFailed, messageFacade, offer);
|
||||||
break;
|
break;
|
||||||
case OFFER_PUBLISHED_TO_DHT:
|
case OFFER_PUBLISHED_TO_DHT:
|
||||||
// should be impossible
|
// should be impossible
|
||||||
onOfferPublishedToDHT();
|
log.warn("That case must not happen.");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log.error("Must not happen");
|
log.error("Illegal state passes. That must not happen");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ public class ValidateOffer
|
||||||
checkNotNull(offer.getId());
|
checkNotNull(offer.getId());
|
||||||
checkNotNull(offer.getMessagePublicKey());
|
checkNotNull(offer.getMessagePublicKey());
|
||||||
checkNotNull(offer.getMinAmount());
|
checkNotNull(offer.getMinAmount());
|
||||||
checkNotNull(offer.getOfferFeePaymentTxID());
|
|
||||||
checkNotNull(offer.getPrice());
|
checkNotNull(offer.getPrice());
|
||||||
|
|
||||||
checkArgument(offer.getAcceptedCountries().size() > 0);
|
checkArgument(offer.getAcceptedCountries().size() > 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue