refactor packages and rename protocol class for trade process, comments

This commit is contained in:
Manfred Karrer 2014-08-26 21:05:40 +02:00
parent c455ae176b
commit d3d23cc459
53 changed files with 136 additions and 573 deletions

View file

@ -27,7 +27,7 @@ import io.bitsquare.gui.util.BSFormatter;
import io.bitsquare.gui.util.ImageUtil; import io.bitsquare.gui.util.ImageUtil;
import io.bitsquare.gui.util.Profiler; import io.bitsquare.gui.util.Profiler;
import io.bitsquare.gui.util.Transitions; import io.bitsquare.gui.util.Transitions;
import io.bitsquare.msg.BootstrapListener; import io.bitsquare.msg.listeners.BootstrapListener;
import io.bitsquare.msg.MessageFacade; import io.bitsquare.msg.MessageFacade;
import io.bitsquare.storage.Persistence; import io.bitsquare.storage.Persistence;
import io.bitsquare.trade.TradeManager; import io.bitsquare.trade.TradeManager;

View file

@ -29,8 +29,8 @@ import io.bitsquare.gui.util.BitSquareValidator;
import io.bitsquare.trade.Offer; import io.bitsquare.trade.Offer;
import io.bitsquare.trade.Trade; import io.bitsquare.trade.Trade;
import io.bitsquare.trade.TradeManager; import io.bitsquare.trade.TradeManager;
import io.bitsquare.trade.protocol.taker.ProtocolForTakerAsSeller; import io.bitsquare.trade.protocol.trade.taker.SellerTakesOfferProtocol;
import io.bitsquare.trade.protocol.taker.ProtocolForTakerAsSellerListener; import io.bitsquare.trade.protocol.trade.taker.SellerTakesOfferProtocolListener;
import com.google.bitcoin.core.Coin; import com.google.bitcoin.core.Coin;
@ -173,7 +173,7 @@ public class TakerOfferController extends CachedViewController {
else { else {
takeOfferButton.setDisable(true); takeOfferButton.setDisable(true);
amountTextField.setEditable(false); amountTextField.setEditable(false);
tradeManager.takeOffer(amount, offer, new ProtocolForTakerAsSellerListener() { tradeManager.takeOffer(amount, offer, new SellerTakesOfferProtocolListener() {
@Override @Override
public void onDepositTxPublished(String depositTxId) { public void onDepositTxPublished(String depositTxId) {
setDepositTxId(depositTxId); setDepositTxId(depositTxId);
@ -207,19 +207,19 @@ public class TakerOfferController extends CachedViewController {
} }
@Override @Override
public void onFault(Throwable throwable, ProtocolForTakerAsSeller.State state) { public void onFault(Throwable throwable, SellerTakesOfferProtocol.State state) {
log.error("Error while executing trade process at state: " + state + " / " + throwable); log.error("Error while executing trade process at state: " + state + " / " + throwable);
Popups.openErrorPopup("Error while executing trade process", Popups.openErrorPopup("Error while executing trade process",
"Error while executing trade process at state: " + state + " / " + throwable); "Error while executing trade process at state: " + state + " / " + throwable);
} }
@Override @Override
public void onWaitingForPeerResponse(ProtocolForTakerAsSeller.State state) { public void onWaitingForPeerResponse(SellerTakesOfferProtocol.State state) {
log.debug("Waiting for peers response at state " + state); log.debug("Waiting for peers response at state " + state);
} }
@Override @Override
public void onCompleted(ProtocolForTakerAsSeller.State state) { public void onCompleted(SellerTakesOfferProtocol.State state) {
log.debug("Trade protocol completed at state " + state); log.debug("Trade protocol completed at state " + state);
} }

View file

@ -146,7 +146,6 @@ public class BitSquareValidator {
public static boolean validateStringAsDouble(String input) { public static boolean validateStringAsDouble(String input) {
try { try {
input = input.replace(",", "."); input = input.replace(",", ".");
//noinspection ResultOfMethodCallIgnored
Double.parseDouble(input); Double.parseDouble(input);
return true; return true;
} catch (NumberFormatException | NullPointerException e) { } catch (NumberFormatException | NullPointerException e) {

View file

@ -55,7 +55,6 @@ public abstract class NumberValidator {
protected ValidationResult validateIfNumber(String input) { protected ValidationResult validateIfNumber(String input) {
try { try {
//noinspection ResultOfMethodCallIgnored
Double.parseDouble(input); Double.parseDouble(input);
return new ValidationResult(true); return new ValidationResult(true);
} catch (Exception e) { } catch (Exception e) {

View file

@ -19,6 +19,9 @@ package io.bitsquare.msg;
import net.tomp2p.peers.PeerAddress; import net.tomp2p.peers.PeerAddress;
/**
* Interface for the object handling incoming messages.
*/
public interface MessageBroker { public interface MessageBroker {
void handleMessage(Object message, PeerAddress peerAddress); void handleMessage(Object message, PeerAddress peerAddress);
} }

View file

@ -18,6 +18,7 @@
package io.bitsquare.msg; package io.bitsquare.msg;
import io.bitsquare.msg.listeners.ArbitratorListener; import io.bitsquare.msg.listeners.ArbitratorListener;
import io.bitsquare.msg.listeners.BootstrapListener;
import io.bitsquare.msg.listeners.GetPeerAddressListener; import io.bitsquare.msg.listeners.GetPeerAddressListener;
import io.bitsquare.msg.listeners.IncomingTradeMessageListener; import io.bitsquare.msg.listeners.IncomingTradeMessageListener;
import io.bitsquare.msg.listeners.OrderBookListener; import io.bitsquare.msg.listeners.OrderBookListener;

View file

@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
// TODO Might be better with a config file
public class SeedNodeAddress { public class SeedNodeAddress {
private final String id; private final String id;
private final String ip; private final String ip;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.msg; package io.bitsquare.msg.listeners;
public interface BootstrapListener { public interface BootstrapListener {
public void onCompleted(); public void onCompleted();

View file

@ -1,24 +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.msg.listeners;
public interface PingPeerListener {
void onPing();
void onPingPeerResult(boolean success);
}

View file

@ -35,7 +35,8 @@ public class Settings implements Serializable {
private List<Country> acceptedCountryLocales = new ArrayList<>(); private List<Country> acceptedCountryLocales = new ArrayList<>();
private List<Arbitrator> acceptedArbitrators = new ArrayList<>(); private List<Arbitrator> acceptedArbitrators = new ArrayList<>();
private long collateral = 100; // is 1/1000 so 100 is a multiplier of 0,1 or 10% of the amount private long collateral = 100; // is 1/1000 so 100 results to 100/1000 = 0,1 (or 10%)
// which will be used for multiplying with the amount to get the collateral size in BTC.
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -111,7 +112,6 @@ public class Settings implements Serializable {
//TODO //TODO
public Arbitrator getRandomArbitrator(Coin amount) { public Arbitrator getRandomArbitrator(Coin amount) {
List<Arbitrator> candidates = new ArrayList<>(); List<Arbitrator> candidates = new ArrayList<>();
//noinspection Convert2streamapi
for (Arbitrator arbitrator : acceptedArbitrators) { for (Arbitrator arbitrator : acceptedArbitrators) {
candidates.add(arbitrator); candidates.add(arbitrator);
} }

View file

@ -45,6 +45,8 @@ import org.slf4j.LoggerFactory;
/** /**
* Simple storage solution for serialized data * Simple storage solution for serialized data
* TODO: Should be improved with a more robust solution or maybe a lightweight database.
* TODO: Should run in a dedicated thread.
*/ */
public class Persistence { public class Persistence {
private static final Logger log = LoggerFactory.getLogger(Persistence.class); private static final Logger log = LoggerFactory.getLogger(Persistence.class);
@ -191,7 +193,6 @@ public class Persistence {
} }
else { else {
if (object instanceof Map) { if (object instanceof Map) {
//noinspection unchecked
return (Map<String, Serializable>) object; return (Map<String, Serializable>) object;
} }
else { else {

View file

@ -29,18 +29,18 @@ import io.bitsquare.trade.handlers.ErrorMessageHandler;
import io.bitsquare.trade.handlers.TransactionResultHandler; import io.bitsquare.trade.handlers.TransactionResultHandler;
import io.bitsquare.trade.protocol.TradeMessage; import io.bitsquare.trade.protocol.TradeMessage;
import io.bitsquare.trade.protocol.createoffer.CreateOfferCoordinator; import io.bitsquare.trade.protocol.createoffer.CreateOfferCoordinator;
import io.bitsquare.trade.protocol.offerer.BankTransferInitedMessage; import io.bitsquare.trade.protocol.trade.offerer.BuyerAcceptsOfferProtocol;
import io.bitsquare.trade.protocol.offerer.DepositTxPublishedMessage; import io.bitsquare.trade.protocol.trade.offerer.BuyerAcceptsOfferProtocolListener;
import io.bitsquare.trade.protocol.offerer.ProtocolForOffererAsBuyer; import io.bitsquare.trade.protocol.trade.offerer.messages.BankTransferInitedMessage;
import io.bitsquare.trade.protocol.offerer.ProtocolForOffererAsBuyerListener; import io.bitsquare.trade.protocol.trade.offerer.messages.DepositTxPublishedMessage;
import io.bitsquare.trade.protocol.offerer.RequestTakerDepositPaymentMessage; import io.bitsquare.trade.protocol.trade.offerer.messages.RequestTakerDepositPaymentMessage;
import io.bitsquare.trade.protocol.offerer.RespondToTakeOfferRequestMessage; import io.bitsquare.trade.protocol.trade.offerer.messages.RespondToTakeOfferRequestMessage;
import io.bitsquare.trade.protocol.taker.PayoutTxPublishedMessage; import io.bitsquare.trade.protocol.trade.taker.SellerTakesOfferProtocol;
import io.bitsquare.trade.protocol.taker.ProtocolForTakerAsSeller; import io.bitsquare.trade.protocol.trade.taker.SellerTakesOfferProtocolListener;
import io.bitsquare.trade.protocol.taker.ProtocolForTakerAsSellerListener; import io.bitsquare.trade.protocol.trade.taker.messages.PayoutTxPublishedMessage;
import io.bitsquare.trade.protocol.taker.RequestOffererPublishDepositTxMessage; import io.bitsquare.trade.protocol.trade.taker.messages.RequestOffererPublishDepositTxMessage;
import io.bitsquare.trade.protocol.taker.RequestTakeOfferMessage; import io.bitsquare.trade.protocol.trade.taker.messages.RequestTakeOfferMessage;
import io.bitsquare.trade.protocol.taker.TakeOfferFeePayedMessage; import io.bitsquare.trade.protocol.trade.taker.messages.TakeOfferFeePayedMessage;
import io.bitsquare.user.User; import io.bitsquare.user.User;
import com.google.bitcoin.core.Coin; import com.google.bitcoin.core.Coin;
@ -81,8 +81,8 @@ public class TradeManager {
private final List<TakeOfferRequestListener> takeOfferRequestListeners = new ArrayList<>(); private final List<TakeOfferRequestListener> takeOfferRequestListeners = new ArrayList<>();
//TODO store TakerAsSellerProtocol in trade //TODO store TakerAsSellerProtocol in trade
private final Map<String, ProtocolForTakerAsSeller> takerAsSellerProtocolMap = new HashMap<>(); private final Map<String, SellerTakesOfferProtocol> takerAsSellerProtocolMap = new HashMap<>();
private final Map<String, ProtocolForOffererAsBuyer> offererAsBuyerProtocolMap = new HashMap<>(); private final Map<String, BuyerAcceptsOfferProtocol> offererAsBuyerProtocolMap = new HashMap<>();
private final Map<String, CreateOfferCoordinator> createOfferCoordinatorMap = new HashMap<>(); private final Map<String, CreateOfferCoordinator> createOfferCoordinatorMap = new HashMap<>();
private final StringProperty newTradeProperty = new SimpleStringProperty(); private final StringProperty newTradeProperty = new SimpleStringProperty();
@ -227,14 +227,14 @@ public class TradeManager {
messageFacade.removeOffer(offer); messageFacade.removeOffer(offer);
} }
public Trade takeOffer(Coin amount, Offer offer, ProtocolForTakerAsSellerListener listener) { public Trade takeOffer(Coin amount, Offer offer, SellerTakesOfferProtocolListener listener) {
Trade trade = createTrade(offer); Trade trade = createTrade(offer);
trade.setTradeAmount(amount); trade.setTradeAmount(amount);
ProtocolForTakerAsSeller protocolForTakerAsSeller = new ProtocolForTakerAsSeller( SellerTakesOfferProtocol sellerTakesOfferProtocol = new SellerTakesOfferProtocol(
trade, listener, messageFacade, walletFacade, blockChainFacade, cryptoFacade, user); trade, listener, messageFacade, walletFacade, blockChainFacade, cryptoFacade, user);
takerAsSellerProtocolMap.put(trade.getId(), protocolForTakerAsSeller); takerAsSellerProtocolMap.put(trade.getId(), sellerTakesOfferProtocol);
protocolForTakerAsSeller.start(); sellerTakesOfferProtocol.start();
return trade; return trade;
} }
@ -284,14 +284,14 @@ public class TradeManager {
Trade trade = createTrade(offer); Trade trade = createTrade(offer);
pendingTrade = trade; pendingTrade = trade;
ProtocolForOffererAsBuyer protocolForOffererAsBuyer = new ProtocolForOffererAsBuyer(trade, BuyerAcceptsOfferProtocol buyerAcceptsOfferProtocol = new BuyerAcceptsOfferProtocol(trade,
sender, sender,
messageFacade, messageFacade,
walletFacade, walletFacade,
blockChainFacade, blockChainFacade,
cryptoFacade, cryptoFacade,
user, user,
new ProtocolForOffererAsBuyerListener() { new BuyerAcceptsOfferProtocolListener() {
@Override @Override
public void onOfferAccepted(Offer offer) { public void onOfferAccepted(Offer offer) {
removeOffer(offer); removeOffer(offer);
@ -317,7 +317,7 @@ public class TradeManager {
} }
@Override @Override
public void onFault(Throwable throwable, ProtocolForOffererAsBuyer.State state) { public void onFault(Throwable throwable, BuyerAcceptsOfferProtocol.State state) {
log.error("Error while executing trade process at state: " + state + " / " + throwable); log.error("Error while executing trade process at state: " + state + " / " + throwable);
Popups.openErrorPopup("Error while executing trade process", Popups.openErrorPopup("Error while executing trade process",
"Error while executing trade process at state: " + state + " / " + "Error while executing trade process at state: " + state + " / " +
@ -325,17 +325,17 @@ public class TradeManager {
} }
@Override @Override
public void onWaitingForPeerResponse(ProtocolForOffererAsBuyer.State state) { public void onWaitingForPeerResponse(BuyerAcceptsOfferProtocol.State state) {
log.debug("Waiting for peers response at state " + state); log.debug("Waiting for peers response at state " + state);
} }
@Override @Override
public void onCompleted(ProtocolForOffererAsBuyer.State state) { public void onCompleted(BuyerAcceptsOfferProtocol.State state) {
log.debug("Trade protocol completed at state " + state); log.debug("Trade protocol completed at state " + state);
} }
@Override @Override
public void onWaitingForUserInteraction(ProtocolForOffererAsBuyer.State state) { public void onWaitingForUserInteraction(BuyerAcceptsOfferProtocol.State state) {
log.debug("Waiting for UI activity at state " + state); log.debug("Waiting for UI activity at state " + state);
} }
@ -348,7 +348,7 @@ public class TradeManager {
}); });
if (!offererAsBuyerProtocolMap.containsKey(trade.getId())) { if (!offererAsBuyerProtocolMap.containsKey(trade.getId())) {
offererAsBuyerProtocolMap.put(trade.getId(), protocolForOffererAsBuyer); offererAsBuyerProtocolMap.put(trade.getId(), buyerAcceptsOfferProtocol);
} }
else { else {
// We don't store the protocol in case we have already a pending offer. The protocol is only // We don't store the protocol in case we have already a pending offer. The protocol is only
@ -356,7 +356,7 @@ public class TradeManager {
log.trace("offererAsBuyerProtocol not stored as offer is already pending."); log.trace("offererAsBuyerProtocol not stored as offer is already pending.");
} }
protocolForOffererAsBuyer.start(); buyerAcceptsOfferProtocol.start();
} }
else { else {
log.warn("Incoming offer take request does not match with any saved offer. We ignore that request."); log.warn("Incoming offer take request does not match with any saved offer. We ignore that request.");

View file

@ -55,6 +55,7 @@ remove dependencies to tomp2p
import net.tomp2p.peers.Number160; import net.tomp2p.peers.Number160;
import net.tomp2p.storage.Data; import net.tomp2p.storage.Data;
*/ */
public class OrderBook implements OrderBookListener { public class OrderBook implements OrderBookListener {
private static final Logger log = LoggerFactory.getLogger(OrderBook.class); private static final Logger log = LoggerFactory.getLogger(OrderBook.class);
private final ObservableList<OrderBookListItem> allOffers = FXCollections.observableArrayList(); private final ObservableList<OrderBookListItem> allOffers = FXCollections.observableArrayList();
@ -148,8 +149,6 @@ public class OrderBook implements OrderBookListener {
// (1 to n) // (1 to n)
boolean arbitratorResult = arbitratorInList(offer.getArbitrator(), settings.getAcceptedArbitrators()); boolean arbitratorResult = arbitratorInList(offer.getArbitrator(), settings.getAcceptedArbitrators());
//noinspection UnnecessaryLocalVariable
boolean result = currencyResult && countryResult && languageResult && amountResult && directionResult && boolean result = currencyResult && countryResult && languageResult && amountResult && directionResult &&
priceResult && arbitratorResult; priceResult && arbitratorResult;

View file

@ -24,6 +24,7 @@ import com.google.bitcoin.core.Coin;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
public class OrderBookFilter { public class OrderBookFilter {
// TODO use ObjectProperty<Direction> instead
private final SimpleBooleanProperty directionChangedProperty = new SimpleBooleanProperty(); private final SimpleBooleanProperty directionChangedProperty = new SimpleBooleanProperty();
private double price; private double price;
@ -65,10 +66,7 @@ public class OrderBookFilter {
this.price = price; this.price = price;
} }
public SimpleBooleanProperty getDirectionChangedProperty() { public SimpleBooleanProperty getDirectionChangedProperty() {
return directionChangedProperty; return directionChangedProperty;
} }
} }

View file

@ -1,53 +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.old;
//TODO not used but let it for reference until all use cases are impl.
class BuyOffererPaymentProcess extends PaymentProcess {
public BuyOffererPaymentProcess() {
super();
}
// case 1 offerer step 1
private void buyOfferOfferer_payToDeposit() {
onDataDepositTx();
payCollateral();
signDepositTx();
publishDepositTx();
sendMessageDepositTxPublished();
onBlockChainConfirmation();
}
// case 1 offerer step 2
private void buyOfferOfferer_payToDeposist() {
payFiat();
sendMessageFiatTxInited();
createPayoutTx();
signPayoutTx();
sendDataPayoutTx();
onBlockChainConfirmation();
}
// case 1 offerer step 3
private void buyOfferOfferer_waitForRelease() {
onMessagePayoutTxPublished();
onBlockChainConfirmation();
done();
}
}

View file

@ -1,52 +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.old;
//TODO not used but let it for reference until all use cases are impl.
public class BuyTakerPaymentProcess extends PaymentProcess {
public BuyTakerPaymentProcess() {
super();
}
@Override
public void executeStep0() {
// bitcoinServices.createMultiSig();
createDepositTx();
payPaymentAndCollateral();
signDepositTx();
sendDataDepositTx();
}
@Override
public void executeStep1() {
onMessageDepositTxPublished();
onMessageFiatTxInited();
onUserInputFiatReceived();
onDataPayoutTx();
}
@Override
public void executeStep2() {
signPayoutTx();
publishPayoutTx();
sendMessagePayoutTxPublished();
onBlockChainConfirmation();
done();
}
}

View file

@ -1,224 +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.old;
import io.bitsquare.btc.BlockChainFacade;
import io.bitsquare.btc.WalletFacade;
import io.bitsquare.msg.MessageFacade;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//TODO not used but let it for reference until all use cases are impl.
public class PaymentProcess {
private static final Logger log = LoggerFactory.getLogger(PaymentProcess.class);
protected String offererDepositPubKey;
protected String offererPayoutAddress;
protected String offererChangeAddress;
protected String offererTotalInputPayment;
protected String offererOutputPayment;
protected String takerDepositPubKey;
protected String takerPayoutAddress;
protected String takerChangeAddress;
protected String takerTotalInputPayment;
protected String takerOutputPayment;
protected String multiSigAddress;
public PaymentProcess() {
}
@Inject
public void setMessageService(MessageFacade messageService) {
}
@Inject
public void setWallet(WalletFacade wallet) {
}
@Inject
public void setBtcServices(BlockChainFacade bitcoinServices) {
}
public void executeStep0() {
}
public void executeStep1() {
}
public void executeStep2() {
}
public void executeStep3() {
}
protected void createDepositTx() {
//wallet.getInputs(offererTotalInputPayment);
//bitcoinServices.createTx(taker);
}
protected void payPaymentAndCollateral() {
}
protected void signDepositTx() {
}
protected void sendDataDepositTx() {
}
protected void onMessageFiatTxInited() {
}
protected void onUserInputFiatReceived() {
}
protected void onDataPayoutTx() {
}
protected void onMessageDepositTxPublished() {
}
protected void signPayoutTx() {
}
protected void publishPayoutTx() {
}
protected void sendMessagePayoutTxPublished() {
}
protected void onBlockChainConfirmation() {
}
protected void done() {
}
protected void onDataDepositTx() {
}
protected void payCollateral() {
}
protected void publishDepositTx() {
}
protected void sendMessageDepositTxPublished() {
}
protected void payFiat() {
}
protected void sendMessageFiatTxInited() {
}
protected void createPayoutTx() {
}
protected void sendDataPayoutTx() {
}
protected void onMessagePayoutTxPublished() {
}
/*
case 1:
BUY offer
taker:
1 PAY BTC
create ms
create deposit tx
pay payment+coll
signContract
send deposit tx to offerer
2 WAIT FOR FIAT
wait for pub tx info msg
wait for build fiat info msg
wait for fiat on bank
wait for payout tx
3 RELEASE BTC
signContract payout tx
pub payout tx
send info to offerer
wait for >= 1 confirm
DONE
offerer:
1 WAIT FOR BTC PAYMENT
wait for deposit tx
pay coll
signContract
pub deposit tx
send info msg to taker
wait for >=1 confirm
2 PAY FIAT
build fiat
send info msg to taker
create payout tx
signContract payout tx
send payout tx to taker
3 WAIT FOR BTC RELEASE
wait for release info msg
wait for >= 1 confirm
DONE
case 2:
SELL offer
taker:
1 PAY COLL
create ms
create deposit tx
pay coll
signContract
send deposit tx to offerer
2 WAIT FOR BTC PAYMENT
wait for pub tx info msg
wait for >=1 confirm
3 PAY FIAT -> Same
build fiat
send info msg to taker
create payout tx
signContract payout tx
send payout tx to offerer
4 WAIT FOR BTC RELEASE -> Same
wait for release info msg
wait for >= 1 confirm
DONE
offerer:
1 WAIT FOR COLL
wait for deposit tx
2 PAY BTC
pay coll+payment
signContract
pub deposit tx
send info msg to taker
3 WAIT FOR FIAT
wait for build fiat info msg
wait for payout tx
wait for fiat on bank
4 RELEASE BTC
signContract payout tx
pub payout tx
send info to taker
wait for >= 1 confirm
DONE
*/
}

View file

@ -1,56 +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.old;
//TODO not used but let it for reference until all use cases are impl.
class SellOffererPaymentProcess extends PaymentProcess {
public SellOffererPaymentProcess() {
super();
}
// case 2 offerer step 1
private void sellOfferOfferer_waitForCollateralPayedByPeer() {
onDataDepositTx();
}
// case 2 offerer step 2
private void sellOfferOfferer_payToDeposit() {
payPaymentAndCollateral();
signDepositTx();
publishDepositTx();
sendMessageDepositTxPublished();
}
// case 2 offerer step 3
private void sellOfferOfferer_waitForFiat() {
onMessageFiatTxInited();
onDataPayoutTx();
onUserInputFiatReceived();
}
// case 2 offerer step 4
private void sellOfferOfferer_releasePayment() {
signPayoutTx();
publishPayoutTx();
sendMessagePayoutTxPublished();
onBlockChainConfirmation();
done();
}
}

View file

@ -1,57 +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.old;
//TODO not used but let it for reference until all use cases are impl.
class SellTakerPaymentProcess extends PaymentProcess {
public SellTakerPaymentProcess() {
super();
}
// case 2 taker step 1
private void sellOfferTaker_payToDeposit() {
//createMultiSig();
createDepositTx();
payCollateral();
signDepositTx();
sendDataDepositTx();
}
// case 2 taker step 2
private void sellOfferTaker_waitForDepositPublished() {
onMessageDepositTxPublished();
onBlockChainConfirmation();
}
// case 2 taker step 3
private void sellOfferTaker_payFiat() {
payFiat();
sendMessageFiatTxInited();
createPayoutTx();
signPayoutTx();
sendDataPayoutTx();
}
// case 2 taker step 4
private void sellOfferTaker_waitForRelease() {
onMessagePayoutTxPublished();
onBlockChainConfirmation();
done();
}
}

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer;
import io.bitsquare.bank.BankAccount; import io.bitsquare.bank.BankAccount;
import io.bitsquare.btc.BlockChainFacade; import io.bitsquare.btc.BlockChainFacade;
@ -26,9 +26,19 @@ import io.bitsquare.msg.MessageFacade;
import io.bitsquare.trade.Contract; import io.bitsquare.trade.Contract;
import io.bitsquare.trade.Offer; import io.bitsquare.trade.Offer;
import io.bitsquare.trade.Trade; import io.bitsquare.trade.Trade;
import io.bitsquare.trade.protocol.taker.PayoutTxPublishedMessage; import io.bitsquare.trade.protocol.trade.offerer.tasks.CreateDepositTx;
import io.bitsquare.trade.protocol.taker.RequestOffererPublishDepositTxMessage; import io.bitsquare.trade.protocol.trade.offerer.tasks.HandleTakeOfferRequest;
import io.bitsquare.trade.protocol.taker.TakeOfferFeePayedMessage; import io.bitsquare.trade.protocol.trade.offerer.tasks.RequestTakerDepositPayment;
import io.bitsquare.trade.protocol.trade.offerer.tasks.SendDepositTxIdToTaker;
import io.bitsquare.trade.protocol.trade.offerer.tasks.SendSignedPayoutTx;
import io.bitsquare.trade.protocol.trade.offerer.tasks.SetupListenerForBlockChainConfirmation;
import io.bitsquare.trade.protocol.trade.offerer.tasks.SignAndPublishDepositTx;
import io.bitsquare.trade.protocol.trade.offerer.tasks.VerifyAndSignContract;
import io.bitsquare.trade.protocol.trade.offerer.tasks.VerifyTakeOfferFeePayment;
import io.bitsquare.trade.protocol.trade.offerer.tasks.VerifyTakerAccount;
import io.bitsquare.trade.protocol.trade.taker.messages.PayoutTxPublishedMessage;
import io.bitsquare.trade.protocol.trade.taker.messages.RequestOffererPublishDepositTxMessage;
import io.bitsquare.trade.protocol.trade.taker.messages.TakeOfferFeePayedMessage;
import io.bitsquare.user.User; import io.bitsquare.user.User;
import com.google.bitcoin.core.Coin; import com.google.bitcoin.core.Coin;
@ -56,9 +66,9 @@ import static io.bitsquare.util.Validator.*;
* It uses sub tasks to not pollute the main class too much with all the async result/fault handling. * It uses sub tasks to not pollute the main class too much with all the async result/fault handling.
* Any data from incoming messages need to be validated before further processing. * Any data from incoming messages need to be validated before further processing.
*/ */
public class ProtocolForOffererAsBuyer { public class BuyerAcceptsOfferProtocol {
private static final Logger log = LoggerFactory.getLogger(ProtocolForOffererAsBuyer.class); private static final Logger log = LoggerFactory.getLogger(BuyerAcceptsOfferProtocol.class);
public enum State { public enum State {
Init, Init,
@ -90,7 +100,7 @@ public class ProtocolForOffererAsBuyer {
private final WalletFacade walletFacade; private final WalletFacade walletFacade;
private final BlockChainFacade blockChainFacade; private final BlockChainFacade blockChainFacade;
private final CryptoFacade cryptoFacade; private final CryptoFacade cryptoFacade;
private final ProtocolForOffererAsBuyerListener listener; private final BuyerAcceptsOfferProtocolListener listener;
// derived // derived
private final String tradeId; private final String tradeId;
@ -127,14 +137,14 @@ public class ProtocolForOffererAsBuyer {
// Constructor // Constructor
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public ProtocolForOffererAsBuyer(Trade trade, public BuyerAcceptsOfferProtocol(Trade trade,
PeerAddress peerAddress, PeerAddress peerAddress,
MessageFacade messageFacade, MessageFacade messageFacade,
WalletFacade walletFacade, WalletFacade walletFacade,
BlockChainFacade blockChainFacade, BlockChainFacade blockChainFacade,
CryptoFacade cryptoFacade, CryptoFacade cryptoFacade,
User user, User user,
ProtocolForOffererAsBuyerListener listener) { BuyerAcceptsOfferProtocolListener listener) {
this.trade = trade; this.trade = trade;
this.peerAddress = peerAddress; this.peerAddress = peerAddress;
this.listener = listener; this.listener = listener;

View file

@ -15,13 +15,13 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer;
import io.bitsquare.trade.Offer; import io.bitsquare.trade.Offer;
import com.google.bitcoin.core.TransactionConfidence; import com.google.bitcoin.core.TransactionConfidence;
public interface ProtocolForOffererAsBuyerListener { public interface BuyerAcceptsOfferProtocolListener {
void onOfferAccepted(Offer offer); void onOfferAccepted(Offer offer);
void onDepositTxPublished(String depositTxID); void onDepositTxPublished(String depositTxID);
@ -32,11 +32,11 @@ public interface ProtocolForOffererAsBuyerListener {
void onPayoutTxPublished(String payoutTxID); void onPayoutTxPublished(String payoutTxID);
void onFault(Throwable throwable, ProtocolForOffererAsBuyer.State state); void onFault(Throwable throwable, BuyerAcceptsOfferProtocol.State state);
void onWaitingForPeerResponse(ProtocolForOffererAsBuyer.State state); void onWaitingForPeerResponse(BuyerAcceptsOfferProtocol.State state);
void onCompleted(ProtocolForOffererAsBuyer.State state); void onCompleted(BuyerAcceptsOfferProtocol.State state);
void onWaitingForUserInteraction(ProtocolForOffererAsBuyer.State state); void onWaitingForUserInteraction(BuyerAcceptsOfferProtocol.State state);
} }

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer.messages;
import io.bitsquare.trade.protocol.TradeMessage; import io.bitsquare.trade.protocol.TradeMessage;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer.messages;
import io.bitsquare.trade.protocol.TradeMessage; import io.bitsquare.trade.protocol.TradeMessage;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer.messages;
import io.bitsquare.bank.BankAccount; import io.bitsquare.bank.BankAccount;
import io.bitsquare.trade.protocol.TradeMessage; import io.bitsquare.trade.protocol.TradeMessage;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer.messages;
import io.bitsquare.trade.protocol.TradeMessage; import io.bitsquare.trade.protocol.TradeMessage;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer.tasks;
import io.bitsquare.btc.WalletFacade; import io.bitsquare.btc.WalletFacade;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;

View file

@ -15,12 +15,13 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer.tasks;
import io.bitsquare.msg.MessageFacade; import io.bitsquare.msg.MessageFacade;
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener; import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
import io.bitsquare.trade.Trade; import io.bitsquare.trade.Trade;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;
import io.bitsquare.trade.protocol.trade.offerer.messages.RespondToTakeOfferRequestMessage;
import net.tomp2p.peers.PeerAddress; import net.tomp2p.peers.PeerAddress;

View file

@ -15,13 +15,14 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer.tasks;
import io.bitsquare.bank.BankAccount; import io.bitsquare.bank.BankAccount;
import io.bitsquare.msg.MessageFacade; import io.bitsquare.msg.MessageFacade;
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener; import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;
import io.bitsquare.trade.handlers.ResultHandler; import io.bitsquare.trade.handlers.ResultHandler;
import io.bitsquare.trade.protocol.trade.offerer.messages.RequestTakerDepositPaymentMessage;
import net.tomp2p.peers.PeerAddress; import net.tomp2p.peers.PeerAddress;

View file

@ -15,12 +15,13 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer.tasks;
import io.bitsquare.msg.MessageFacade; import io.bitsquare.msg.MessageFacade;
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener; import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;
import io.bitsquare.trade.handlers.ResultHandler; import io.bitsquare.trade.handlers.ResultHandler;
import io.bitsquare.trade.protocol.trade.offerer.messages.DepositTxPublishedMessage;
import com.google.bitcoin.core.Transaction; import com.google.bitcoin.core.Transaction;
import com.google.bitcoin.core.Utils; import com.google.bitcoin.core.Utils;

View file

@ -15,13 +15,14 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer.tasks;
import io.bitsquare.btc.WalletFacade; import io.bitsquare.btc.WalletFacade;
import io.bitsquare.msg.MessageFacade; import io.bitsquare.msg.MessageFacade;
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener; import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;
import io.bitsquare.trade.handlers.ResultHandler; import io.bitsquare.trade.handlers.ResultHandler;
import io.bitsquare.trade.protocol.trade.offerer.messages.BankTransferInitedMessage;
import com.google.bitcoin.core.Coin; import com.google.bitcoin.core.Coin;
import com.google.bitcoin.core.ECKey; import com.google.bitcoin.core.ECKey;

View file

@ -15,10 +15,11 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer.tasks;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;
import io.bitsquare.trade.handlers.ResultHandler; import io.bitsquare.trade.handlers.ResultHandler;
import io.bitsquare.trade.protocol.trade.offerer.BuyerAcceptsOfferProtocolListener;
import com.google.bitcoin.core.Transaction; import com.google.bitcoin.core.Transaction;
import com.google.bitcoin.core.TransactionConfidence; import com.google.bitcoin.core.TransactionConfidence;
@ -30,7 +31,7 @@ public class SetupListenerForBlockChainConfirmation {
private static final Logger log = LoggerFactory.getLogger(SetupListenerForBlockChainConfirmation.class); private static final Logger log = LoggerFactory.getLogger(SetupListenerForBlockChainConfirmation.class);
public static void run(ResultHandler resultHandler, ExceptionHandler exceptionHandler, public static void run(ResultHandler resultHandler, ExceptionHandler exceptionHandler,
Transaction depositTransaction, ProtocolForOffererAsBuyerListener listener) { Transaction depositTransaction, BuyerAcceptsOfferProtocolListener listener) {
log.trace("Run task"); log.trace("Run task");
//TODO //TODO
// sharedModel.offererPaymentProtocolListener.onDepositTxConfirmedInBlockchain(); // sharedModel.offererPaymentProtocolListener.onDepositTxConfirmedInBlockchain();

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer.tasks;
import io.bitsquare.btc.WalletFacade; import io.bitsquare.btc.WalletFacade;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer.tasks;
import io.bitsquare.bank.BankAccount; import io.bitsquare.bank.BankAccount;
import io.bitsquare.crypto.CryptoFacade; import io.bitsquare.crypto.CryptoFacade;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer.tasks;
import io.bitsquare.btc.WalletFacade; import io.bitsquare.btc.WalletFacade;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;

View file

@ -15,13 +15,13 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.offerer; package io.bitsquare.trade.protocol.trade.offerer.tasks;
import io.bitsquare.bank.BankAccount; import io.bitsquare.bank.BankAccount;
import io.bitsquare.btc.BlockChainFacade; import io.bitsquare.btc.BlockChainFacade;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;
import io.bitsquare.trade.handlers.ResultHandler; import io.bitsquare.trade.handlers.ResultHandler;
import io.bitsquare.trade.protocol.shared.VerifyPeerAccount; import io.bitsquare.trade.protocol.trade.shared.tasks.VerifyPeerAccount;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.shared; package io.bitsquare.trade.protocol.trade.shared.tasks;
import io.bitsquare.bank.BankAccount; import io.bitsquare.bank.BankAccount;
import io.bitsquare.btc.BlockChainFacade; import io.bitsquare.btc.BlockChainFacade;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker;
import io.bitsquare.bank.BankAccount; import io.bitsquare.bank.BankAccount;
import io.bitsquare.btc.BlockChainFacade; import io.bitsquare.btc.BlockChainFacade;
@ -25,10 +25,20 @@ import io.bitsquare.msg.MessageFacade;
import io.bitsquare.trade.Contract; import io.bitsquare.trade.Contract;
import io.bitsquare.trade.Offer; import io.bitsquare.trade.Offer;
import io.bitsquare.trade.Trade; import io.bitsquare.trade.Trade;
import io.bitsquare.trade.protocol.offerer.BankTransferInitedMessage; import io.bitsquare.trade.protocol.trade.offerer.messages.BankTransferInitedMessage;
import io.bitsquare.trade.protocol.offerer.DepositTxPublishedMessage; import io.bitsquare.trade.protocol.trade.offerer.messages.DepositTxPublishedMessage;
import io.bitsquare.trade.protocol.offerer.RequestTakerDepositPaymentMessage; import io.bitsquare.trade.protocol.trade.offerer.messages.RequestTakerDepositPaymentMessage;
import io.bitsquare.trade.protocol.offerer.RespondToTakeOfferRequestMessage; import io.bitsquare.trade.protocol.trade.offerer.messages.RespondToTakeOfferRequestMessage;
import io.bitsquare.trade.protocol.trade.taker.tasks.CreateAndSignContract;
import io.bitsquare.trade.protocol.trade.taker.tasks.GetPeerAddress;
import io.bitsquare.trade.protocol.trade.taker.tasks.PayDeposit;
import io.bitsquare.trade.protocol.trade.taker.tasks.PayTakeOfferFee;
import io.bitsquare.trade.protocol.trade.taker.tasks.RequestTakeOffer;
import io.bitsquare.trade.protocol.trade.taker.tasks.SendPayoutTxToOfferer;
import io.bitsquare.trade.protocol.trade.taker.tasks.SendSignedTakerDepositTxAsHex;
import io.bitsquare.trade.protocol.trade.taker.tasks.SendTakeOfferFeePayedTxId;
import io.bitsquare.trade.protocol.trade.taker.tasks.SignAndPublishPayoutTx;
import io.bitsquare.trade.protocol.trade.taker.tasks.VerifyOffererAccount;
import io.bitsquare.user.User; import io.bitsquare.user.User;
import com.google.bitcoin.core.Coin; import com.google.bitcoin.core.Coin;
@ -52,8 +62,8 @@ import static io.bitsquare.util.Validator.*;
* It uses sub tasks to not pollute the main class too much with all the async result/fault handling. * It uses sub tasks to not pollute the main class too much with all the async result/fault handling.
* Any data from incoming messages as well data used to send to the peer need to be validated before further processing. * Any data from incoming messages as well data used to send to the peer need to be validated before further processing.
*/ */
public class ProtocolForTakerAsSeller { public class SellerTakesOfferProtocol {
private static final Logger log = LoggerFactory.getLogger(ProtocolForTakerAsSeller.class); private static final Logger log = LoggerFactory.getLogger(SellerTakesOfferProtocol.class);
public enum State { public enum State {
@ -76,7 +86,7 @@ public class ProtocolForTakerAsSeller {
// provided data // provided data
private final Trade trade; private final Trade trade;
private final ProtocolForTakerAsSellerListener listener; private final SellerTakesOfferProtocolListener listener;
private final MessageFacade messageFacade; private final MessageFacade messageFacade;
private final WalletFacade walletFacade; private final WalletFacade walletFacade;
private final BlockChainFacade blockChainFacade; private final BlockChainFacade blockChainFacade;
@ -122,8 +132,8 @@ public class ProtocolForTakerAsSeller {
// Constructor // Constructor
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public ProtocolForTakerAsSeller(Trade trade, public SellerTakesOfferProtocol(Trade trade,
ProtocolForTakerAsSellerListener listener, SellerTakesOfferProtocolListener listener,
MessageFacade messageFacade, MessageFacade messageFacade,
WalletFacade walletFacade, WalletFacade walletFacade,
BlockChainFacade blockChainFacade, BlockChainFacade blockChainFacade,

View file

@ -15,22 +15,22 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker;
import io.bitsquare.trade.Trade; import io.bitsquare.trade.Trade;
public interface ProtocolForTakerAsSellerListener { public interface SellerTakesOfferProtocolListener {
void onDepositTxPublished(String depositTxId); void onDepositTxPublished(String depositTxId);
void onBankTransferInited(String tradeId); void onBankTransferInited(String tradeId);
void onPayoutTxPublished(Trade trade, String hashAsString); void onPayoutTxPublished(Trade trade, String hashAsString);
void onFault(Throwable throwable, ProtocolForTakerAsSeller.State state); void onFault(Throwable throwable, SellerTakesOfferProtocol.State state);
void onWaitingForPeerResponse(ProtocolForTakerAsSeller.State state); void onWaitingForPeerResponse(SellerTakesOfferProtocol.State state);
void onCompleted(ProtocolForTakerAsSeller.State state); void onCompleted(SellerTakesOfferProtocol.State state);
void onTakeOfferRequestRejected(Trade trade); void onTakeOfferRequestRejected(Trade trade);
} }

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker.messages;
import io.bitsquare.trade.protocol.TradeMessage; import io.bitsquare.trade.protocol.TradeMessage;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker.messages;
import io.bitsquare.bank.BankAccount; import io.bitsquare.bank.BankAccount;
import io.bitsquare.trade.protocol.TradeMessage; import io.bitsquare.trade.protocol.TradeMessage;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker.messages;
import io.bitsquare.trade.protocol.TradeMessage; import io.bitsquare.trade.protocol.TradeMessage;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker.messages;
import io.bitsquare.trade.protocol.TradeMessage; import io.bitsquare.trade.protocol.TradeMessage;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker.tasks;
import io.bitsquare.bank.BankAccount; import io.bitsquare.bank.BankAccount;
import io.bitsquare.crypto.CryptoFacade; import io.bitsquare.crypto.CryptoFacade;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker.tasks;
import io.bitsquare.msg.MessageFacade; import io.bitsquare.msg.MessageFacade;
import io.bitsquare.msg.listeners.GetPeerAddressListener; import io.bitsquare.msg.listeners.GetPeerAddressListener;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker.tasks;
import io.bitsquare.btc.WalletFacade; import io.bitsquare.btc.WalletFacade;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker.tasks;
import io.bitsquare.btc.WalletFacade; import io.bitsquare.btc.WalletFacade;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;

View file

@ -15,12 +15,13 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker.tasks;
import io.bitsquare.msg.MessageFacade; import io.bitsquare.msg.MessageFacade;
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener; import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;
import io.bitsquare.trade.handlers.ResultHandler; import io.bitsquare.trade.handlers.ResultHandler;
import io.bitsquare.trade.protocol.trade.taker.messages.RequestTakeOfferMessage;
import net.tomp2p.peers.PeerAddress; import net.tomp2p.peers.PeerAddress;

View file

@ -15,12 +15,13 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker.tasks;
import io.bitsquare.msg.MessageFacade; import io.bitsquare.msg.MessageFacade;
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener; import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;
import io.bitsquare.trade.handlers.ResultHandler; import io.bitsquare.trade.handlers.ResultHandler;
import io.bitsquare.trade.protocol.trade.taker.messages.PayoutTxPublishedMessage;
import net.tomp2p.peers.PeerAddress; import net.tomp2p.peers.PeerAddress;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker.tasks;
import io.bitsquare.bank.BankAccount; import io.bitsquare.bank.BankAccount;
import io.bitsquare.btc.WalletFacade; import io.bitsquare.btc.WalletFacade;
@ -23,6 +23,7 @@ import io.bitsquare.msg.MessageFacade;
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener; import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;
import io.bitsquare.trade.handlers.ResultHandler; import io.bitsquare.trade.handlers.ResultHandler;
import io.bitsquare.trade.protocol.trade.taker.messages.RequestOffererPublishDepositTxMessage;
import com.google.bitcoin.core.Transaction; import com.google.bitcoin.core.Transaction;
import com.google.bitcoin.core.Utils; import com.google.bitcoin.core.Utils;

View file

@ -15,12 +15,13 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker.tasks;
import io.bitsquare.msg.MessageFacade; import io.bitsquare.msg.MessageFacade;
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener; import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;
import io.bitsquare.trade.handlers.ResultHandler; import io.bitsquare.trade.handlers.ResultHandler;
import io.bitsquare.trade.protocol.trade.taker.messages.TakeOfferFeePayedMessage;
import com.google.bitcoin.core.Coin; import com.google.bitcoin.core.Coin;

View file

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker.tasks;
import io.bitsquare.btc.WalletFacade; import io.bitsquare.btc.WalletFacade;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;

View file

@ -15,13 +15,13 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>. * along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/ */
package io.bitsquare.trade.protocol.taker; package io.bitsquare.trade.protocol.trade.taker.tasks;
import io.bitsquare.bank.BankAccount; import io.bitsquare.bank.BankAccount;
import io.bitsquare.btc.BlockChainFacade; import io.bitsquare.btc.BlockChainFacade;
import io.bitsquare.trade.handlers.ExceptionHandler; import io.bitsquare.trade.handlers.ExceptionHandler;
import io.bitsquare.trade.handlers.ResultHandler; import io.bitsquare.trade.handlers.ResultHandler;
import io.bitsquare.trade.protocol.shared.VerifyPeerAccount; import io.bitsquare.trade.protocol.trade.shared.tasks.VerifyPeerAccount;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;

View file

@ -28,7 +28,6 @@ public class BtcValidatorTest {
@Test @Test
public void testIsMinSpendableAmount() { public void testIsMinSpendableAmount() {
Coin amount = null; Coin amount = null;
//noinspection ConstantConditions
assertFalse("tx unfunded, pending", BtcValidator.isMinSpendableAmount(amount)); assertFalse("tx unfunded, pending", BtcValidator.isMinSpendableAmount(amount));
amount = Coin.ZERO; amount = Coin.ZERO;