mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-20 21:04:28 -04:00
Refactor trade object
This commit is contained in:
parent
0ddd025b93
commit
a9f6d8481b
9 changed files with 109 additions and 89 deletions
|
@ -195,12 +195,12 @@ public class TomP2POfferBookService extends TomP2PDHTService implements OfferBoo
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.trace("Get offers with offers.size(): " + offers.size());
|
||||||
executor.execute(() -> offerRepositoryListeners.stream().forEach(listener ->
|
executor.execute(() -> offerRepositoryListeners.stream().forEach(listener ->
|
||||||
listener.onOffersReceived(offers)));
|
listener.onOffersReceived(offers)));
|
||||||
}
|
}
|
||||||
|
|
||||||
log.trace("Get offers from DHT was successful. Stored data: [key: " + locationKey
|
log.trace("Get offers from DHT was successful. Received data: [key: " + locationKey
|
||||||
+ ", values: " + futureGet.dataMap() + "]");
|
+ ", values: " + futureGet.dataMap() + "]");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -18,9 +18,12 @@
|
||||||
package io.bitsquare.trade;
|
package io.bitsquare.trade;
|
||||||
|
|
||||||
import io.bitsquare.offer.Offer;
|
import io.bitsquare.offer.Offer;
|
||||||
|
import io.bitsquare.p2p.Peer;
|
||||||
import io.bitsquare.trade.protocol.trade.offerer.OffererAsBuyerProtocol;
|
import io.bitsquare.trade.protocol.trade.offerer.OffererAsBuyerProtocol;
|
||||||
|
|
||||||
|
import org.bitcoinj.core.Coin;
|
||||||
import org.bitcoinj.core.TransactionConfidence;
|
import org.bitcoinj.core.TransactionConfidence;
|
||||||
|
import org.bitcoinj.utils.Fiat;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.util.concurrent.FutureCallback;
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
|
@ -42,6 +45,7 @@ public class OffererTrade extends Trade implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
transient private static final Logger log = LoggerFactory.getLogger(OffererTrade.class);
|
transient private static final Logger log = LoggerFactory.getLogger(OffererTrade.class);
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Enum
|
// Enum
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -66,11 +70,14 @@ public class OffererTrade extends Trade implements Serializable {
|
||||||
EXCEPTION
|
EXCEPTION
|
||||||
}
|
}
|
||||||
|
|
||||||
protected OffererProcessState processState;
|
|
||||||
protected OffererLifeCycleState lifeCycleState;
|
|
||||||
|
|
||||||
transient protected ObjectProperty<OffererProcessState> processStateProperty = new SimpleObjectProperty<>(processState);
|
private Coin tradeAmount;
|
||||||
transient protected ObjectProperty<OffererLifeCycleState> lifeCycleStateProperty = new SimpleObjectProperty<>(lifeCycleState);
|
private Peer tradingPeer;
|
||||||
|
private OffererProcessState processState;
|
||||||
|
private OffererLifeCycleState lifeCycleState;
|
||||||
|
|
||||||
|
transient private ObjectProperty<OffererProcessState> processStateProperty = new SimpleObjectProperty<>(processState);
|
||||||
|
transient private ObjectProperty<OffererLifeCycleState> lifeCycleStateProperty = new SimpleObjectProperty<>(lifeCycleState);
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -89,6 +96,7 @@ public class OffererTrade extends Trade implements Serializable {
|
||||||
lifeCycleStateProperty = new SimpleObjectProperty<>(lifeCycleState);
|
lifeCycleStateProperty = new SimpleObjectProperty<>(lifeCycleState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void onFiatPaymentStarted() {
|
public void onFiatPaymentStarted() {
|
||||||
((OffererAsBuyerProtocol) protocol).onFiatPaymentStarted();
|
((OffererAsBuyerProtocol) protocol).onFiatPaymentStarted();
|
||||||
}
|
}
|
||||||
|
@ -123,28 +131,46 @@ public class OffererTrade extends Trade implements Serializable {
|
||||||
lifeCycleStateProperty.set(lifeCycleState);
|
lifeCycleStateProperty.set(lifeCycleState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTradeAmount(Coin tradeAmount) {
|
||||||
|
this.tradeAmount = tradeAmount;
|
||||||
|
tradeAmountProperty.set(tradeAmount);
|
||||||
|
tradeVolumeProperty.set(getTradeVolume());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTradingPeer(Peer tradingPeer) {
|
||||||
|
this.tradingPeer = tradingPeer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Getters
|
// Getters
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
public OffererProcessState getProcessState() {
|
@Override
|
||||||
return processState;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OffererLifeCycleState getLifeCycleState() {
|
|
||||||
return lifeCycleState;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReadOnlyObjectProperty<OffererProcessState> processStateProperty() {
|
public ReadOnlyObjectProperty<OffererProcessState> processStateProperty() {
|
||||||
return processStateProperty;
|
return processStateProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ReadOnlyObjectProperty<OffererLifeCycleState> lifeCycleStateProperty() {
|
public ReadOnlyObjectProperty<OffererLifeCycleState> lifeCycleStateProperty() {
|
||||||
return lifeCycleStateProperty;
|
return lifeCycleStateProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Coin getTradeAmount() {
|
||||||
|
return tradeAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fiat getTradeVolume() {
|
||||||
|
return offer.getVolumeByAmount(tradeAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Peer getTradingPeer() {
|
||||||
|
return tradingPeer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Private
|
// Private
|
||||||
|
|
|
@ -18,9 +18,12 @@
|
||||||
package io.bitsquare.trade;
|
package io.bitsquare.trade;
|
||||||
|
|
||||||
import io.bitsquare.offer.Offer;
|
import io.bitsquare.offer.Offer;
|
||||||
|
import io.bitsquare.p2p.Peer;
|
||||||
import io.bitsquare.trade.protocol.trade.taker.TakerAsSellerProtocol;
|
import io.bitsquare.trade.protocol.trade.taker.TakerAsSellerProtocol;
|
||||||
|
|
||||||
|
import org.bitcoinj.core.Coin;
|
||||||
import org.bitcoinj.core.TransactionConfidence;
|
import org.bitcoinj.core.TransactionConfidence;
|
||||||
|
import org.bitcoinj.utils.Fiat;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.util.concurrent.FutureCallback;
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
|
@ -42,7 +45,6 @@ public class TakerTrade extends Trade implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
transient private static final Logger log = LoggerFactory.getLogger(TakerTrade.class);
|
transient private static final Logger log = LoggerFactory.getLogger(TakerTrade.class);
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Enum
|
// Enum
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -70,19 +72,28 @@ public class TakerTrade extends Trade implements Serializable {
|
||||||
EXCEPTION
|
EXCEPTION
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TakerProcessState processState;
|
|
||||||
protected TakerLifeCycleState lifeCycleState;
|
|
||||||
|
|
||||||
transient protected ObjectProperty<TakerProcessState> processStateProperty = new SimpleObjectProperty<>(processState);
|
private final Coin tradeAmount;
|
||||||
transient protected ObjectProperty<TakerLifeCycleState> lifeCycleStateProperty = new SimpleObjectProperty<>(lifeCycleState);
|
private final Peer tradingPeer;
|
||||||
|
|
||||||
|
private TakerProcessState processState;
|
||||||
|
private TakerLifeCycleState lifeCycleState;
|
||||||
|
|
||||||
|
transient private ObjectProperty<TakerProcessState> processStateProperty = new SimpleObjectProperty<>(processState);
|
||||||
|
transient private ObjectProperty<TakerLifeCycleState> lifeCycleStateProperty = new SimpleObjectProperty<>(lifeCycleState);
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
public TakerTrade(Offer offer) {
|
public TakerTrade(Offer offer, Coin tradeAmount, Peer peer) {
|
||||||
super(offer);
|
super(offer);
|
||||||
|
this.tradeAmount = tradeAmount;
|
||||||
|
this.tradingPeer = peer;
|
||||||
|
|
||||||
|
tradeAmountProperty = new SimpleObjectProperty<>(tradeAmount);
|
||||||
|
tradeVolumeProperty = new SimpleObjectProperty<>(getTradeVolume()); // cannot be set before offer is set
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serialized object does not create our transient objects
|
// Serialized object does not create our transient objects
|
||||||
|
@ -91,6 +102,8 @@ public class TakerTrade extends Trade implements Serializable {
|
||||||
|
|
||||||
processStateProperty = new SimpleObjectProperty<>(processState);
|
processStateProperty = new SimpleObjectProperty<>(processState);
|
||||||
lifeCycleStateProperty = new SimpleObjectProperty<>(lifeCycleState);
|
lifeCycleStateProperty = new SimpleObjectProperty<>(lifeCycleState);
|
||||||
|
tradeAmountProperty = new SimpleObjectProperty<>(tradeAmount);
|
||||||
|
tradeVolumeProperty = new SimpleObjectProperty<>(getTradeVolume());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onFiatPaymentReceived() {
|
public void onFiatPaymentReceived() {
|
||||||
|
@ -128,14 +141,30 @@ public class TakerTrade extends Trade implements Serializable {
|
||||||
// Getters
|
// Getters
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@Override
|
||||||
public ReadOnlyObjectProperty<TakerProcessState> processStateProperty() {
|
public ReadOnlyObjectProperty<TakerProcessState> processStateProperty() {
|
||||||
return processStateProperty;
|
return processStateProperty;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public ReadOnlyObjectProperty<TakerLifeCycleState> lifeCycleStateProperty() {
|
public ReadOnlyObjectProperty<TakerLifeCycleState> lifeCycleStateProperty() {
|
||||||
return lifeCycleStateProperty;
|
return lifeCycleStateProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Coin getTradeAmount() {
|
||||||
|
return tradeAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fiat getTradeVolume() {
|
||||||
|
return offer.getVolumeByAmount(tradeAmount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Peer getTradingPeer() {
|
||||||
|
return tradingPeer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Private
|
// Private
|
||||||
|
|
|
@ -27,7 +27,6 @@ import org.bitcoinj.core.Coin;
|
||||||
import org.bitcoinj.core.Transaction;
|
import org.bitcoinj.core.Transaction;
|
||||||
import org.bitcoinj.utils.Fiat;
|
import org.bitcoinj.utils.Fiat;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -57,20 +56,18 @@ abstract public class Trade implements Serializable {
|
||||||
protected final Offer offer;
|
protected final Offer offer;
|
||||||
protected final Date date;
|
protected final Date date;
|
||||||
|
|
||||||
protected Coin tradeAmount;
|
|
||||||
protected Contract contract;
|
protected Contract contract;
|
||||||
protected String contractAsJson;
|
protected String contractAsJson;
|
||||||
protected String takerContractSignature;
|
protected String takerContractSignature;
|
||||||
protected String offererContractSignature;
|
protected String offererContractSignature;
|
||||||
protected Transaction depositTx;
|
protected Transaction depositTx;
|
||||||
protected Transaction payoutTx;
|
protected Transaction payoutTx;
|
||||||
protected Peer tradingPeer;
|
|
||||||
protected int depthInBlocks = 0;
|
protected int depthInBlocks = 0;
|
||||||
|
|
||||||
transient protected String errorMessage;
|
transient protected String errorMessage;
|
||||||
transient protected Throwable throwable;
|
transient protected Throwable throwable;
|
||||||
transient protected ObjectProperty<Coin> tradeAmountProperty;
|
transient protected ObjectProperty<Coin> tradeAmountProperty = new SimpleObjectProperty<>();
|
||||||
transient protected ObjectProperty<Fiat> tradeVolumeProperty;
|
transient protected ObjectProperty<Fiat> tradeVolumeProperty = new SimpleObjectProperty<>();
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -79,25 +76,14 @@ abstract public class Trade implements Serializable {
|
||||||
|
|
||||||
public Trade(Offer offer) {
|
public Trade(Offer offer) {
|
||||||
this.offer = offer;
|
this.offer = offer;
|
||||||
|
|
||||||
date = new Date();
|
date = new Date();
|
||||||
tradeAmountProperty = new SimpleObjectProperty<>(tradeAmount);
|
|
||||||
tradeVolumeProperty = new SimpleObjectProperty<>(getTradeVolume()); // cannot be set before offer is set
|
|
||||||
}
|
|
||||||
|
|
||||||
// Serialized object does not create our transient objects
|
|
||||||
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
|
|
||||||
in.defaultReadObject();
|
|
||||||
|
|
||||||
tradeAmountProperty = new SimpleObjectProperty<>(tradeAmount);
|
|
||||||
tradeVolumeProperty = new SimpleObjectProperty<>(getTradeVolume());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The deserialized tx has not actual confidence data, so we need to get the fresh one from the wallet.
|
// The deserialized tx has not actual confidence data, so we need to get the fresh one from the wallet.
|
||||||
public void updateTxFromWallet(TradeWalletService tradeWalletService) {
|
public void updateTxFromWallet(TradeWalletService tradeWalletService) {
|
||||||
if (depositTx != null) {
|
if (depositTx != null)
|
||||||
depositTx = tradeWalletService.commitsDepositTx(depositTx);
|
setDepositTx(tradeWalletService.commitsDepositTx(depositTx));
|
||||||
setConfidenceListener();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDepositTx(Transaction tx) {
|
public void setDepositTx(Transaction tx) {
|
||||||
|
@ -134,18 +120,6 @@ abstract public class Trade implements Serializable {
|
||||||
// Setters
|
// Setters
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
public void setTradeAmount(Coin tradeAmount) {
|
|
||||||
this.tradeAmount = tradeAmount;
|
|
||||||
tradeAmountProperty.set(tradeAmount);
|
|
||||||
tradeVolumeProperty.set(getTradeVolume());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setTradingPeer(Peer tradingPeer) {
|
|
||||||
this.tradingPeer = tradingPeer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTakerContractSignature(String takerSignature) {
|
public void setTakerContractSignature(String takerSignature) {
|
||||||
this.takerContractSignature = takerSignature;
|
this.takerContractSignature = takerSignature;
|
||||||
}
|
}
|
||||||
|
@ -154,10 +128,6 @@ abstract public class Trade implements Serializable {
|
||||||
this.offererContractSignature = offererContractSignature;
|
this.offererContractSignature = offererContractSignature;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Coin getTradeAmount() {
|
|
||||||
return tradeAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Contract getContract() {
|
public Contract getContract() {
|
||||||
return contract;
|
return contract;
|
||||||
}
|
}
|
||||||
|
@ -187,10 +157,6 @@ abstract public class Trade implements Serializable {
|
||||||
// Getters
|
// Getters
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
public Fiat getTradeVolume() {
|
|
||||||
return offer.getVolumeByAmount(tradeAmount);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTakerContractSignature() {
|
public String getTakerContractSignature() {
|
||||||
return takerContractSignature;
|
return takerContractSignature;
|
||||||
}
|
}
|
||||||
|
@ -227,10 +193,6 @@ abstract public class Trade implements Serializable {
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Peer getTradingPeer() {
|
|
||||||
return tradingPeer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReadOnlyObjectProperty<Coin> tradeAmountProperty() {
|
public ReadOnlyObjectProperty<Coin> tradeAmountProperty() {
|
||||||
return tradeAmountProperty;
|
return tradeAmountProperty;
|
||||||
}
|
}
|
||||||
|
@ -251,6 +213,12 @@ abstract public class Trade implements Serializable {
|
||||||
|
|
||||||
public abstract ReadOnlyObjectProperty<? extends LifeCycleState> lifeCycleStateProperty();
|
public abstract ReadOnlyObjectProperty<? extends LifeCycleState> lifeCycleStateProperty();
|
||||||
|
|
||||||
|
public abstract Coin getTradeAmount();
|
||||||
|
|
||||||
|
public abstract Fiat getTradeVolume();
|
||||||
|
|
||||||
|
public abstract Peer getTradingPeer();
|
||||||
|
|
||||||
protected abstract void setConfidenceListener();
|
protected abstract void setConfidenceListener();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -260,14 +228,12 @@ abstract public class Trade implements Serializable {
|
||||||
", mailboxMessage=" + mailboxMessage +
|
", mailboxMessage=" + mailboxMessage +
|
||||||
", offer=" + offer +
|
", offer=" + offer +
|
||||||
", date=" + date +
|
", date=" + date +
|
||||||
", tradeAmount=" + tradeAmount +
|
|
||||||
", contract=" + contract +
|
", contract=" + contract +
|
||||||
", contractAsJson='" + contractAsJson + '\'' +
|
", contractAsJson='" + contractAsJson + '\'' +
|
||||||
", takerContractSignature='" + takerContractSignature + '\'' +
|
", takerContractSignature='" + takerContractSignature + '\'' +
|
||||||
", offererContractSignature='" + offererContractSignature + '\'' +
|
", offererContractSignature='" + offererContractSignature + '\'' +
|
||||||
", depositTx=" + depositTx +
|
", depositTx=" + depositTx +
|
||||||
", payoutTx=" + payoutTx +
|
", payoutTx=" + payoutTx +
|
||||||
", tradingPeer=" + tradingPeer +
|
|
||||||
", depthInBlocks=" + depthInBlocks +
|
", depthInBlocks=" + depthInBlocks +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,6 +179,7 @@ public class TradeManager {
|
||||||
TakerTrade takerTrade = (TakerTrade) trade;
|
TakerTrade takerTrade = (TakerTrade) trade;
|
||||||
TakerAsSellerProtocol sellerTakesOfferProtocol = createTakerAsSellerProtocol(takerTrade);
|
TakerAsSellerProtocol sellerTakesOfferProtocol = createTakerAsSellerProtocol(takerTrade);
|
||||||
takerTrade.setProtocol(sellerTakesOfferProtocol);
|
takerTrade.setProtocol(sellerTakesOfferProtocol);
|
||||||
|
takerTrade.updateTxFromWallet(tradeWalletService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,7 +306,7 @@ public class TradeManager {
|
||||||
// TODO handle overpaid securityDeposit
|
// TODO handle overpaid securityDeposit
|
||||||
Coin amountToWithdraw = trade.getSecurityDeposit();
|
Coin amountToWithdraw = trade.getSecurityDeposit();
|
||||||
if (trade instanceof OffererTrade)
|
if (trade instanceof OffererTrade)
|
||||||
amountToWithdraw = amountToWithdraw.add(trade.getTradeAmount());
|
amountToWithdraw = amountToWithdraw.add(((OffererTrade) trade).getTradeAmount());
|
||||||
|
|
||||||
FutureCallback<Transaction> callback = new FutureCallback<Transaction>() {
|
FutureCallback<Transaction> callback = new FutureCallback<Transaction>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -411,9 +412,7 @@ public class TradeManager {
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
private TakerTrade takeAvailableOffer(Coin amount, Offer offer, Peer peer) {
|
private TakerTrade takeAvailableOffer(Coin amount, Offer offer, Peer peer) {
|
||||||
TakerTrade takerTrade = new TakerTrade(offer);
|
TakerTrade takerTrade = new TakerTrade(offer, amount, peer);
|
||||||
takerTrade.setTradeAmount(amount);
|
|
||||||
takerTrade.setTradingPeer(peer);
|
|
||||||
takerTrade.setLifeCycleState(TakerTrade.TakerLifeCycleState.PENDING);
|
takerTrade.setLifeCycleState(TakerTrade.TakerLifeCycleState.PENDING);
|
||||||
pendingTrades.add(takerTrade);
|
pendingTrades.add(takerTrade);
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class OffererAsBuyerProtocol implements Protocol {
|
||||||
|
|
||||||
// We don't store anything in the model as we might be in a trade process and receive that request from another peer who wants to take the offer
|
// We don't store anything in the model as we might be in a trade process and receive that request from another peer who wants to take the offer
|
||||||
// at the same time
|
// at the same time
|
||||||
boolean isOfferOpen = model.trade.getLifeCycleState() == OffererTrade.OffererLifeCycleState.OPEN_OFFER;
|
boolean isOfferOpen = model.trade.lifeCycleStateProperty().get() == OffererTrade.OffererLifeCycleState.OPEN_OFFER;
|
||||||
ReportOfferAvailabilityMessage reportOfferAvailabilityMessage = new ReportOfferAvailabilityMessage(model.id, isOfferOpen);
|
ReportOfferAvailabilityMessage reportOfferAvailabilityMessage = new ReportOfferAvailabilityMessage(model.id, isOfferOpen);
|
||||||
model.messageService.sendMessage(sender, reportOfferAvailabilityMessage, new SendMessageListener() {
|
model.messageService.sendMessage(sender, reportOfferAvailabilityMessage, new SendMessageListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,7 +19,7 @@ package io.bitsquare.trade.protocol.trade.offerer.tasks;
|
||||||
|
|
||||||
import io.bitsquare.common.taskrunner.Task;
|
import io.bitsquare.common.taskrunner.Task;
|
||||||
import io.bitsquare.common.taskrunner.TaskRunner;
|
import io.bitsquare.common.taskrunner.TaskRunner;
|
||||||
import io.bitsquare.trade.Trade;
|
import io.bitsquare.trade.OffererTrade;
|
||||||
import io.bitsquare.trade.protocol.trade.offerer.models.OffererAsBuyerModel;
|
import io.bitsquare.trade.protocol.trade.offerer.models.OffererAsBuyerModel;
|
||||||
|
|
||||||
import org.bitcoinj.core.Coin;
|
import org.bitcoinj.core.Coin;
|
||||||
|
@ -37,13 +37,13 @@ public class CreateAndSignPayoutTx extends Task<OffererAsBuyerModel> {
|
||||||
@Override
|
@Override
|
||||||
protected void doRun() {
|
protected void doRun() {
|
||||||
try {
|
try {
|
||||||
Trade trade = model.trade;
|
OffererTrade offererTrade = model.trade;
|
||||||
Coin securityDeposit = trade.getSecurityDeposit();
|
Coin securityDeposit = offererTrade.getSecurityDeposit();
|
||||||
Coin offererPayoutAmount = trade.getTradeAmount().add(securityDeposit);
|
Coin offererPayoutAmount = offererTrade.getTradeAmount().add(securityDeposit);
|
||||||
@SuppressWarnings("UnnecessaryLocalVariable") Coin takerPayoutAmount = securityDeposit;
|
@SuppressWarnings("UnnecessaryLocalVariable") Coin takerPayoutAmount = securityDeposit;
|
||||||
|
|
||||||
byte[] offererPayoutTxSignature = model.tradeWalletService.offererCreatesAndSignsPayoutTx(
|
byte[] offererPayoutTxSignature = model.tradeWalletService.offererCreatesAndSignsPayoutTx(
|
||||||
trade.getDepositTx(),
|
offererTrade.getDepositTx(),
|
||||||
offererPayoutAmount,
|
offererPayoutAmount,
|
||||||
takerPayoutAmount,
|
takerPayoutAmount,
|
||||||
model.offerer.addressEntry,
|
model.offerer.addressEntry,
|
||||||
|
|
|
@ -19,7 +19,7 @@ package io.bitsquare.trade.protocol.trade.offerer.tasks;
|
||||||
|
|
||||||
import io.bitsquare.common.taskrunner.Task;
|
import io.bitsquare.common.taskrunner.Task;
|
||||||
import io.bitsquare.common.taskrunner.TaskRunner;
|
import io.bitsquare.common.taskrunner.TaskRunner;
|
||||||
import io.bitsquare.trade.Trade;
|
import io.bitsquare.trade.OffererTrade;
|
||||||
import io.bitsquare.trade.protocol.trade.messages.RequestDepositTxInputsMessage;
|
import io.bitsquare.trade.protocol.trade.messages.RequestDepositTxInputsMessage;
|
||||||
import io.bitsquare.trade.protocol.trade.offerer.models.OffererAsBuyerModel;
|
import io.bitsquare.trade.protocol.trade.offerer.models.OffererAsBuyerModel;
|
||||||
|
|
||||||
|
@ -40,10 +40,10 @@ public class ProcessRequestDepositTxInputsMessage extends Task<OffererAsBuyerMod
|
||||||
protected void doRun() {
|
protected void doRun() {
|
||||||
try {
|
try {
|
||||||
checkTradeId(model.id, model.getTradeMessage());
|
checkTradeId(model.id, model.getTradeMessage());
|
||||||
Trade trade = model.trade;
|
OffererTrade offererTrade = model.trade;
|
||||||
RequestDepositTxInputsMessage requestDepositTxInputsMessage = (RequestDepositTxInputsMessage) model.getTradeMessage();
|
RequestDepositTxInputsMessage requestDepositTxInputsMessage = (RequestDepositTxInputsMessage) model.getTradeMessage();
|
||||||
|
|
||||||
trade.setTradeAmount(positiveCoinOf(nonZeroCoinOf(requestDepositTxInputsMessage.tradeAmount)));
|
offererTrade.setTradeAmount(positiveCoinOf(nonZeroCoinOf(requestDepositTxInputsMessage.tradeAmount)));
|
||||||
model.setTakeOfferFeeTxId(nonEmptyStringOf(requestDepositTxInputsMessage.takeOfferFeeTxId));
|
model.setTakeOfferFeeTxId(nonEmptyStringOf(requestDepositTxInputsMessage.takeOfferFeeTxId));
|
||||||
model.taker.tradeWalletPubKey = checkNotNull(requestDepositTxInputsMessage.takerTradeWalletPubKey);
|
model.taker.tradeWalletPubKey = checkNotNull(requestDepositTxInputsMessage.takerTradeWalletPubKey);
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ package io.bitsquare.trade.protocol.trade.offerer.tasks;
|
||||||
import io.bitsquare.common.taskrunner.Task;
|
import io.bitsquare.common.taskrunner.Task;
|
||||||
import io.bitsquare.common.taskrunner.TaskRunner;
|
import io.bitsquare.common.taskrunner.TaskRunner;
|
||||||
import io.bitsquare.trade.Contract;
|
import io.bitsquare.trade.Contract;
|
||||||
import io.bitsquare.trade.Trade;
|
import io.bitsquare.trade.OffererTrade;
|
||||||
import io.bitsquare.trade.protocol.trade.offerer.models.OffererAsBuyerModel;
|
import io.bitsquare.trade.protocol.trade.offerer.models.OffererAsBuyerModel;
|
||||||
import io.bitsquare.util.Utilities;
|
import io.bitsquare.util.Utilities;
|
||||||
|
|
||||||
|
@ -37,11 +37,11 @@ public class VerifyAndSignContract extends Task<OffererAsBuyerModel> {
|
||||||
@Override
|
@Override
|
||||||
protected void doRun() {
|
protected void doRun() {
|
||||||
try {
|
try {
|
||||||
Trade trade = model.trade;
|
OffererTrade offererTrade = model.trade;
|
||||||
|
|
||||||
Contract contract = new Contract(
|
Contract contract = new Contract(
|
||||||
model.offer,
|
model.offer,
|
||||||
trade.getTradeAmount(),
|
offererTrade.getTradeAmount(),
|
||||||
model.getTakeOfferFeeTxId(),
|
model.getTakeOfferFeeTxId(),
|
||||||
model.offerer.accountId,
|
model.offerer.accountId,
|
||||||
model.taker.accountId,
|
model.taker.accountId,
|
||||||
|
@ -52,10 +52,10 @@ public class VerifyAndSignContract extends Task<OffererAsBuyerModel> {
|
||||||
String contractAsJson = Utilities.objectToJson(contract);
|
String contractAsJson = Utilities.objectToJson(contract);
|
||||||
String signature = model.signatureService.signMessage(model.offerer.registrationKeyPair, contractAsJson);
|
String signature = model.signatureService.signMessage(model.offerer.registrationKeyPair, contractAsJson);
|
||||||
|
|
||||||
trade.setContract(contract);
|
offererTrade.setContract(contract);
|
||||||
trade.setContractAsJson(contractAsJson);
|
offererTrade.setContractAsJson(contractAsJson);
|
||||||
trade.setOffererContractSignature(signature);
|
offererTrade.setOffererContractSignature(signature);
|
||||||
trade.setTakerContractSignature(model.taker.contractSignature);
|
offererTrade.setTakerContractSignature(model.taker.contractSignature);
|
||||||
|
|
||||||
complete();
|
complete();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue