Refactor models for offerer

This commit is contained in:
Manfred Karrer 2015-03-17 22:35:53 +01:00
parent afd52b5948
commit 9b50dc40e5
18 changed files with 178 additions and 246 deletions

View file

@ -415,8 +415,6 @@ public class TradeWalletService {
verifyTransaction(payoutTx); verifyTransaction(payoutTx);
checkWalletConsistency(); checkWalletConsistency();
checkScriptSig(payoutTx, input, 0);
input.verify(input.getConnectedOutput());
printTxWithInputs("payoutTx", payoutTx); printTxWithInputs("payoutTx", payoutTx);
ListenableFuture<Transaction> broadcastComplete = walletAppKit.peerGroup().broadcastTransaction(payoutTx); ListenableFuture<Transaction> broadcastComplete = walletAppKit.peerGroup().broadcastTransaction(payoutTx);

View file

@ -125,9 +125,9 @@ public class TradeManager {
for (Map.Entry<String, Offer> entry : openOffers.entrySet()) { for (Map.Entry<String, Offer> entry : openOffers.entrySet()) {
createBuyerAcceptsOfferProtocol(entry.getValue()); createBuyerAcceptsOfferProtocol(entry.getValue());
} }
/* for (Map.Entry<String, Trade> entry : pendingTrades.entrySet()) { for (Map.Entry<String, Trade> entry : pendingTrades.entrySet()) {
createBuyerAcceptsOfferProtocol(entry.getValue().getOffer()); createBuyerAcceptsOfferProtocol(entry.getValue().getOffer());
}*/ }
} }
@ -251,7 +251,8 @@ public class TradeManager {
walletService, walletService,
blockChainService, blockChainService,
signatureService, signatureService,
user); user,
persistence);
SellerAsTakerProtocol sellerTakesOfferProtocol = new SellerAsTakerProtocol(model); SellerAsTakerProtocol sellerTakesOfferProtocol = new SellerAsTakerProtocol(model);
sellerAsTakerProtocolMap.put(trade.getId(), sellerTakesOfferProtocol); sellerAsTakerProtocolMap.put(trade.getId(), sellerTakesOfferProtocol);
@ -359,13 +360,7 @@ public class TradeManager {
} }
private void createBuyerAcceptsOfferProtocol(Offer offer) { private void createBuyerAcceptsOfferProtocol(Offer offer) {
BuyerAsOffererModel model = new BuyerAsOffererModel(
offer,
tradeMessageService,
walletService,
blockChainService,
signatureService,
user);
Trade trade; Trade trade;
if (pendingTrades.containsKey(offer.getId())) { if (pendingTrades.containsKey(offer.getId())) {
@ -377,7 +372,15 @@ public class TradeManager {
pendingTrades.put(trade.getId(), trade); pendingTrades.put(trade.getId(), trade);
persistPendingTrades(); persistPendingTrades();
} }
model.setTrade(trade);
BuyerAsOffererModel model = new BuyerAsOffererModel(
trade,
tradeMessageService,
walletService,
blockChainService,
signatureService,
user,
persistence);
currentPendingTrade = trade; currentPendingTrade = trade;
// TODO check, remove listener // TODO check, remove listener

View file

@ -17,16 +17,17 @@
package io.bitsquare.trade.protocol.trade; package io.bitsquare.trade.protocol.trade;
import io.bitsquare.fiat.FiatAccount;
import io.bitsquare.btc.AddressEntry; import io.bitsquare.btc.AddressEntry;
import io.bitsquare.btc.BlockChainService; import io.bitsquare.btc.BlockChainService;
import io.bitsquare.btc.TradeWalletService; import io.bitsquare.btc.TradeWalletService;
import io.bitsquare.btc.WalletService; import io.bitsquare.btc.WalletService;
import io.bitsquare.common.taskrunner.SharedModel;
import io.bitsquare.crypto.SignatureService; import io.bitsquare.crypto.SignatureService;
import io.bitsquare.fiat.FiatAccount;
import io.bitsquare.offer.Offer; import io.bitsquare.offer.Offer;
import io.bitsquare.persistence.Persistence;
import io.bitsquare.trade.TradeMessageService; import io.bitsquare.trade.TradeMessageService;
import io.bitsquare.user.User; import io.bitsquare.user.User;
import io.bitsquare.common.taskrunner.SharedModel;
import org.bitcoinj.crypto.DeterministicKey; import org.bitcoinj.crypto.DeterministicKey;
@ -44,6 +45,7 @@ public class OfferSharedModel extends SharedModel {
private final WalletService walletService; private final WalletService walletService;
private final BlockChainService blockChainService; private final BlockChainService blockChainService;
private final SignatureService signatureService; private final SignatureService signatureService;
private Persistence persistence;
// derived // derived
@ -66,12 +68,14 @@ public class OfferSharedModel extends SharedModel {
WalletService walletService, WalletService walletService,
BlockChainService blockChainService, BlockChainService blockChainService,
SignatureService signatureService, SignatureService signatureService,
User user) { User user,
Persistence persistence) {
this.offer = offer; this.offer = offer;
this.tradeMessageService = tradeMessageService; this.tradeMessageService = tradeMessageService;
this.walletService = walletService; this.walletService = walletService;
this.blockChainService = blockChainService; this.blockChainService = blockChainService;
this.signatureService = signatureService; this.signatureService = signatureService;
this.persistence = persistence;
id = offer.getId(); id = offer.getId();
tradeWalletService = walletService.getTradeWalletService(); tradeWalletService = walletService.getTradeWalletService();
@ -85,8 +89,12 @@ public class OfferSharedModel extends SharedModel {
networkPubKey = user.getNetworkPubKey(); networkPubKey = user.getNetworkPubKey();
} }
// getter/setter //setter
public void setTradeMessage(TradeMessage tradeMessage) {
this.tradeMessage = tradeMessage;
}
// getter
public String getId() { public String getId() {
return id; return id;
} }
@ -99,10 +107,6 @@ public class OfferSharedModel extends SharedModel {
return tradeMessage; return tradeMessage;
} }
public void setTradeMessage(TradeMessage tradeMessage) {
this.tradeMessage = tradeMessage;
}
public Offer getOffer() { public Offer getOffer() {
return offer; return offer;
} }

View file

@ -0,0 +1,44 @@
/*
* 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;
import io.bitsquare.fiat.FiatAccount;
import io.bitsquare.network.Peer;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionOutput;
import java.security.PublicKey;
import java.util.List;
public class TakerModel {
public Peer peer;
public String accountId;
public FiatAccount fiatAccount;
public PublicKey messagePublicKey;
public String contractAsJson;
public Coin payoutAmount;
public Transaction depositTx;
public List<TransactionOutput> connectedOutputsForAllInputs;
public List<TransactionOutput> outputs;
public String payoutAddress;
public byte[] pubKey;
}

View file

@ -20,22 +20,14 @@ package io.bitsquare.trade.protocol.trade.offerer;
import io.bitsquare.btc.BlockChainService; import io.bitsquare.btc.BlockChainService;
import io.bitsquare.btc.WalletService; import io.bitsquare.btc.WalletService;
import io.bitsquare.crypto.SignatureService; import io.bitsquare.crypto.SignatureService;
import io.bitsquare.fiat.FiatAccount; import io.bitsquare.persistence.Persistence;
import io.bitsquare.network.Peer;
import io.bitsquare.offer.Offer;
import io.bitsquare.trade.Trade; import io.bitsquare.trade.Trade;
import io.bitsquare.trade.TradeMessageService; import io.bitsquare.trade.TradeMessageService;
import io.bitsquare.trade.protocol.trade.OfferSharedModel; import io.bitsquare.trade.protocol.trade.OfferSharedModel;
import io.bitsquare.trade.protocol.trade.TakerModel;
import io.bitsquare.user.User; import io.bitsquare.user.User;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.Transaction; import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionOutput;
import java.security.PublicKey;
import java.util.List;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -44,72 +36,55 @@ public class BuyerAsOffererModel extends OfferSharedModel {
private static final Logger log = LoggerFactory.getLogger(BuyerAsOffererModel.class); private static final Logger log = LoggerFactory.getLogger(BuyerAsOffererModel.class);
// derived
private final byte[] offererPubKey;
// data written/read by tasks private final Trade trade;
private Trade trade;
private Peer taker;
public final TakerModel taker;
public final OffererModel offerer;
private String takerAccountId;
private FiatAccount takerFiatAccount;
private PublicKey takerMessagePublicKey;
private String takerContractAsJson;
private Coin takerPayoutAmount;
private String takeOfferFeeTxId;
private ECKey.ECDSASignature offererSignature;
private Coin offererPayoutAmount;
private List<TransactionOutput> offererConnectedOutputsForAllInputs;
private List<TransactionOutput> offererOutputs;
private Transaction takerDepositTx;
private List<TransactionOutput> takerConnectedOutputsForAllInputs;
private List<TransactionOutput> takerOutputs;
private String takerPayoutAddress;
private Transaction offererPayoutTx;
private Transaction publishedDepositTx; private Transaction publishedDepositTx;
private byte[] takerPubKey; private String takeOfferFeeTxId;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Constructor // Constructor
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public BuyerAsOffererModel(Offer offer, public BuyerAsOffererModel(Trade trade,
TradeMessageService tradeMessageService, TradeMessageService tradeMessageService,
WalletService walletService, WalletService walletService,
BlockChainService blockChainService, BlockChainService blockChainService,
SignatureService signatureService, SignatureService signatureService,
User user) { User user,
super(offer, Persistence persistence) {
super(trade.getOffer(),
tradeMessageService, tradeMessageService,
walletService, walletService,
blockChainService, blockChainService,
signatureService, signatureService,
user); user,
persistence);
offererPubKey = getAddressEntry().getPubKey(); this.trade = trade;
taker = new TakerModel();
offerer = new OffererModel();
offerer.pubKey = getAddressEntry().getPubKey();
} }
//getter/setter public Trade getTrade() {
public List<TransactionOutput> getOffererConnectedOutputsForAllInputs() { return trade;
return offererConnectedOutputsForAllInputs;
} }
public void setOffererConnectedOutputsForAllInputs(List<TransactionOutput> offererConnectedOutputsForAllInputs) { public Transaction getPublishedDepositTx() {
this.offererConnectedOutputsForAllInputs = offererConnectedOutputsForAllInputs; return publishedDepositTx;
} }
public List<TransactionOutput> getOffererOutputs() { public void setPublishedDepositTx(Transaction publishedDepositTx) {
return offererOutputs; this.publishedDepositTx = publishedDepositTx;
}
public void setOffererOutputs(List<TransactionOutput> offererOutputs) {
this.offererOutputs = offererOutputs;
}
public Peer getTaker() {
return taker;
} }
public String getTakeOfferFeeTxId() { public String getTakeOfferFeeTxId() {
@ -119,132 +94,4 @@ public class BuyerAsOffererModel extends OfferSharedModel {
public void setTakeOfferFeeTxId(String takeOfferFeeTxId) { public void setTakeOfferFeeTxId(String takeOfferFeeTxId) {
this.takeOfferFeeTxId = takeOfferFeeTxId; this.takeOfferFeeTxId = takeOfferFeeTxId;
} }
public String getTakerAccountId() {
return takerAccountId;
}
public void setTakerAccountId(String takerAccountId) {
this.takerAccountId = takerAccountId;
}
public FiatAccount getTakerFiatAccount() {
return takerFiatAccount;
}
public void setTakerFiatAccount(FiatAccount takerFiatAccount) {
this.takerFiatAccount = takerFiatAccount;
}
public PublicKey getTakerMessagePublicKey() {
return takerMessagePublicKey;
}
public void setTakerMessagePublicKey(PublicKey takerMessagePublicKey) {
this.takerMessagePublicKey = takerMessagePublicKey;
}
public String getTakerContractAsJson() {
return takerContractAsJson;
}
public void setTakerContractAsJson(String takerContractAsJson) {
this.takerContractAsJson = takerContractAsJson;
}
public byte[] getOffererPubKey() {
return offererPubKey;
}
public ECKey.ECDSASignature getOffererSignature() {
return offererSignature;
}
public void setOffererSignature(ECKey.ECDSASignature offererSignature) {
this.offererSignature = offererSignature;
}
public Coin getOffererPayoutAmount() {
return offererPayoutAmount;
}
public void setOffererPayoutAmount(Coin offererPayoutAmount) {
this.offererPayoutAmount = offererPayoutAmount;
}
public Coin getTakerPayoutAmount() {
return takerPayoutAmount;
}
public void setTakerPayoutAmount(Coin takerPayoutAmount) {
this.takerPayoutAmount = takerPayoutAmount;
}
public void setTrade(Trade trade) {
this.trade = trade;
}
public Trade getTrade() {
return trade;
}
public void setTaker(Peer taker) {
this.taker = taker;
}
public void setTakerDepositTx(Transaction takerDepositTx) {
this.takerDepositTx = takerDepositTx;
}
public Transaction getTakerDepositTx() {
return takerDepositTx;
}
public void setTakerConnectedOutputsForAllInputs(List<TransactionOutput> takerConnectedOutputsForAllInputs) {
this.takerConnectedOutputsForAllInputs = takerConnectedOutputsForAllInputs;
}
public List<TransactionOutput> getTakerConnectedOutputsForAllInputs() {
return takerConnectedOutputsForAllInputs;
}
public void setTakerOutputs(List<TransactionOutput> takerOutputs) {
this.takerOutputs = takerOutputs;
}
public List<TransactionOutput> getTakerOutputs() {
return takerOutputs;
}
public String getTakerPayoutAddress() {
return takerPayoutAddress;
}
public void setTakerPayoutAddress(String takerPayoutAddress) {
this.takerPayoutAddress = takerPayoutAddress;
}
public void setOffererPayoutTx(Transaction offererPayoutTx) {
this.offererPayoutTx = offererPayoutTx;
}
public Transaction getOffererPayoutTx() {
return offererPayoutTx;
}
public void setPublishedDepositTx(Transaction publishedDepositTx) {
this.publishedDepositTx = publishedDepositTx;
}
public Transaction getPublishedDepositTx() {
return publishedDepositTx;
}
public byte[] getTakerPubKey() {
return takerPubKey;
}
public void setTakerPubKey(byte[] takerPubKey) {
this.takerPubKey = takerPubKey;
}
} }

View file

@ -82,7 +82,7 @@ public class BuyerAsOffererProtocol {
private void handleRequestDepositTxInputsMessage(RequestDepositTxInputsMessage tradeMessage, Peer taker) { private void handleRequestDepositTxInputsMessage(RequestDepositTxInputsMessage tradeMessage, Peer taker) {
model.setTradeMessage(tradeMessage); model.setTradeMessage(tradeMessage);
model.setTaker(taker); model.taker.peer = taker;
BuyerAsOffererTaskRunner<BuyerAsOffererModel> taskRunner = new BuyerAsOffererTaskRunner<>(model, BuyerAsOffererTaskRunner<BuyerAsOffererModel> taskRunner = new BuyerAsOffererTaskRunner<>(model,
() -> { () -> {

View file

@ -0,0 +1,34 @@
/*
* 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;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionOutput;
import java.util.List;
public class OffererModel {
public byte[] pubKey;
public ECKey.ECDSASignature payoutSignature;
public Coin payoutAmount;
public List<TransactionOutput> connectedOutputsForAllInputs;
public List<TransactionOutput> outputs;
public Transaction payoutTx;
}

View file

@ -20,9 +20,9 @@ package io.bitsquare.trade.protocol.trade.offerer.tasks;
import io.bitsquare.btc.AddressEntry; import io.bitsquare.btc.AddressEntry;
import io.bitsquare.btc.FeePolicy; import io.bitsquare.btc.FeePolicy;
import io.bitsquare.btc.TradeWalletService; import io.bitsquare.btc.TradeWalletService;
import io.bitsquare.trade.protocol.trade.offerer.BuyerAsOffererModel;
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.protocol.trade.offerer.BuyerAsOffererModel;
import org.bitcoinj.core.Coin; import org.bitcoinj.core.Coin;
@ -43,8 +43,8 @@ public class GetOffererDepositTxInputs extends Task<BuyerAsOffererModel> {
AddressEntry addressInfo = model.getAddressEntry(); AddressEntry addressInfo = model.getAddressEntry();
TradeWalletService.TransactionDataResult result = model.getTradeWalletService().offererCreatesDepositTxInputs(offererInputAmount, addressInfo); TradeWalletService.TransactionDataResult result = model.getTradeWalletService().offererCreatesDepositTxInputs(offererInputAmount, addressInfo);
model.setOffererConnectedOutputsForAllInputs(result.getConnectedOutputsForAllInputs()); model.offerer.connectedOutputsForAllInputs = result.getConnectedOutputsForAllInputs();
model.setOffererOutputs(result.getOutputs()); model.offerer.outputs = result.getOutputs();
complete(); complete();
} catch (Throwable e) { } catch (Throwable e) {

View file

@ -44,7 +44,7 @@ public class ProcessRequestDepositTxInputsMessage extends Task<BuyerAsOffererMod
RequestDepositTxInputsMessage requestDepositTxInputsMessage = (RequestDepositTxInputsMessage) model.getTradeMessage(); RequestDepositTxInputsMessage requestDepositTxInputsMessage = (RequestDepositTxInputsMessage) model.getTradeMessage();
trade.setTradeAmount(positiveCoinOf(nonZeroCoinOf(requestDepositTxInputsMessage.getTradeAmount()))); trade.setTradeAmount(positiveCoinOf(nonZeroCoinOf(requestDepositTxInputsMessage.getTradeAmount())));
model.setTakeOfferFeeTxId(nonEmptyStringOf(requestDepositTxInputsMessage.getTakeOfferFeeTxId())); model.setTakeOfferFeeTxId(nonEmptyStringOf(requestDepositTxInputsMessage.getTakeOfferFeeTxId()));
model.setTakerPubKey(checkNotNull(requestDepositTxInputsMessage.getTakerPubKey())); model.taker.pubKey = checkNotNull(requestDepositTxInputsMessage.getTakerPubKey());
complete(); complete();
} catch (Throwable t) { } catch (Throwable t) {

View file

@ -17,10 +17,10 @@
package io.bitsquare.trade.protocol.trade.offerer.tasks; package io.bitsquare.trade.protocol.trade.offerer.tasks;
import io.bitsquare.trade.protocol.trade.offerer.BuyerAsOffererModel;
import io.bitsquare.trade.protocol.trade.taker.messages.RequestOffererPublishDepositTxMessage;
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.protocol.trade.offerer.BuyerAsOffererModel;
import io.bitsquare.trade.protocol.trade.taker.messages.RequestOffererPublishDepositTxMessage;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -41,15 +41,15 @@ public class ProcessRequestOffererPublishDepositTxMessage extends Task<BuyerAsOf
checkTradeId(model.getId(), model.getTradeMessage()); checkTradeId(model.getId(), model.getTradeMessage());
RequestOffererPublishDepositTxMessage message = (RequestOffererPublishDepositTxMessage) model.getTradeMessage(); RequestOffererPublishDepositTxMessage message = (RequestOffererPublishDepositTxMessage) model.getTradeMessage();
model.setTakerFiatAccount(checkNotNull(message.getTakerBankAccount())); model.taker.fiatAccount = checkNotNull(message.getTakerBankAccount());
model.setTakerAccountId(nonEmptyStringOf(message.getTakerAccountId())); model.taker.accountId = nonEmptyStringOf(message.getTakerAccountId());
model.setTakerMessagePublicKey(checkNotNull(message.getTakerMessagePublicKey())); model.taker.messagePublicKey = checkNotNull(message.getTakerMessagePublicKey());
model.setTakerContractAsJson(nonEmptyStringOf(message.getTakerContractAsJson())); model.taker.contractAsJson = nonEmptyStringOf(message.getTakerContractAsJson());
model.setTakerPayoutAddress(nonEmptyStringOf(message.getTakerPayoutAddress())); model.taker.payoutAddress = nonEmptyStringOf(message.getTakerPayoutAddress());
model.setTakerDepositTx(checkNotNull(message.getTakersDepositTx())); model.taker.depositTx = checkNotNull(message.getTakersDepositTx());
model.setTakerConnectedOutputsForAllInputs(checkNotNull(message.getTakerConnectedOutputsForAllInputs())); model.taker.connectedOutputsForAllInputs = checkNotNull(message.getTakerConnectedOutputsForAllInputs());
checkArgument(message.getTakerConnectedOutputsForAllInputs().size() > 0); checkArgument(message.getTakerConnectedOutputsForAllInputs().size() > 0);
model.setTakerOutputs(checkNotNull(message.getTakerOutputs())); model.taker.outputs = checkNotNull(message.getTakerOutputs());
complete(); complete();
} catch (Throwable t) { } catch (Throwable t) {

View file

@ -35,16 +35,15 @@ public class RequestDepositPayment extends Task<BuyerAsOffererModel> {
@Override @Override
protected void doRun() { protected void doRun() {
model.getOffererPubKey();
RequestDepositPaymentMessage tradeMessage = new RequestDepositPaymentMessage( RequestDepositPaymentMessage tradeMessage = new RequestDepositPaymentMessage(
model.getId(), model.getId(),
model.getOffererConnectedOutputsForAllInputs(), model.offerer.connectedOutputsForAllInputs,
model.getOffererOutputs(), model.offerer.outputs,
model.getOffererPubKey(), model.offerer.pubKey,
model.getFiatAccount(), model.getFiatAccount(),
model.getAccountId()); model.getAccountId());
model.getTradeMessageService().sendMessage(model.getTaker(), tradeMessage, new SendMessageListener() { model.getTradeMessageService().sendMessage(model.taker.peer, tradeMessage, new SendMessageListener() {
@Override @Override
public void handleResult() { public void handleResult() {
log.trace("RequestTakerDepositPaymentMessage successfully arrived at peer"); log.trace("RequestTakerDepositPaymentMessage successfully arrived at peer");

View file

@ -38,11 +38,11 @@ public class SendBankTransferStartedMessage extends Task<BuyerAsOffererModel> {
BankTransferStartedMessage tradeMessage = new BankTransferStartedMessage( BankTransferStartedMessage tradeMessage = new BankTransferStartedMessage(
model.getId(), model.getId(),
model.getPublishedDepositTx(), model.getPublishedDepositTx(),
model.getOffererSignature().encodeToDER(), model.offerer.payoutSignature.encodeToDER(),
model.getOffererPayoutAmount(), model.offerer.payoutAmount,
model.getTakerPayoutAmount(), model.taker.payoutAmount,
model.getAddressEntry().getAddressString()); model.getAddressEntry().getAddressString());
model.getTradeMessageService().sendMessage(model.getTaker(), tradeMessage, new SendMessageListener() { model.getTradeMessageService().sendMessage(model.taker.peer, tradeMessage, new SendMessageListener() {
@Override @Override
public void handleResult() { public void handleResult() {
log.trace("Sending BankTransferInitedMessage succeeded."); log.trace("Sending BankTransferInitedMessage succeeded.");

View file

@ -37,7 +37,7 @@ public class SendDepositTxIdToTaker extends Task<BuyerAsOffererModel> {
protected void doRun() { protected void doRun() {
DepositTxPublishedMessage tradeMessage = new DepositTxPublishedMessage(model.getId(), model.getTrade().getDepositTx()); DepositTxPublishedMessage tradeMessage = new DepositTxPublishedMessage(model.getId(), model.getTrade().getDepositTx());
model.getTradeMessageService().sendMessage(model.getTaker(), tradeMessage, new SendMessageListener() { model.getTradeMessageService().sendMessage(model.taker.peer, tradeMessage, new SendMessageListener() {
@Override @Override
public void handleResult() { public void handleResult() {
log.trace("DepositTxPublishedMessage successfully arrived at peer"); log.trace("DepositTxPublishedMessage successfully arrived at peer");

View file

@ -45,13 +45,13 @@ public class SignAndPublishDepositTx extends Task<BuyerAsOffererModel> {
try { try {
Coin offererInputAmount = model.getTrade().getSecurityDeposit().add(FeePolicy.TX_FEE); Coin offererInputAmount = model.getTrade().getSecurityDeposit().add(FeePolicy.TX_FEE);
model.getTradeWalletService().offererSignsAndPublishTx( model.getTradeWalletService().offererSignsAndPublishTx(
model.getTakerDepositTx(), model.taker.depositTx,
model.getOffererConnectedOutputsForAllInputs(), model.offerer.connectedOutputsForAllInputs,
model.getTakerConnectedOutputsForAllInputs(), model.taker.connectedOutputsForAllInputs,
model.getOffererOutputs(), model.offerer.outputs,
offererInputAmount, offererInputAmount,
model.getOffererPubKey(), model.offerer.pubKey,
model.getTakerPubKey(), model.taker.pubKey,
model.getArbitratorPubKey(), model.getArbitratorPubKey(),
new FutureCallback<Transaction>() { new FutureCallback<Transaction>() {
@Override @Override

View file

@ -47,16 +47,16 @@ public class SignPayoutTx extends Task<BuyerAsOffererModel> {
trade.getDepositTx(), trade.getDepositTx(),
offererPayoutAmount, offererPayoutAmount,
takerPayoutAmount, takerPayoutAmount,
model.getTakerPayoutAddress(), model.taker.payoutAddress,
model.getWalletService().getAddressEntry(trade.getId()), model.getWalletService().getAddressEntry(trade.getId()),
model.getOffererPubKey(), model.offerer.pubKey,
model.getTakerPubKey(), model.taker.pubKey,
model.getArbitratorPubKey()); model.getArbitratorPubKey());
model.setOffererPayoutTx(result.getPayoutTx()); model.offerer.payoutTx = result.getPayoutTx();
model.setOffererSignature(result.getOffererSignature()); model.offerer.payoutSignature = result.getOffererSignature();
model.setOffererPayoutAmount(offererPayoutAmount); model.offerer.payoutAmount = offererPayoutAmount;
model.setTakerPayoutAmount(takerPayoutAmount); model.taker.payoutAmount = takerPayoutAmount;
complete(); complete();
} catch (Exception e) { } catch (Exception e) {

View file

@ -43,11 +43,11 @@ public class VerifyAndSignContract extends Task<BuyerAsOffererModel> {
trade.getTradeAmount(), trade.getTradeAmount(),
model.getTakeOfferFeeTxId(), model.getTakeOfferFeeTxId(),
model.getAccountId(), model.getAccountId(),
model.getTakerAccountId(), model.taker.accountId,
model.getFiatAccount(), model.getFiatAccount(),
model.getTakerFiatAccount(), model.taker.fiatAccount,
model.getNetworkPubKey(), model.getNetworkPubKey(),
model.getTakerMessagePublicKey()); model.taker.messagePublicKey);
String contractAsJson = Utilities.objectToJson(contract); String contractAsJson = Utilities.objectToJson(contract);
String signature = model.getSignatureService().signMessage(model.getRegistrationKeyPair(), contractAsJson); String signature = model.getSignatureService().signMessage(model.getRegistrationKeyPair(), contractAsJson);

View file

@ -17,9 +17,9 @@
package io.bitsquare.trade.protocol.trade.offerer.tasks; package io.bitsquare.trade.protocol.trade.offerer.tasks;
import io.bitsquare.trade.protocol.trade.offerer.BuyerAsOffererModel;
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.protocol.trade.offerer.BuyerAsOffererModel;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -35,7 +35,7 @@ public class VerifyTakerAccount extends Task<BuyerAsOffererModel> {
protected void doRun() { protected void doRun() {
//TODO mocked yet //TODO mocked yet
if (model.getBlockChainService().verifyAccountRegistration()) { if (model.getBlockChainService().verifyAccountRegistration()) {
if (model.getBlockChainService().isAccountBlackListed(model.getTakerAccountId(), model.getTakerFiatAccount())) { if (model.getBlockChainService().isAccountBlackListed(model.taker.accountId, model.taker.fiatAccount)) {
log.error("Taker is blacklisted"); log.error("Taker is blacklisted");
failed("Taker is blacklisted"); failed("Taker is blacklisted");
} }

View file

@ -17,11 +17,12 @@
package io.bitsquare.trade.protocol.trade.taker; package io.bitsquare.trade.protocol.trade.taker;
import io.bitsquare.fiat.FiatAccount;
import io.bitsquare.btc.BlockChainService; import io.bitsquare.btc.BlockChainService;
import io.bitsquare.btc.WalletService; import io.bitsquare.btc.WalletService;
import io.bitsquare.crypto.SignatureService; import io.bitsquare.crypto.SignatureService;
import io.bitsquare.fiat.FiatAccount;
import io.bitsquare.network.Peer; import io.bitsquare.network.Peer;
import io.bitsquare.persistence.Persistence;
import io.bitsquare.trade.Trade; import io.bitsquare.trade.Trade;
import io.bitsquare.trade.TradeMessageService; import io.bitsquare.trade.TradeMessageService;
import io.bitsquare.trade.protocol.trade.OfferSharedModel; import io.bitsquare.trade.protocol.trade.OfferSharedModel;
@ -71,13 +72,15 @@ public class SellerAsTakerModel extends OfferSharedModel {
WalletService walletService, WalletService walletService,
BlockChainService blockChainService, BlockChainService blockChainService,
SignatureService signatureService, SignatureService signatureService,
User user) { User user,
Persistence persistence) {
super(trade.getOffer(), super(trade.getOffer(),
tradeMessageService, tradeMessageService,
walletService, walletService,
blockChainService, blockChainService,
signatureService, signatureService,
user); user,
persistence);
this.trade = trade; this.trade = trade;
this.offerer = offerer; this.offerer = offerer;