Generalize models

This commit is contained in:
Manfred Karrer 2015-04-02 12:15:47 +02:00
parent 34192dd808
commit 33bd09e82c
39 changed files with 409 additions and 591 deletions

View File

@ -45,15 +45,15 @@ public class OffererCreatesAndSignPayoutTx extends OffererTradeTask {
offererTrade.getDepositTx(),
offererPayoutAmount,
takerPayoutAmount,
offererTradeProcessModel.offerer.getAddressEntry(),
offererTradeProcessModel.taker.getPayoutAddressString(),
offererTradeProcessModel.offerer.getTradeWalletPubKey(),
offererTradeProcessModel.taker.getTradeWalletPubKey(),
offererTradeProcessModel.getAddressEntry(),
offererTradeProcessModel.tradingPeer.getPayoutAddressString(),
offererTradeProcessModel.getTradeWalletPubKey(),
offererTradeProcessModel.tradingPeer.getTradeWalletPubKey(),
offererTradeProcessModel.getArbitratorPubKey());
offererTradeProcessModel.offerer.setPayoutTxSignature(offererPayoutTxSignature);
offererTradeProcessModel.offerer.setPayoutAmount(offererPayoutAmount);
offererTradeProcessModel.taker.setPayoutAmount(takerPayoutAmount);
offererTradeProcessModel.setPayoutTxSignature(offererPayoutTxSignature);
offererTradeProcessModel.setPayoutAmount(offererPayoutAmount);
offererTradeProcessModel.tradingPeer.setPayoutAmount(takerPayoutAmount);
complete();
} catch (Throwable t) {

View File

@ -43,10 +43,10 @@ public class OffererCreatesDepositTxInputs extends OffererTradeTask {
log.debug("offererTrade.id" + offererTrade.getId());
Coin inputAmount = offererTrade.getSecurityDeposit().add(FeePolicy.TX_FEE);
TradeWalletService.Result result = offererTradeProcessModel.getTradeWalletService().createDepositTxInputs(inputAmount,
offererTradeProcessModel.offerer.getAddressEntry());
offererTradeProcessModel.getAddressEntry());
offererTradeProcessModel.offerer.setConnectedOutputsForAllInputs(result.getConnectedOutputsForAllInputs());
offererTradeProcessModel.offerer.setOutputs(result.getOutputs());
offererTradeProcessModel.setConnectedOutputsForAllInputs(result.getConnectedOutputsForAllInputs());
offererTradeProcessModel.setOutputs(result.getOutputs());
complete();
} catch (Throwable t) {

View File

@ -46,7 +46,7 @@ public class OffererProcessRequestDepositTxInputsMessage extends OffererTradeTas
offererTrade.setTradeAmount(positiveCoinOf(nonZeroCoinOf(message.tradeAmount)));
offererTradeProcessModel.setTakeOfferFeeTxId(nonEmptyStringOf(message.takeOfferFeeTxId));
offererTradeProcessModel.taker.setTradeWalletPubKey(checkNotNull(message.takerTradeWalletPubKey));
offererTradeProcessModel.tradingPeer.setTradeWalletPubKey(checkNotNull(message.takerTradeWalletPubKey));
complete();
} catch (Throwable t) {

View File

@ -44,15 +44,15 @@ public class OffererProcessRequestPublishDepositTxMessage extends OffererTradeTa
checkTradeId(offererTradeProcessModel.getId(), message);
checkNotNull(message);
offererTradeProcessModel.taker.setFiatAccount(checkNotNull(message.takerFiatAccount));
offererTradeProcessModel.taker.setAccountId(nonEmptyStringOf(message.takerAccountId));
offererTradeProcessModel.taker.setP2pSigPubKey(checkNotNull(message.takerP2PSigPublicKey));
offererTradeProcessModel.taker.setP2pEncryptPubKey(checkNotNull(message.takerP2PEncryptPublicKey));
offererTradeProcessModel.taker.setContractAsJson(nonEmptyStringOf(message.takerContractAsJson));
offererTradeProcessModel.taker.setContractSignature(nonEmptyStringOf(message.takerContractSignature));
offererTradeProcessModel.taker.setPayoutAddressString(nonEmptyStringOf(message.takerPayoutAddressString));
offererTradeProcessModel.taker.setPreparedDepositTx(checkNotNull(message.takersPreparedDepositTx));
offererTradeProcessModel.taker.setConnectedOutputsForAllInputs(checkNotNull(message.takerConnectedOutputsForAllInputs));
offererTradeProcessModel.tradingPeer.setFiatAccount(checkNotNull(message.takerFiatAccount));
offererTradeProcessModel.tradingPeer.setAccountId(nonEmptyStringOf(message.takerAccountId));
offererTradeProcessModel.tradingPeer.setP2pSigPubKey(checkNotNull(message.takerP2PSigPublicKey));
offererTradeProcessModel.tradingPeer.setP2pEncryptPubKey(checkNotNull(message.takerP2PEncryptPublicKey));
offererTradeProcessModel.tradingPeer.setContractAsJson(nonEmptyStringOf(message.takerContractAsJson));
offererTradeProcessModel.tradingPeer.setContractSignature(nonEmptyStringOf(message.takerContractSignature));
offererTradeProcessModel.tradingPeer.setPayoutAddressString(nonEmptyStringOf(message.takerPayoutAddressString));
offererTradeProcessModel.tradingPeer.setPreparedDepositTx(checkNotNull(message.takersPreparedDepositTx));
offererTradeProcessModel.tradingPeer.setConnectedOutputsForAllInputs(checkNotNull(message.takerConnectedOutputsForAllInputs));
checkArgument(message.takerConnectedOutputsForAllInputs.size() > 0);
complete();

View File

@ -39,14 +39,14 @@ public class OffererSendsFiatTransferStartedMessage extends OffererTradeTask {
protected void doRun() {
try {
FiatTransferStartedMessage tradeMessage = new FiatTransferStartedMessage(offererTradeProcessModel.getId(),
offererTradeProcessModel.offerer.getPayoutTxSignature(),
offererTradeProcessModel.offerer.getPayoutAmount(),
offererTradeProcessModel.taker.getPayoutAmount(),
offererTradeProcessModel.offerer.getAddressEntry().getAddressString());
offererTradeProcessModel.getPayoutTxSignature(),
offererTradeProcessModel.getPayoutAmount(),
offererTradeProcessModel.tradingPeer.getPayoutAmount(),
offererTradeProcessModel.getAddressEntry().getAddressString());
offererTradeProcessModel.getMessageService().sendMessage(offererTrade.getTradingPeer(), tradeMessage,
offererTradeProcessModel.taker.getP2pSigPubKey(),
offererTradeProcessModel.taker.getP2pEncryptPubKey(),
offererTradeProcessModel.tradingPeer.getP2pSigPubKey(),
offererTradeProcessModel.tradingPeer.getP2pEncryptPubKey(),
new SendMessageListener() {
@Override
public void handleResult() {

View File

@ -40,13 +40,13 @@ public class OffererSendsRequestSellerDepositPaymentMessage extends OffererTrade
try {
RequestPayDepositMessage tradeMessage = new RequestPayDepositMessage(
offererTradeProcessModel.getId(),
offererTradeProcessModel.offerer.getConnectedOutputsForAllInputs(),
offererTradeProcessModel.offerer.getOutputs(),
offererTradeProcessModel.offerer.getTradeWalletPubKey(),
offererTradeProcessModel.offerer.getP2pSigPubKey(),
offererTradeProcessModel.offerer.getP2pEncryptPubKey(),
offererTradeProcessModel.offerer.getFiatAccount(),
offererTradeProcessModel.offerer.getAccountId());
offererTradeProcessModel.getConnectedOutputsForAllInputs(),
offererTradeProcessModel.getOutputs(),
offererTradeProcessModel.getTradeWalletPubKey(),
offererTradeProcessModel.getP2pSigPubKey(),
offererTradeProcessModel.getP2pEncryptPubKey(),
offererTradeProcessModel.getFiatAccount(),
offererTradeProcessModel.getAccountId());
offererTradeProcessModel.getMessageService().sendMessage(offererTrade.getTradingPeer(), tradeMessage, new SendMessageListener() {
@Override

View File

@ -47,13 +47,13 @@ public class OffererSignsAndPublishDepositTx extends OffererTradeTask {
Coin inputAmount = offererTrade.getSecurityDeposit().add(FeePolicy.TX_FEE);
offererTradeProcessModel.getTradeWalletService().signAndPublishDepositTx(
offererTradeProcessModel.taker.getPreparedDepositTx(),
offererTradeProcessModel.offerer.getConnectedOutputsForAllInputs(),
offererTradeProcessModel.taker.getConnectedOutputsForAllInputs(),
offererTradeProcessModel.offerer.getOutputs(),
offererTradeProcessModel.tradingPeer.getPreparedDepositTx(),
offererTradeProcessModel.getConnectedOutputsForAllInputs(),
offererTradeProcessModel.tradingPeer.getConnectedOutputsForAllInputs(),
offererTradeProcessModel.getOutputs(),
inputAmount,
offererTradeProcessModel.offerer.getTradeWalletPubKey(),
offererTradeProcessModel.taker.getTradeWalletPubKey(),
offererTradeProcessModel.getTradeWalletPubKey(),
offererTradeProcessModel.tradingPeer.getTradeWalletPubKey(),
offererTradeProcessModel.getArbitratorPubKey(),
new FutureCallback<Transaction>() {
@Override

View File

@ -42,20 +42,20 @@ public class OffererVerifiesAndSignsContract extends OffererTradeTask {
offererTradeProcessModel.getOffer(),
offererTrade.getTradeAmount(),
offererTradeProcessModel.getTakeOfferFeeTxId(),
offererTradeProcessModel.offerer.getAccountId(),
offererTradeProcessModel.taker.getAccountId(),
offererTradeProcessModel.offerer.getFiatAccount(),
offererTradeProcessModel.taker.getFiatAccount(),
offererTradeProcessModel.offerer.getP2pSigPubKey(),
offererTradeProcessModel.taker.getP2pSigPubKey());
offererTradeProcessModel.getAccountId(),
offererTradeProcessModel.tradingPeer.getAccountId(),
offererTradeProcessModel.getFiatAccount(),
offererTradeProcessModel.tradingPeer.getFiatAccount(),
offererTradeProcessModel.getP2pSigPubKey(),
offererTradeProcessModel.tradingPeer.getP2pSigPubKey());
String contractAsJson = Utilities.objectToJson(contract);
String signature = offererTradeProcessModel.getSignatureService().signMessage(offererTradeProcessModel.offerer.getRegistrationKeyPair(),
String signature = offererTradeProcessModel.getSignatureService().signMessage(offererTradeProcessModel.getRegistrationKeyPair(),
contractAsJson);
offererTrade.setContract(contract);
offererTrade.setContractAsJson(contractAsJson);
offererTrade.setOffererContractSignature(signature);
offererTrade.setTakerContractSignature(offererTradeProcessModel.taker.getContractSignature());
offererTrade.setTakerContractSignature(offererTradeProcessModel.tradingPeer.getContractSignature());
complete();
} catch (Throwable t) {

View File

@ -47,15 +47,15 @@ public class TakerCreatesAndSignsPayoutTx extends TakerTradeTask {
takerTrade.getDepositTx(),
takerPayoutAmount,
offererPayoutAmount,
takerTradeProcessModel.taker.getAddressEntry(),
takerTradeProcessModel.offerer.getPayoutAddressString(),
takerTradeProcessModel.taker.getTradeWalletPubKey(),
takerTradeProcessModel.offerer.getTradeWalletPubKey(),
takerTradeProcessModel.getAddressEntry(),
takerTradeProcessModel.tradingPeer.getPayoutAddressString(),
takerTradeProcessModel.getTradeWalletPubKey(),
takerTradeProcessModel.tradingPeer.getTradeWalletPubKey(),
takerTradeProcessModel.getArbitratorPubKey());
takerTradeProcessModel.taker.setPayoutTxSignature(takerPayoutTxSignature);
takerTradeProcessModel.taker.setPayoutAmount(takerPayoutAmount);
takerTradeProcessModel.offerer.setPayoutAmount(offererPayoutAmount);
takerTradeProcessModel.setPayoutTxSignature(takerPayoutTxSignature);
takerTradeProcessModel.setPayoutAmount(takerPayoutAmount);
takerTradeProcessModel.tradingPeer.setPayoutAmount(offererPayoutAmount);
complete();
} catch (Throwable t) {

View File

@ -41,10 +41,10 @@ public class TakerCreatesDepositTxInputs extends TakerTradeTask {
log.debug("takerTrade.id" + takerTrade.getId());
Coin inputAmount = takerTrade.getSecurityDeposit().add(FeePolicy.TX_FEE);
TradeWalletService.Result result = takerTradeProcessModel.getTradeWalletService().createDepositTxInputs(inputAmount,
takerTradeProcessModel.taker.getAddressEntry());
takerTradeProcessModel.getAddressEntry());
takerTradeProcessModel.taker.setConnectedOutputsForAllInputs(result.getConnectedOutputsForAllInputs());
takerTradeProcessModel.taker.setOutputs(result.getOutputs());
takerTradeProcessModel.setConnectedOutputsForAllInputs(result.getConnectedOutputsForAllInputs());
takerTradeProcessModel.setOutputs(result.getOutputs());
complete();
} catch (Throwable t) {

View File

@ -42,17 +42,17 @@ public class TakerProcessRequestPublishDepositTxFromTakerMessage extends TakerTr
checkTradeId(takerTradeProcessModel.getId(), message);
checkNotNull(message);
takerTradeProcessModel.offerer.setFiatAccount(checkNotNull(message.takerFiatAccount));
takerTradeProcessModel.offerer.setAccountId(nonEmptyStringOf(message.takerAccountId));
takerTradeProcessModel.offerer.setP2pSigPubKey(checkNotNull(message.takerP2PSigPublicKey));
takerTradeProcessModel.offerer.setP2pSigPubKey(checkNotNull(message.takerP2PSigPublicKey));
takerTradeProcessModel.offerer.setTradeWalletPubKey(checkNotNull(message.sellerTradeWalletPubKey));
takerTradeProcessModel.offerer.setP2pEncryptPubKey(checkNotNull(message.takerP2PEncryptPublicKey));
takerTradeProcessModel.offerer.setContractAsJson(nonEmptyStringOf(message.takerContractAsJson));
takerTradeProcessModel.offerer.setContractSignature(nonEmptyStringOf(message.takerContractSignature));
takerTradeProcessModel.offerer.setPayoutAddressString(nonEmptyStringOf(message.takerPayoutAddressString));
takerTradeProcessModel.offerer.setPreparedDepositTx(checkNotNull(message.takersPreparedDepositTx));
takerTradeProcessModel.offerer.setConnectedOutputsForAllInputs(checkNotNull(message.takerConnectedOutputsForAllInputs));
takerTradeProcessModel.tradingPeer.setFiatAccount(checkNotNull(message.takerFiatAccount));
takerTradeProcessModel.tradingPeer.setAccountId(nonEmptyStringOf(message.takerAccountId));
takerTradeProcessModel.tradingPeer.setP2pSigPubKey(checkNotNull(message.takerP2PSigPublicKey));
takerTradeProcessModel.tradingPeer.setP2pSigPubKey(checkNotNull(message.takerP2PSigPublicKey));
takerTradeProcessModel.tradingPeer.setTradeWalletPubKey(checkNotNull(message.sellerTradeWalletPubKey));
takerTradeProcessModel.tradingPeer.setP2pEncryptPubKey(checkNotNull(message.takerP2PEncryptPublicKey));
takerTradeProcessModel.tradingPeer.setContractAsJson(nonEmptyStringOf(message.takerContractAsJson));
takerTradeProcessModel.tradingPeer.setContractSignature(nonEmptyStringOf(message.takerContractSignature));
takerTradeProcessModel.tradingPeer.setPayoutAddressString(nonEmptyStringOf(message.takerPayoutAddressString));
takerTradeProcessModel.tradingPeer.setPreparedDepositTx(checkNotNull(message.takersPreparedDepositTx));
takerTradeProcessModel.tradingPeer.setConnectedOutputsForAllInputs(checkNotNull(message.takerConnectedOutputsForAllInputs));
checkArgument(message.takerConnectedOutputsForAllInputs.size() > 0);
complete();

View File

@ -39,14 +39,14 @@ public class TakerSendsFiatTransferStartedMessage extends TakerTradeTask {
protected void doRun() {
try {
FiatTransferStartedMessage tradeMessage = new FiatTransferStartedMessage(takerTradeProcessModel.getId(),
takerTradeProcessModel.taker.getPayoutTxSignature(),
takerTradeProcessModel.taker.getPayoutAmount(),
takerTradeProcessModel.offerer.getPayoutAmount(),
takerTradeProcessModel.taker.getAddressEntry().getAddressString());
takerTradeProcessModel.getPayoutTxSignature(),
takerTradeProcessModel.getPayoutAmount(),
takerTradeProcessModel.tradingPeer.getPayoutAmount(),
takerTradeProcessModel.getAddressEntry().getAddressString());
takerTradeProcessModel.getMessageService().sendMessage(takerTrade.getTradingPeer(), tradeMessage,
takerTradeProcessModel.taker.getP2pSigPubKey(),
takerTradeProcessModel.taker.getP2pEncryptPubKey(),
takerTradeProcessModel.getP2pSigPubKey(),
takerTradeProcessModel.getP2pEncryptPubKey(),
new SendMessageListener() {
@Override
public void handleResult() {

View File

@ -47,7 +47,7 @@ public class TakerSendsRequestDepositTxInputsMessage extends TakerTradeTask {
takerTradeProcessModel.getId(),
takerTradeProcessModel.getTakeOfferFeeTx().getHashAsString(),
takerTrade.getTradeAmount(),
takerTradeProcessModel.taker.getTradeWalletPubKey());
takerTradeProcessModel.getTradeWalletPubKey());
takerTradeProcessModel.getMessageService().sendMessage(takerTrade.getTradingPeer(), message, new SendMessageListener() {
@Override

View File

@ -41,13 +41,13 @@ public class TakerSendsRequestPayDepositMessage extends TakerTradeTask {
RequestPayDepositFromOffererMessage message = new RequestPayDepositFromOffererMessage(
takerTradeProcessModel.getId(),
model.getTradeAmount(),
takerTradeProcessModel.taker.getConnectedOutputsForAllInputs(),
takerTradeProcessModel.taker.getOutputs(),
takerTradeProcessModel.taker.getTradeWalletPubKey(),
takerTradeProcessModel.taker.getP2pSigPubKey(),
takerTradeProcessModel.taker.getP2pEncryptPubKey(),
takerTradeProcessModel.taker.getFiatAccount(),
takerTradeProcessModel.taker.getAccountId());
takerTradeProcessModel.getConnectedOutputsForAllInputs(),
takerTradeProcessModel.getOutputs(),
takerTradeProcessModel.getTradeWalletPubKey(),
takerTradeProcessModel.getP2pSigPubKey(),
takerTradeProcessModel.getP2pEncryptPubKey(),
takerTradeProcessModel.getFiatAccount(),
takerTradeProcessModel.getAccountId());
takerTradeProcessModel.getMessageService().sendMessage(takerTrade.getTradingPeer(), message, new SendMessageListener() {
@Override

View File

@ -40,15 +40,15 @@ public class TakerSendsRequestPublishDepositTxMessage extends TakerTradeTask {
try {
RequestPublishDepositTxMessage tradeMessage = new RequestPublishDepositTxMessage(
takerTradeProcessModel.getId(),
takerTradeProcessModel.taker.getFiatAccount(),
takerTradeProcessModel.taker.getAccountId(),
takerTradeProcessModel.taker.getP2pSigPubKey(),
takerTradeProcessModel.taker.getP2pEncryptPublicKey(),
takerTradeProcessModel.getFiatAccount(),
takerTradeProcessModel.getAccountId(),
takerTradeProcessModel.getP2pSigPubKey(),
takerTradeProcessModel.getP2pEncryptPublicKey(),
takerTrade.getContractAsJson(),
takerTrade.getTakerContractSignature(),
takerTradeProcessModel.taker.getAddressEntry().getAddressString(),
takerTradeProcessModel.taker.getPreparedDepositTx(),
takerTradeProcessModel.taker.getConnectedOutputsForAllInputs()
takerTradeProcessModel.getAddressEntry().getAddressString(),
takerTradeProcessModel.getPreparedDepositTx(),
takerTradeProcessModel.getConnectedOutputsForAllInputs()
);
takerTradeProcessModel.getMessageService().sendMessage(takerTrade.getTradingPeer(), tradeMessage, new SendMessageListener() {

View File

@ -47,13 +47,13 @@ public class TakerSignsAndPublishDepositTx extends TakerTradeTask {
Coin inputAmount = takerTrade.getSecurityDeposit().add(FeePolicy.TX_FEE);
takerTradeProcessModel.getTradeWalletService().signAndPublishDepositTx(
takerTradeProcessModel.offerer.getPreparedDepositTx(),
takerTradeProcessModel.taker.getConnectedOutputsForAllInputs(),
takerTradeProcessModel.offerer.getConnectedOutputsForAllInputs(),
takerTradeProcessModel.taker.getOutputs(),
takerTradeProcessModel.tradingPeer.getPreparedDepositTx(),
takerTradeProcessModel.getConnectedOutputsForAllInputs(),
takerTradeProcessModel.tradingPeer.getConnectedOutputsForAllInputs(),
takerTradeProcessModel.getOutputs(),
inputAmount,
takerTradeProcessModel.taker.getTradeWalletPubKey(),
takerTradeProcessModel.offerer.getTradeWalletPubKey(),
takerTradeProcessModel.getTradeWalletPubKey(),
takerTradeProcessModel.tradingPeer.getTradeWalletPubKey(),
takerTradeProcessModel.getArbitratorPubKey(),
new FutureCallback<Transaction>() {
@Override

View File

@ -40,20 +40,20 @@ public class TakerVerifiesAndSignsContract extends TakerTradeTask {
takerTradeProcessModel.getOffer(),
takerTrade.getTradeAmount(),
takerTradeProcessModel.getTakeOfferFeeTx().getHashAsString(),
takerTradeProcessModel.offerer.getAccountId(),
takerTradeProcessModel.taker.getAccountId(),
takerTradeProcessModel.offerer.getFiatAccount(),
takerTradeProcessModel.taker.getFiatAccount(),
takerTradeProcessModel.offerer.getP2pSigPubKey(),
takerTradeProcessModel.taker.getP2pSigPubKey());
takerTradeProcessModel.tradingPeer.getAccountId(),
takerTradeProcessModel.getAccountId(),
takerTradeProcessModel.tradingPeer.getFiatAccount(),
takerTradeProcessModel.getFiatAccount(),
takerTradeProcessModel.tradingPeer.getP2pSigPubKey(),
takerTradeProcessModel.getP2pSigPubKey());
String contractAsJson = Utilities.objectToJson(contract);
String signature = takerTradeProcessModel.getSignatureService().signMessage(takerTradeProcessModel.taker.getRegistrationKeyPair(),
String signature = takerTradeProcessModel.getSignatureService().signMessage(takerTradeProcessModel.getRegistrationKeyPair(),
contractAsJson);
takerTrade.setContract(contract);
takerTrade.setContractAsJson(contractAsJson);
takerTrade.setOffererContractSignature(signature);
takerTrade.setOffererContractSignature(takerTradeProcessModel.offerer.getContractSignature());
takerTrade.setOffererContractSignature(takerTradeProcessModel.tradingPeer.getContractSignature());
complete();
} catch (Throwable t) {

View File

@ -1,186 +0,0 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.trade.protocol.trade.offerer.models;
import io.bitsquare.btc.AddressEntry;
import io.bitsquare.btc.WalletService;
import io.bitsquare.fiat.FiatAccount;
import io.bitsquare.offer.Offer;
import io.bitsquare.user.User;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionOutput;
import org.bitcoinj.crypto.DeterministicKey;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.security.PublicKey;
import java.util.Arrays;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Offerer implements Serializable {
// That object is saved to disc. We need to take care of changes to not break deserialization.
private static final long serialVersionUID = 1L;
transient private static final Logger log = LoggerFactory.getLogger(Offerer.class);
// Transient/Immutable
private transient Offer offer;
private transient WalletService walletService;
private transient User user;
// Mutable
private byte[] payoutTxSignature;
private Coin payoutAmount;
private List<TransactionOutput> connectedOutputsForAllInputs;
private List<TransactionOutput> outputs; // used to verify amounts with change outputs
private Transaction preparedDepositTx;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor, initialization
///////////////////////////////////////////////////////////////////////////////////////////
public Offerer() {
log.trace("Created by constructor");
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
log.trace("Created from serialized form.");
}
// We need to wait until backend services are ready to set the required dependencies
public void onAllServicesInitialized(Offer offer,
WalletService walletService,
User user) {
log.trace("onBackendReady");
this.offer = offer;
this.walletService = walletService;
this.user = user;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getter only
///////////////////////////////////////////////////////////////////////////////////////////
public FiatAccount getFiatAccount() {
return user.getFiatAccount(offer.getBankAccountId());
}
public String getAccountId() {
return user.getAccountId();
}
public PublicKey getP2pSigPubKey() {
return user.getP2PSigPubKey();
}
public PublicKey getP2pEncryptPublicKey() {
return user.getP2PEncryptPubKey();
}
public PublicKey getP2pEncryptPubKey() {
return user.getP2PEncryptPubKey();
}
public byte[] getRegistrationPubKey() {
return walletService.getRegistrationAddressEntry().getPubKey();
}
public DeterministicKey getRegistrationKeyPair() {
return walletService.getRegistrationAddressEntry().getKeyPair();
}
public AddressEntry getAddressEntry() {
return walletService.getAddressEntry(offer.getId());
}
public byte[] getTradeWalletPubKey() {
return getAddressEntry().getPubKey();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getter/Setter for Mutable objects
///////////////////////////////////////////////////////////////////////////////////////////
public List<TransactionOutput> getOutputs() {
return outputs;
}
public void setOutputs(List<TransactionOutput> outputs) {
this.outputs = outputs;
}
public byte[] getPayoutTxSignature() {
return payoutTxSignature;
}
public void setPayoutTxSignature(byte[] payoutTxSignature) {
this.payoutTxSignature = payoutTxSignature;
}
public Coin getPayoutAmount() {
return payoutAmount;
}
public void setPayoutAmount(Coin payoutAmount) {
this.payoutAmount = payoutAmount;
}
public List<TransactionOutput> getConnectedOutputsForAllInputs() {
return connectedOutputsForAllInputs;
}
public void setConnectedOutputsForAllInputs(List<TransactionOutput> connectedOutputsForAllInputs) {
this.connectedOutputsForAllInputs = connectedOutputsForAllInputs;
}
public Transaction getPreparedDepositTx() {
return preparedDepositTx;
}
public void setPreparedDepositTx(Transaction preparedDepositTx) {
this.preparedDepositTx = preparedDepositTx;
}
@Override
public String toString() {
return "Offerer{" +
"offer=" + offer +
", walletService=" + walletService +
", user=" + user +
", payoutTxSignature=" + Arrays.toString(payoutTxSignature) +
", payoutAmount=" + payoutAmount +
", connectedOutputsForAllInputs=" + connectedOutputsForAllInputs +
", outputs=" + outputs +
'}';
}
}

View File

@ -18,20 +18,29 @@
package io.bitsquare.trade.protocol.trade.offerer.models;
import io.bitsquare.arbitration.ArbitrationRepository;
import io.bitsquare.btc.AddressEntry;
import io.bitsquare.btc.BlockChainService;
import io.bitsquare.btc.TradeWalletService;
import io.bitsquare.btc.WalletService;
import io.bitsquare.crypto.SignatureService;
import io.bitsquare.fiat.FiatAccount;
import io.bitsquare.offer.Offer;
import io.bitsquare.p2p.MessageService;
import io.bitsquare.trade.protocol.trade.ProcessModel;
import io.bitsquare.user.User;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionOutput;
import org.bitcoinj.crypto.DeterministicKey;
import java.io.IOException;
import java.io.Serializable;
import java.security.PublicKey;
import java.util.List;
import javax.annotation.Nullable;
import org.slf4j.Logger;
@ -44,12 +53,21 @@ public class OffererProcessModel extends ProcessModel implements Serializable {
transient private static final Logger log = LoggerFactory.getLogger(OffererProcessModel.class);
// Immutable
public final Taker taker;
public final Offerer offerer;
public final TradingPeer tradingPeer;
// Transient/Immutable
private transient Offer offer;
private transient WalletService walletService;
private transient User user;
// Mutable
private String takeOfferFeeTxId;
private Transaction payoutTx;
private byte[] payoutTxSignature;
private Coin payoutAmount;
private List<TransactionOutput> connectedOutputsForAllInputs;
private List<TransactionOutput> outputs; // used to verify amounts with change outputs
private Transaction preparedDepositTx;
///////////////////////////////////////////////////////////////////////////////////////////
@ -58,8 +76,7 @@ public class OffererProcessModel extends ProcessModel implements Serializable {
public OffererProcessModel() {
log.trace("Created by constructor");
taker = new Taker();
offerer = new Offerer();
tradingPeer = new TradingPeer();
}
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
@ -84,8 +101,9 @@ public class OffererProcessModel extends ProcessModel implements Serializable {
signatureService,
arbitrationRepository,
user);
offerer.onAllServicesInitialized(offer, walletService, user);
this.offer = offer;
this.walletService = walletService;
this.user = user;
}
@ -110,14 +128,90 @@ public class OffererProcessModel extends ProcessModel implements Serializable {
this.payoutTx = payoutTx;
}
@Override
public String toString() {
return "OffererProcessModel{" +
"taker=" + taker +
", offerer=" + offerer +
", takeOfferFeeTxId='" + takeOfferFeeTxId + '\'' +
'}';
///////////////////////////////////////////////////////////////////////////////////////////
// Getter only
///////////////////////////////////////////////////////////////////////////////////////////
public FiatAccount getFiatAccount() {
return user.getFiatAccount(offer.getBankAccountId());
}
public String getAccountId() {
return user.getAccountId();
}
public PublicKey getP2pSigPubKey() {
return user.getP2PSigPubKey();
}
public PublicKey getP2pEncryptPublicKey() {
return user.getP2PEncryptPubKey();
}
public PublicKey getP2pEncryptPubKey() {
return user.getP2PEncryptPubKey();
}
public byte[] getRegistrationPubKey() {
return walletService.getRegistrationAddressEntry().getPubKey();
}
public DeterministicKey getRegistrationKeyPair() {
return walletService.getRegistrationAddressEntry().getKeyPair();
}
public AddressEntry getAddressEntry() {
return walletService.getAddressEntry(offer.getId());
}
public byte[] getTradeWalletPubKey() {
return getAddressEntry().getPubKey();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getter/Setter for Mutable objects
///////////////////////////////////////////////////////////////////////////////////////////
public List<TransactionOutput> getOutputs() {
return outputs;
}
public void setOutputs(List<TransactionOutput> outputs) {
this.outputs = outputs;
}
public byte[] getPayoutTxSignature() {
return payoutTxSignature;
}
public void setPayoutTxSignature(byte[] payoutTxSignature) {
this.payoutTxSignature = payoutTxSignature;
}
public Coin getPayoutAmount() {
return payoutAmount;
}
public void setPayoutAmount(Coin payoutAmount) {
this.payoutAmount = payoutAmount;
}
public List<TransactionOutput> getConnectedOutputsForAllInputs() {
return connectedOutputsForAllInputs;
}
public void setConnectedOutputsForAllInputs(List<TransactionOutput> connectedOutputsForAllInputs) {
this.connectedOutputsForAllInputs = connectedOutputsForAllInputs;
}
public Transaction getPreparedDepositTx() {
return preparedDepositTx;
}
public void setPreparedDepositTx(Transaction preparedDepositTx) {
this.preparedDepositTx = preparedDepositTx;
}
}

View File

@ -35,11 +35,11 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Taker implements Serializable {
public class TradingPeer implements Serializable {
// That object is saved to disc. We need to take care of changes to not break deserialization.
private static final long serialVersionUID = 1L;
transient private static final Logger log = LoggerFactory.getLogger(Taker.class);
transient private static final Logger log = LoggerFactory.getLogger(TradingPeer.class);
// Mutable
private String accountId;
@ -60,7 +60,7 @@ public class Taker implements Serializable {
// Constructor, initialization
///////////////////////////////////////////////////////////////////////////////////////////
public Taker() {
public TradingPeer() {
log.trace("Created by constructor");
}

View File

@ -41,14 +41,14 @@ public class OffererCreatesAndSignsContract extends OffererTradeTask {
offererTradeProcessModel.getOffer(),
model.getTradeAmount(),
offererTradeProcessModel.getTakeOfferFeeTxId(),
offererTradeProcessModel.offerer.getAccountId(),
offererTradeProcessModel.offerer.getAccountId(),
offererTradeProcessModel.offerer.getFiatAccount(),
offererTradeProcessModel.offerer.getFiatAccount(),
offererTradeProcessModel.getAccountId(),
offererTradeProcessModel.getAccountId(),
offererTradeProcessModel.getFiatAccount(),
offererTradeProcessModel.getFiatAccount(),
offererTradeProcessModel.getOffer().getP2PSigPubKey(),
offererTradeProcessModel.offerer.getP2pSigPubKey());
offererTradeProcessModel.getP2pSigPubKey());
String contractAsJson = Utilities.objectToJson(contract);
String signature = offererTradeProcessModel.getSignatureService().signMessage(offererTradeProcessModel.offerer.getRegistrationKeyPair(),
String signature = offererTradeProcessModel.getSignatureService().signMessage(offererTradeProcessModel.getRegistrationKeyPair(),
contractAsJson);
model.setContract(contract);

View File

@ -45,16 +45,16 @@ public class OffererCreatesAndSignsDepositTx extends OffererTradeTask {
TradeWalletService.Result result = offererTradeProcessModel.getTradeWalletService().createAndSignDepositTx(
inputAmount,
msOutputAmount,
offererTradeProcessModel.taker.getConnectedOutputsForAllInputs(),
offererTradeProcessModel.taker.getOutputs(),
offererTradeProcessModel.offerer.getAddressEntry(),
offererTradeProcessModel.taker.getTradeWalletPubKey(),
offererTradeProcessModel.offerer.getTradeWalletPubKey(),
offererTradeProcessModel.tradingPeer.getConnectedOutputsForAllInputs(),
offererTradeProcessModel.tradingPeer.getOutputs(),
offererTradeProcessModel.getAddressEntry(),
offererTradeProcessModel.tradingPeer.getTradeWalletPubKey(),
offererTradeProcessModel.getTradeWalletPubKey(),
offererTradeProcessModel.getArbitratorPubKey());
offererTradeProcessModel.offerer.setConnectedOutputsForAllInputs(result.getConnectedOutputsForAllInputs());
offererTradeProcessModel.offerer.setPreparedDepositTx(result.getDepositTx());
offererTradeProcessModel.setConnectedOutputsForAllInputs(result.getConnectedOutputsForAllInputs());
offererTradeProcessModel.setPreparedDepositTx(result.getDepositTx());
complete();
} catch (Throwable t) {

View File

@ -44,10 +44,10 @@ public class OffererProcessFiatTransferStartedMessage extends OffererTradeTask {
checkTradeId(offererTradeProcessModel.getId(), message);
checkNotNull(message);
offererTradeProcessModel.taker.setSignature(checkNotNull(message.buyerSignature));
offererTradeProcessModel.offerer.setPayoutAmount(positiveCoinOf(nonZeroCoinOf(message.sellerPayoutAmount)));
offererTradeProcessModel.taker.setPayoutAmount(positiveCoinOf(nonZeroCoinOf(message.buyerPayoutAmount)));
offererTradeProcessModel.taker.setPayoutAddressString(nonEmptyStringOf(message.buyerPayoutAddress));
offererTradeProcessModel.tradingPeer.setSignature(checkNotNull(message.buyerSignature));
offererTradeProcessModel.setPayoutAmount(positiveCoinOf(nonZeroCoinOf(message.sellerPayoutAmount)));
offererTradeProcessModel.tradingPeer.setPayoutAmount(positiveCoinOf(nonZeroCoinOf(message.buyerPayoutAmount)));
offererTradeProcessModel.tradingPeer.setPayoutAddressString(nonEmptyStringOf(message.buyerPayoutAddress));
if (offererTrade instanceof OffererAsBuyerTrade)
offererTrade.setProcessState(OffererAsBuyerTrade.ProcessState.FIAT_PAYMENT_STARTED);

View File

@ -42,14 +42,14 @@ public class OffererProcessRequestPayDepositFromOffererMessage extends OffererTr
checkTradeId(offererTradeProcessModel.getId(), message);
checkNotNull(message);
offererTradeProcessModel.taker.setConnectedOutputsForAllInputs(checkNotNull(message.buyerConnectedOutputsForAllInputs));
offererTradeProcessModel.tradingPeer.setConnectedOutputsForAllInputs(checkNotNull(message.buyerConnectedOutputsForAllInputs));
checkArgument(message.buyerConnectedOutputsForAllInputs.size() > 0);
offererTradeProcessModel.taker.setOutputs(checkNotNull(message.buyerOutputs));
offererTradeProcessModel.taker.setTradeWalletPubKey(checkNotNull(message.buyerTradeWalletPubKey));
offererTradeProcessModel.taker.setP2pSigPubKey(checkNotNull(message.buyerP2PSigPublicKey));
offererTradeProcessModel.taker.setP2pEncryptPubKey(checkNotNull(message.buyerP2PEncryptPublicKey));
offererTradeProcessModel.taker.setFiatAccount(checkNotNull(message.buyerFiatAccount));
offererTradeProcessModel.taker.setAccountId(nonEmptyStringOf(message.buyerAccountId));
offererTradeProcessModel.tradingPeer.setOutputs(checkNotNull(message.buyerOutputs));
offererTradeProcessModel.tradingPeer.setTradeWalletPubKey(checkNotNull(message.buyerTradeWalletPubKey));
offererTradeProcessModel.tradingPeer.setP2pSigPubKey(checkNotNull(message.buyerP2PSigPublicKey));
offererTradeProcessModel.tradingPeer.setP2pEncryptPubKey(checkNotNull(message.buyerP2PEncryptPublicKey));
offererTradeProcessModel.tradingPeer.setFiatAccount(checkNotNull(message.buyerFiatAccount));
offererTradeProcessModel.tradingPeer.setAccountId(nonEmptyStringOf(message.buyerAccountId));
offererTrade.setTradeAmount(positiveCoinOf(nonZeroCoinOf(message.tradeAmount)));
complete();

View File

@ -41,8 +41,8 @@ public class OffererSendsPayoutTxPublishedMessage extends OffererTradeTask {
PayoutTxPublishedMessage tradeMessage = new PayoutTxPublishedMessage(offererTradeProcessModel.getId(), offererTradeProcessModel.getPayoutTx());
offererTradeProcessModel.getMessageService().sendMessage(offererTrade.getTradingPeer(),
tradeMessage,
offererTradeProcessModel.offerer.getP2pSigPubKey(),
offererTradeProcessModel.offerer.getP2pEncryptPubKey(),
offererTradeProcessModel.getP2pSigPubKey(),
offererTradeProcessModel.getP2pEncryptPubKey(),
new SendMessageListener() {
@Override
public void handleResult() {

View File

@ -40,16 +40,16 @@ public class OffererSendsRequestPublishDepositTxFromTakerMessage extends Offerer
try {
RequestPublishDepositTxFromTakerMessage tradeMessage = new RequestPublishDepositTxFromTakerMessage(
offererTradeProcessModel.getId(),
offererTradeProcessModel.offerer.getFiatAccount(),
offererTradeProcessModel.offerer.getAccountId(),
offererTradeProcessModel.offerer.getTradeWalletPubKey(),
offererTradeProcessModel.offerer.getP2pSigPubKey(),
offererTradeProcessModel.offerer.getP2pEncryptPublicKey(),
offererTradeProcessModel.getFiatAccount(),
offererTradeProcessModel.getAccountId(),
offererTradeProcessModel.getTradeWalletPubKey(),
offererTradeProcessModel.getP2pSigPubKey(),
offererTradeProcessModel.getP2pEncryptPublicKey(),
offererTrade.getContractAsJson(),
offererTrade.getOffererContractSignature(),
offererTradeProcessModel.offerer.getAddressEntry().getAddressString(),
offererTradeProcessModel.offerer.getPreparedDepositTx(),
offererTradeProcessModel.offerer.getConnectedOutputsForAllInputs()
offererTradeProcessModel.getAddressEntry().getAddressString(),
offererTradeProcessModel.getPreparedDepositTx(),
offererTradeProcessModel.getConnectedOutputsForAllInputs()
);
offererTradeProcessModel.getMessageService().sendMessage(offererTrade.getTradingPeer(), tradeMessage, new SendMessageListener() {

View File

@ -44,13 +44,13 @@ public class OffererSignsAndPublishPayoutTx extends OffererTradeTask {
try {
offererTradeProcessModel.getTradeWalletService().signAndPublishPayoutTx(
offererTrade.getDepositTx(),
offererTradeProcessModel.taker.getSignature(),
offererTradeProcessModel.taker.getPayoutAmount(),
offererTradeProcessModel.offerer.getPayoutAmount(),
offererTradeProcessModel.taker.getPayoutAddressString(),
offererTradeProcessModel.offerer.getAddressEntry(),
offererTradeProcessModel.taker.getTradeWalletPubKey(),
offererTradeProcessModel.offerer.getTradeWalletPubKey(),
offererTradeProcessModel.tradingPeer.getSignature(),
offererTradeProcessModel.tradingPeer.getPayoutAmount(),
offererTradeProcessModel.getPayoutAmount(),
offererTradeProcessModel.tradingPeer.getPayoutAddressString(),
offererTradeProcessModel.getAddressEntry(),
offererTradeProcessModel.tradingPeer.getTradeWalletPubKey(),
offererTradeProcessModel.getTradeWalletPubKey(),
offererTradeProcessModel.getArbitratorPubKey(),
new FutureCallback<Transaction>() {
@Override

View File

@ -41,14 +41,14 @@ public class TakerCreatesAndSignContract extends TakerTradeTask {
takerTradeProcessModel.getOffer(),
model.getTradeAmount(),
takerTradeProcessModel.getTakeOfferFeeTx().getHashAsString(),
takerTradeProcessModel.offerer.getAccountId(),
takerTradeProcessModel.taker.getAccountId(),
takerTradeProcessModel.offerer.getFiatAccount(),
takerTradeProcessModel.taker.getFiatAccount(),
takerTradeProcessModel.tradingPeer.getAccountId(),
takerTradeProcessModel.getAccountId(),
takerTradeProcessModel.tradingPeer.getFiatAccount(),
takerTradeProcessModel.getFiatAccount(),
takerTradeProcessModel.getOffer().getP2PSigPubKey(),
takerTradeProcessModel.taker.getP2pSigPubKey());
takerTradeProcessModel.getP2pSigPubKey());
String contractAsJson = Utilities.objectToJson(contract);
String signature = takerTradeProcessModel.getSignatureService().signMessage(takerTradeProcessModel.taker.getRegistrationKeyPair(), contractAsJson);
String signature = takerTradeProcessModel.getSignatureService().signMessage(takerTradeProcessModel.getRegistrationKeyPair(), contractAsJson);
model.setContract(contract);
model.setContractAsJson(contractAsJson);

View File

@ -45,15 +45,15 @@ public class TakerCreatesAndSignsDepositTx extends TakerTradeTask {
TradeWalletService.Result result = takerTradeProcessModel.getTradeWalletService().createAndSignDepositTx(
inputAmount,
msOutputAmount,
takerTradeProcessModel.offerer.getConnectedOutputsForAllInputs(),
takerTradeProcessModel.offerer.getOutputs(),
takerTradeProcessModel.taker.getAddressEntry(),
takerTradeProcessModel.offerer.getTradeWalletPubKey(),
takerTradeProcessModel.taker.getTradeWalletPubKey(),
takerTradeProcessModel.tradingPeer.getConnectedOutputsForAllInputs(),
takerTradeProcessModel.tradingPeer.getOutputs(),
takerTradeProcessModel.getAddressEntry(),
takerTradeProcessModel.tradingPeer.getTradeWalletPubKey(),
takerTradeProcessModel.getTradeWalletPubKey(),
takerTradeProcessModel.getArbitratorPubKey());
takerTradeProcessModel.taker.setConnectedOutputsForAllInputs(result.getConnectedOutputsForAllInputs());
takerTradeProcessModel.taker.setPreparedDepositTx(result.getDepositTx());
takerTradeProcessModel.setConnectedOutputsForAllInputs(result.getConnectedOutputsForAllInputs());
takerTradeProcessModel.setPreparedDepositTx(result.getDepositTx());
complete();
} catch (Throwable t) {

View File

@ -44,10 +44,10 @@ public class TakerProcessFiatTransferStartedMessage extends TakerTradeTask {
checkTradeId(takerTradeProcessModel.getId(), message);
checkNotNull(message);
takerTradeProcessModel.offerer.setSignature(checkNotNull(message.buyerSignature));
takerTradeProcessModel.offerer.setPayoutAmount(positiveCoinOf(nonZeroCoinOf(message.buyerPayoutAmount)));
takerTradeProcessModel.taker.setPayoutAmount(positiveCoinOf(nonZeroCoinOf(message.sellerPayoutAmount)));
takerTradeProcessModel.offerer.setPayoutAddressString(nonEmptyStringOf(message.buyerPayoutAddress));
takerTradeProcessModel.tradingPeer.setSignature(checkNotNull(message.buyerSignature));
takerTradeProcessModel.tradingPeer.setPayoutAmount(positiveCoinOf(nonZeroCoinOf(message.buyerPayoutAmount)));
takerTradeProcessModel.setPayoutAmount(positiveCoinOf(nonZeroCoinOf(message.sellerPayoutAmount)));
takerTradeProcessModel.tradingPeer.setPayoutAddressString(nonEmptyStringOf(message.buyerPayoutAddress));
if (takerTrade instanceof TakerAsBuyerTrade)
takerTrade.setProcessState(TakerAsBuyerTrade.ProcessState.FIAT_PAYMENT_STARTED);

View File

@ -42,14 +42,14 @@ public class TakerProcessRequestSellerDepositPaymentMessage extends TakerTradeTa
checkTradeId(takerTradeProcessModel.getId(), message);
checkNotNull(message);
takerTradeProcessModel.offerer.setConnectedOutputsForAllInputs(checkNotNull(message.buyerConnectedOutputsForAllInputs));
takerTradeProcessModel.tradingPeer.setConnectedOutputsForAllInputs(checkNotNull(message.buyerConnectedOutputsForAllInputs));
checkArgument(message.buyerConnectedOutputsForAllInputs.size() > 0);
takerTradeProcessModel.offerer.setOutputs(checkNotNull(message.buyerOutputs));
takerTradeProcessModel.offerer.setTradeWalletPubKey(checkNotNull(message.buyerTradeWalletPubKey));
takerTradeProcessModel.offerer.setP2pSigPubKey(checkNotNull(message.buyerP2PSigPublicKey));
takerTradeProcessModel.offerer.setP2pEncryptPubKey(checkNotNull(message.buyerP2PEncryptPublicKey));
takerTradeProcessModel.offerer.setFiatAccount(checkNotNull(message.buyerFiatAccount));
takerTradeProcessModel.offerer.setAccountId(nonEmptyStringOf(message.buyerAccountId));
takerTradeProcessModel.tradingPeer.setOutputs(checkNotNull(message.buyerOutputs));
takerTradeProcessModel.tradingPeer.setTradeWalletPubKey(checkNotNull(message.buyerTradeWalletPubKey));
takerTradeProcessModel.tradingPeer.setP2pSigPubKey(checkNotNull(message.buyerP2PSigPublicKey));
takerTradeProcessModel.tradingPeer.setP2pEncryptPubKey(checkNotNull(message.buyerP2PEncryptPublicKey));
takerTradeProcessModel.tradingPeer.setFiatAccount(checkNotNull(message.buyerFiatAccount));
takerTradeProcessModel.tradingPeer.setAccountId(nonEmptyStringOf(message.buyerAccountId));
complete();
} catch (Throwable t) {

View File

@ -41,8 +41,8 @@ public class TakerSendsPayoutTxPublishedMessage extends TakerTradeTask {
PayoutTxPublishedMessage tradeMessage = new PayoutTxPublishedMessage(takerTradeProcessModel.getId(), takerTradeProcessModel.getPayoutTx());
takerTradeProcessModel.getMessageService().sendMessage(takerTrade.getTradingPeer(),
tradeMessage,
takerTradeProcessModel.offerer.getP2pSigPubKey(),
takerTradeProcessModel.offerer.getP2pEncryptPubKey(),
takerTradeProcessModel.tradingPeer.getP2pSigPubKey(),
takerTradeProcessModel.tradingPeer.getP2pEncryptPubKey(),
new SendMessageListener() {
@Override
public void handleResult() {

View File

@ -44,13 +44,13 @@ public class TakerSignsAndPublishPayoutTx extends TakerTradeTask {
try {
takerTradeProcessModel.getTradeWalletService().signAndPublishPayoutTx(
takerTrade.getDepositTx(),
takerTradeProcessModel.offerer.getSignature(),
takerTradeProcessModel.offerer.getPayoutAmount(),
takerTradeProcessModel.taker.getPayoutAmount(),
takerTradeProcessModel.offerer.getPayoutAddressString(),
takerTradeProcessModel.taker.getAddressEntry(),
takerTradeProcessModel.offerer.getTradeWalletPubKey(),
takerTradeProcessModel.taker.getTradeWalletPubKey(),
takerTradeProcessModel.tradingPeer.getSignature(),
takerTradeProcessModel.tradingPeer.getPayoutAmount(),
takerTradeProcessModel.getPayoutAmount(),
takerTradeProcessModel.tradingPeer.getPayoutAddressString(),
takerTradeProcessModel.getAddressEntry(),
takerTradeProcessModel.tradingPeer.getTradeWalletPubKey(),
takerTradeProcessModel.getTradeWalletPubKey(),
takerTradeProcessModel.getArbitratorPubKey(),
new FutureCallback<Transaction>() {
@Override

View File

@ -38,8 +38,8 @@ public class VerifyTakerAccount extends OffererTradeTask {
try {
//TODO mocked yet
if (offererTradeProcessModel.getBlockChainService().verifyAccountRegistration()) {
if (offererTradeProcessModel.getBlockChainService().isAccountBlackListed(offererTradeProcessModel.taker.getAccountId(), offererTradeProcessModel
.taker
if (offererTradeProcessModel.getBlockChainService().isAccountBlackListed(offererTradeProcessModel.tradingPeer.getAccountId(), offererTradeProcessModel
.tradingPeer
.getFiatAccount())) {
log.error("Taker is blacklisted");
failed("Taker is blacklisted");

View File

@ -38,8 +38,7 @@ public class CreateTakeOfferFeeTx extends TakerTradeTask {
@Override
protected void doRun() {
try {
Transaction createTakeOfferFeeTx = takerTradeProcessModel.getTradeWalletService().createTakeOfferFeeTx(takerTradeProcessModel.taker
.getAddressEntry());
Transaction createTakeOfferFeeTx = takerTradeProcessModel.getTradeWalletService().createTakeOfferFeeTx(takerTradeProcessModel.getAddressEntry());
takerTradeProcessModel.setTakeOfferFeeTx(createTakeOfferFeeTx);

View File

@ -35,8 +35,8 @@ public class VerifyOffererAccount extends TakerTradeTask {
protected void doRun() {
try {
if (takerTradeProcessModel.getBlockChainService().verifyAccountRegistration()) {
if (takerTradeProcessModel.getBlockChainService().isAccountBlackListed(takerTradeProcessModel.offerer.getAccountId(),
takerTradeProcessModel.offerer.getFiatAccount())) {
if (takerTradeProcessModel.getBlockChainService().isAccountBlackListed(takerTradeProcessModel.tradingPeer.getAccountId(),
takerTradeProcessModel.tradingPeer.getFiatAccount())) {
failed("Taker is blacklisted.");
}
else {

View File

@ -1,190 +0,0 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.trade.protocol.trade.taker.models;
import io.bitsquare.btc.AddressEntry;
import io.bitsquare.btc.WalletService;
import io.bitsquare.fiat.FiatAccount;
import io.bitsquare.offer.Offer;
import io.bitsquare.user.User;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionOutput;
import org.bitcoinj.crypto.DeterministicKey;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.security.PublicKey;
import java.util.List;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Taker implements Serializable {
// That object is saved to disc. We need to take care of changes to not break deserialization.
private static final long serialVersionUID = 1L;
transient private static final Logger log = LoggerFactory.getLogger(Taker.class);
// Transient/Immutable
transient private Offer offer;
transient private WalletService walletService;
transient private User user;
// Mutable
private List<TransactionOutput> connectedOutputsForAllInputs;
private Coin payoutAmount;
private Transaction preparedDepositTx;
private List<TransactionOutput> outputs; // used to verify amounts with change outputs
private byte[] payoutTxSignature;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor, initialization
///////////////////////////////////////////////////////////////////////////////////////////
public Taker() {
log.trace("Created by constructor");
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
log.trace("Created from serialized form.");
}
// We need to wait until backend services are ready to set the required dependencies
public void onAllServicesInitialized(Offer offer,
WalletService walletService,
User user) {
log.trace("onBackendReady");
this.offer = offer;
this.walletService = walletService;
this.user = user;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getter only
///////////////////////////////////////////////////////////////////////////////////////////
public FiatAccount getFiatAccount() {
return user.getFiatAccount(offer.getBankAccountId());
}
public DeterministicKey getRegistrationKeyPair() {
return walletService.getRegistrationAddressEntry().getKeyPair();
}
public String getAccountId() {
return user.getAccountId();
}
public PublicKey getP2pSigPubKey() {
return user.getP2PSigPubKey();
}
public PublicKey getP2pEncryptPublicKey() {
return user.getP2PEncryptPubKey();
}
public byte[] getRegistrationPubKey() {
return walletService.getRegistrationAddressEntry().getPubKey();
}
public AddressEntry getAddressEntry() {
return walletService.getAddressEntry(offer.getId());
}
public byte[] getTradeWalletPubKey() {
return getAddressEntry().getPubKey();
}
public PublicKey getP2pEncryptPubKey() {
return user.getP2PEncryptPubKey();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getter/Setter for Mutable objects
///////////////////////////////////////////////////////////////////////////////////////////
@Nullable
public List<TransactionOutput> getConnectedOutputsForAllInputs() {
return connectedOutputsForAllInputs;
}
public void setConnectedOutputsForAllInputs(List<TransactionOutput> connectedOutputsForAllInputs) {
this.connectedOutputsForAllInputs = connectedOutputsForAllInputs;
}
@Nullable
public Coin getPayoutAmount() {
return payoutAmount;
}
public void setPayoutAmount(Coin payoutAmount) {
this.payoutAmount = payoutAmount;
}
@Nullable
public Transaction getPreparedDepositTx() {
return preparedDepositTx;
}
public void setPreparedDepositTx(Transaction preparedDepositTx) {
this.preparedDepositTx = preparedDepositTx;
}
@Nullable
public List<TransactionOutput> getOutputs() {
return outputs;
}
public void setOutputs(List<TransactionOutput> outputs) {
this.outputs = outputs;
}
@Nullable
public byte[] getPayoutTxSignature() {
return payoutTxSignature;
}
public void setPayoutTxSignature(byte[] payoutTxSignature) {
this.payoutTxSignature = payoutTxSignature;
}
@Override
public String toString() {
return "Taker{" +
"offer=" + offer +
", walletService=" + walletService +
", user=" + user +
", connectedOutputsForAllInputs=" + connectedOutputsForAllInputs +
", payoutAmount=" + payoutAmount +
", preparedDepositTx=" + preparedDepositTx +
'}';
}
}

View File

@ -18,20 +18,29 @@
package io.bitsquare.trade.protocol.trade.taker.models;
import io.bitsquare.arbitration.ArbitrationRepository;
import io.bitsquare.btc.AddressEntry;
import io.bitsquare.btc.BlockChainService;
import io.bitsquare.btc.TradeWalletService;
import io.bitsquare.btc.WalletService;
import io.bitsquare.crypto.SignatureService;
import io.bitsquare.fiat.FiatAccount;
import io.bitsquare.offer.Offer;
import io.bitsquare.p2p.MessageService;
import io.bitsquare.trade.protocol.trade.ProcessModel;
import io.bitsquare.user.User;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionOutput;
import org.bitcoinj.crypto.DeterministicKey;
import java.io.IOException;
import java.io.Serializable;
import java.security.PublicKey;
import java.util.List;
import javax.annotation.Nullable;
import org.slf4j.Logger;
@ -49,12 +58,21 @@ public class TakerProcessModel extends ProcessModel implements Serializable {
transient private static final Logger log = LoggerFactory.getLogger(TakerProcessModel.class);
// Immutable
public final Taker taker;
public final Offerer offerer;
public final TradingPeer tradingPeer;
// Transient/Immutable
transient private Offer offer;
transient private WalletService walletService;
transient private User user;
// Mutable
private Transaction takeOfferFeeTx;
private Transaction payoutTx;
private List<TransactionOutput> connectedOutputsForAllInputs;
private Coin payoutAmount;
private Transaction preparedDepositTx;
private List<TransactionOutput> outputs; // used to verify amounts with change outputs
private byte[] payoutTxSignature;
///////////////////////////////////////////////////////////////////////////////////////////
@ -63,8 +81,7 @@ public class TakerProcessModel extends ProcessModel implements Serializable {
public TakerProcessModel() {
log.trace("Created by constructor");
taker = new Taker();
offerer = new Offerer();
tradingPeer = new TradingPeer();
}
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
@ -91,7 +108,9 @@ public class TakerProcessModel extends ProcessModel implements Serializable {
arbitrationRepository,
user);
taker.onAllServicesInitialized(offer, walletService, user);
this.offer = offer;
this.walletService = walletService;
this.user = user;
}
@ -118,13 +137,95 @@ public class TakerProcessModel extends ProcessModel implements Serializable {
}
@Override
public String toString() {
return "TakerProcessModel{" +
"taker=" + taker +
", offerer=" + offerer +
", takeOfferFeeTx=" + takeOfferFeeTx +
", payoutTx=" + payoutTx +
'}';
///////////////////////////////////////////////////////////////////////////////////////////
// Getter only
///////////////////////////////////////////////////////////////////////////////////////////
public FiatAccount getFiatAccount() {
return user.getFiatAccount(offer.getBankAccountId());
}
public DeterministicKey getRegistrationKeyPair() {
return walletService.getRegistrationAddressEntry().getKeyPair();
}
public String getAccountId() {
return user.getAccountId();
}
public PublicKey getP2pSigPubKey() {
return user.getP2PSigPubKey();
}
public PublicKey getP2pEncryptPublicKey() {
return user.getP2PEncryptPubKey();
}
public byte[] getRegistrationPubKey() {
return walletService.getRegistrationAddressEntry().getPubKey();
}
public AddressEntry getAddressEntry() {
return walletService.getAddressEntry(offer.getId());
}
public byte[] getTradeWalletPubKey() {
return getAddressEntry().getPubKey();
}
public PublicKey getP2pEncryptPubKey() {
return user.getP2PEncryptPubKey();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Getter/Setter for Mutable objects
///////////////////////////////////////////////////////////////////////////////////////////
@Nullable
public List<TransactionOutput> getConnectedOutputsForAllInputs() {
return connectedOutputsForAllInputs;
}
public void setConnectedOutputsForAllInputs(List<TransactionOutput> connectedOutputsForAllInputs) {
this.connectedOutputsForAllInputs = connectedOutputsForAllInputs;
}
@Nullable
public Coin getPayoutAmount() {
return payoutAmount;
}
public void setPayoutAmount(Coin payoutAmount) {
this.payoutAmount = payoutAmount;
}
@Nullable
public Transaction getPreparedDepositTx() {
return preparedDepositTx;
}
public void setPreparedDepositTx(Transaction preparedDepositTx) {
this.preparedDepositTx = preparedDepositTx;
}
@Nullable
public List<TransactionOutput> getOutputs() {
return outputs;
}
public void setOutputs(List<TransactionOutput> outputs) {
this.outputs = outputs;
}
@Nullable
public byte[] getPayoutTxSignature() {
return payoutTxSignature;
}
public void setPayoutTxSignature(byte[] payoutTxSignature) {
this.payoutTxSignature = payoutTxSignature;
}
}

View File

@ -40,11 +40,11 @@ import org.slf4j.LoggerFactory;
/**
* Fully serializable, no transient fields
*/
public class Offerer implements Serializable {
public class TradingPeer implements Serializable {
// That object is saved to disc. We need to take care of changes to not break deserialization.
private static final long serialVersionUID = 1L;
transient private static final Logger log = LoggerFactory.getLogger(Offerer.class);
transient private static final Logger log = LoggerFactory.getLogger(TradingPeer.class);
// Mutable
private byte[] tradeWalletPubKey;
@ -66,7 +66,7 @@ public class Offerer implements Serializable {
// Constructor, initialization
///////////////////////////////////////////////////////////////////////////////////////////
public Offerer() {
public TradingPeer() {
log.trace("Created by constructor");
}