trade protocol fixed states

This commit is contained in:
Manfred Karrer 2014-07-05 16:49:42 +02:00
parent fd1f23ea62
commit 16e1267c08
26 changed files with 104 additions and 106 deletions

View File

@ -10,41 +10,19 @@ import javafx.fxml.FXMLLoader;
*/
public class GuiceFXMLLoader extends FXMLLoader
{
private static Injector injector = null;
// not used yet
/* public GuiceFXMLLoader()
public static void setInjector(Injector injector)
{
super();
setupControllerFactory();
GuiceFXMLLoader.injector = injector;
}
public GuiceFXMLLoader(URL url)
{
super(url);
setupControllerFactory();
}
public GuiceFXMLLoader(URL url, ResourceBundle resourceBundle, BuilderFactory builderFactory)
{
super(url, resourceBundle, builderFactory);
setupControllerFactory();
} */
public GuiceFXMLLoader(URL url, ResourceBundle resourceBundle)
{
super(url, resourceBundle);
setupControllerFactory();
}
public static void setInjector(Injector injector)
{
GuiceFXMLLoader.injector = injector;
}
private void setupControllerFactory()
{
if (GuiceFXMLLoader.injector != null)

View File

@ -163,7 +163,9 @@ public class PendingTradeController implements Initializable, ChildController, H
initCopyIcons();
// select
Optional<PendingTradesListItem> currentTradeItemOptional = tradeItems.stream().filter((e) -> e.getTrade().getId().equals(trading.getPendingTrade().getId())).findFirst();
Optional<PendingTradesListItem> currentTradeItemOptional = tradeItems.stream()
.filter((e) -> trading.getPendingTrade() != null && e.getTrade().getId().equals(trading.getPendingTrade().getId()))
.findFirst();
if (currentTradeItemOptional.isPresent())
{
openTradesTable.getSelectionModel().select(currentTradeItemOptional.get());

View File

@ -320,9 +320,6 @@ public class Trading
{
// log.trace("processTradingMessage TradeId " + tradeMessage.getTradeId());
log.trace("processTradingMessage instance " + tradeMessage.getClass().getSimpleName());
log.trace("processTradingMessage instance " + tradeMessage.getClass().getName());
log.trace("processTradingMessage instance " + tradeMessage.getClass().getCanonicalName());
log.trace("processTradingMessage instance " + tradeMessage.getClass().getTypeName());
String tradeId = tradeMessage.getTradeId();

View File

@ -222,7 +222,7 @@ public class OrderBook implements OrderBookListener
@Override
public void onOfferRemoved(Data offerData, boolean success)
{
if (success)
if (success && offerData != null)
{
try
{

View File

@ -21,6 +21,7 @@ public class CreateDepositTx
String takerMultiSigPubKey,
String arbitratorPubKeyAsHex)
{
log.trace("Run task");
try
{
String offererPubKey = walletFacade.getAddressInfoByTradeID(tradeId).getPubKeyAsHexString();

View File

@ -14,6 +14,7 @@ public class HandleTakeOfferRequest
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, PeerAddress peerAddress, MessageFacade messageFacade, Trade.State tradeState, String tradeId)
{
log.trace("Run task");
boolean takeOfferRequestAccepted = tradeState == Trade.State.OPEN;
if (!takeOfferRequestAccepted)
{

View File

@ -35,14 +35,6 @@ public class ProtocolForOffererAsBuyer
{
private static final Logger log = LoggerFactory.getLogger(ProtocolForOffererAsBuyer.class);
private final String arbitratorPubKey;
private final BigInteger collateral;
private final BankAccount bankAccount;
private final String accountId;
private final BigInteger tradeAmount;
private final String messagePubKey;
private final ECKey accountKey;
private final String payoutAddress;
public enum State
{
@ -68,6 +60,7 @@ public class ProtocolForOffererAsBuyer
onPayoutTxPublishedMessage
}
// provided
private final Trade trade;
private final PeerAddress peerAddress;
private final MessageFacade messageFacade;
@ -76,11 +69,15 @@ public class ProtocolForOffererAsBuyer
private final CryptoFacade cryptoFacade;
private final ProtocolForOffererAsBuyerListener listener;
private final String id;
// derived
private final String tradeId;
private final Offer offer;
private State state;
private final String arbitratorPubKey;
private final BankAccount bankAccount;
private final String accountId;
private final String messagePubKey;
private final ECKey accountKey;
private final String payoutAddress;
// data written/read by tasks
private String preparedOffererDepositTxAsHex;
@ -99,6 +96,10 @@ public class ProtocolForOffererAsBuyer
private String txScriptSigAsHex;
private long takerTxOutIndex;
// state
private State state;
private int position = 0;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
@ -121,18 +122,18 @@ public class ProtocolForOffererAsBuyer
this.blockChainFacade = blockChainFacade;
this.cryptoFacade = cryptoFacade;
id = trade.getId();
tradeId = trade.getId();
offer = trade.getOffer();
arbitratorPubKey = offer.getArbitrator().getPubKeyAsHex();
collateral = trade.getCollateralAmount();
bankAccount = user.getBankAccount(trade.getOffer().getBankAccountId());
accountId = user.getAccountId();
tradeAmount = trade.getTradeAmount();
messagePubKey = user.getMessagePubKeyAsHex();
accountKey = walletFacade.getRegistrationAddressInfo().getKey();
payoutAddress = walletFacade.getAddressInfoByTradeID(tradeId).getAddressString();
state = State.Init;
}
@ -140,8 +141,8 @@ public class ProtocolForOffererAsBuyer
public void start()
{
log.debug("start called ");
HandleTakeOfferRequest.run(this::onResultHandleTakeOfferRequest, this::onFault, peerAddress, messageFacade, trade.getState(), tradeId);
state = State.HandleTakeOfferRequest;
HandleTakeOfferRequest.run(this::onResultHandleTakeOfferRequest, this::onFault, peerAddress, messageFacade, trade.getState(), tradeId);
}
public void onResultHandleTakeOfferRequest(boolean takeOfferRequestAccepted)
@ -168,6 +169,7 @@ public class ProtocolForOffererAsBuyer
public void onTakeOfferFeePayedMessage(@NotNull TakeOfferFeePayedMessage message)
{
log.debug("onTakeOfferFeePayedMessage called ");
log.debug("state " + state);
// validation
checkState(state == State.HandleTakeOfferRequest);
@ -184,17 +186,18 @@ public class ProtocolForOffererAsBuyer
trade.setTradeAmount(tradeAmount);
// next task
VerifyTakeOfferFeePayment.run(this::onResultVerifyTakeOfferFeePayment, this::onFault, walletFacade, this.takeOfferFeeTxId);
state = State.VerifyTakeOfferFeePayment;
VerifyTakeOfferFeePayment.run(this::onResultVerifyTakeOfferFeePayment, this::onFault, walletFacade, this.takeOfferFeeTxId);
}
public void onResultVerifyTakeOfferFeePayment()
{
log.debug("onResultVerifyTakeOfferFeePayment called ");
BigInteger collateral = trade.getCollateralAmount();
state = State.CreateDepositTx;
CreateDepositTx.run(this::onResultCreateDepositTx, this::onFault, walletFacade, tradeId, collateral, takerPubKey, arbitratorPubKey);
state = State.CreateDepositTx;
}
public void onResultCreateDepositTx(String offererPubKey, String preparedOffererDepositTxAsHex, long offererTxOutIndex)
@ -203,7 +206,7 @@ public class ProtocolForOffererAsBuyer
this.preparedOffererDepositTxAsHex = preparedOffererDepositTxAsHex;
this.offererTxOutIndex = offererTxOutIndex;
state = State.RequestTakerDepositPayment;
RequestTakerDepositPayment.run(this::onResultRequestTakerDepositPayment,
this::onFault,
peerAddress,
@ -214,8 +217,6 @@ public class ProtocolForOffererAsBuyer
offererPubKey,
preparedOffererDepositTxAsHex,
offererTxOutIndex);
state = State.RequestTakerDepositPayment;
}
public void onResultRequestTakerDepositPayment()
@ -232,6 +233,7 @@ public class ProtocolForOffererAsBuyer
public void onRequestOffererPublishDepositTxMessage(RequestOffererPublishDepositTxMessage message)
{
log.debug("onRequestOffererPublishDepositTxMessage called ");
log.debug("state " + state);
// validation
checkState(state == State.RequestTakerDepositPayment);
@ -259,14 +261,16 @@ public class ProtocolForOffererAsBuyer
this.takerTxOutIndex = takerTxOutIndex;
// next task
VerifyTakerAccount.run(this::onResultVerifyTakerAccount, this::onFault, blockChainFacade, this.peersAccountId, this.peersBankAccount);
state = State.VerifyTakerAccount;
VerifyTakerAccount.run(this::onResultVerifyTakerAccount, this::onFault, blockChainFacade, this.peersAccountId, this.peersBankAccount);
}
public void onResultVerifyTakerAccount()
{
log.debug("onResultVerifyTakerAccount called ");
BigInteger tradeAmount = trade.getTradeAmount();
state = State.VerifyAndSignContract;
VerifyAndSignContract.run(this::onResultVerifyAndSignContract,
this::onFault,
cryptoFacade,
@ -281,8 +285,6 @@ public class ProtocolForOffererAsBuyer
peersMessagePubKey,
peersContractAsJson,
accountKey);
state = State.VerifyAndSignContract;
}
public void onResultVerifyAndSignContract(Contract contract, String contractAsJson, String signature)
@ -292,7 +294,7 @@ public class ProtocolForOffererAsBuyer
trade.setContract(contract);
trade.setContractAsJson(contractAsJson);
trade.setContractTakerSignature(signature);
state = State.SignAndPublishDepositTx;
SignAndPublishDepositTx.run(this::onResultSignAndPublishDepositTx,
this::onFault,
walletFacade,
@ -302,7 +304,6 @@ public class ProtocolForOffererAsBuyer
txScriptSigAsHex,
offererTxOutIndex,
takerTxOutIndex);
state = State.SignAndPublishDepositTx;
}
public void onResultSignAndPublishDepositTx(Transaction depositTransaction)
@ -312,16 +313,16 @@ public class ProtocolForOffererAsBuyer
trade.setDepositTransaction(depositTransaction);
listener.onDepositTxPublished(depositTransaction.getHashAsString());
SendDepositTxIdToTaker.run(this::onResultSendDepositTxIdToTaker, this::onFault, peerAddress, messageFacade, tradeId, depositTransaction);
state = State.SendDepositTxIdToTaker;
SendDepositTxIdToTaker.run(this::onResultSendDepositTxIdToTaker, this::onFault, peerAddress, messageFacade, tradeId, depositTransaction);
}
public void onResultSendDepositTxIdToTaker()
{
log.debug("onResultSendDepositTxIdToTaker called ");
SetupListenerForBlockChainConfirmation.run(this::onResultSetupListenerForBlockChainConfirmation, this::onFault, trade.getDepositTransaction(), listener);
state = State.SetupListenerForBlockChainConfirmation;
SetupListenerForBlockChainConfirmation.run(this::onResultSetupListenerForBlockChainConfirmation, this::onFault, trade.getDepositTransaction(), listener);
}
public void onResultSetupListenerForBlockChainConfirmation()
@ -341,16 +342,18 @@ public class ProtocolForOffererAsBuyer
public void onUIEventBankTransferInited()
{
log.debug("onUIEventBankTransferInited called ");
log.debug("state " + state);
// validation
checkState(state == State.onResultSetupListenerForBlockChainConfirmation);
checkState(state.ordinal() >= State.SignAndPublishDepositTx.ordinal() && state.ordinal() <= State.onResultSetupListenerForBlockChainConfirmation.ordinal());
state = State.onUIEventBankTransferInited;
// next task
String depositTransactionId = trade.getDepositTransaction().getHashAsString();
BigInteger tradeAmount = trade.getTradeAmount();
BigInteger collateral = trade.getCollateralAmount();
state = State.SendSignedPayoutTx;
SendSignedPayoutTx.run(this::onResultSendSignedPayoutTx,
this::onFault,
peerAddress,
@ -362,7 +365,6 @@ public class ProtocolForOffererAsBuyer
depositTransactionId,
collateral,
tradeAmount);
state = State.SendSignedPayoutTx;
}
public void onResultSendSignedPayoutTx()
@ -380,6 +382,7 @@ public class ProtocolForOffererAsBuyer
public void onPayoutTxPublishedMessage(PayoutTxPublishedMessage message)
{
log.debug("onPayoutTxPublishedMessage called ");
log.debug("state " + state);
// validation
checkState(state == State.SendSignedPayoutTx);
@ -400,7 +403,7 @@ public class ProtocolForOffererAsBuyer
public String getId()
{
return id;
return tradeId;
}

View File

@ -24,6 +24,7 @@ public class RequestTakerDepositPayment
String preparedOffererDepositTxAsHex,
long offererTxOutIndex)
{
log.trace("Run task");
RequestTakerDepositPaymentMessage tradeMessage = new RequestTakerDepositPaymentMessage(tradeId, bankAccount, accountId, offererPubKey, preparedOffererDepositTxAsHex, offererTxOutIndex);
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener()
{

View File

@ -16,6 +16,7 @@ public class SendDepositTxIdToTaker
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, PeerAddress peerAddress, MessageFacade messageFacade, String tradeId, Transaction depositTransaction)
{
log.trace("Run task");
DepositTxPublishedMessage tradeMessage = new DepositTxPublishedMessage(tradeId, Utils.bytesToHexString(depositTransaction.bitcoinSerialize()));
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener()
{

View File

@ -28,6 +28,7 @@ public class SendSignedPayoutTx
BigInteger collateral,
BigInteger tradeAmount)
{
log.trace("Run task");
try
{
BigInteger offererPaybackAmount = tradeAmount.add(collateral);

View File

@ -12,7 +12,9 @@ public class SetupListenerForBlockChainConfirmation
private static final Logger log = LoggerFactory.getLogger(SetupListenerForBlockChainConfirmation.class);
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, Transaction depositTransaction, ProtocolForOffererAsBuyerListener listener)
{ //TODO
{
log.trace("Run task");
//TODO
// sharedModel.offererPaymentProtocolListener.onDepositTxConfirmedInBlockchain();
depositTransaction.getConfidence().addEventListener(new TransactionConfidence.Listener()

View File

@ -21,6 +21,7 @@ public class SignAndPublishDepositTx
long offererTxOutIndex,
long takerTxOutIndex)
{
log.trace("Run task");
try
{
walletFacade.offererSignAndPublishTx(preparedOffererDepositTxAsHex,

View File

@ -30,6 +30,7 @@ public class VerifyAndSignContract
String peersContractAsJson,
ECKey registrationKey)
{
log.trace("Run task");
Contract contract = new Contract(offer, tradeAmount, takeOfferFeeTxId, accountId, peersAccountId, bankAccount, peersBankAccount, messagePubKeyAsHex, takerMessagePubKey);
String contractAsJson = Utilities.objectToJson(contract);

View File

@ -11,7 +11,9 @@ public class VerifyTakeOfferFeePayment
private static final Logger log = LoggerFactory.getLogger(VerifyTakeOfferFeePayment.class);
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, WalletFacade walletFacade, String takeOfferFeeTxId)
{ //TODO mocked yet, need a confidence listeners
{
log.trace("Run task");
//TODO mocked yet, need a confidence listeners
int numOfPeersSeenTx = walletFacade.getNumOfPeersSeenTx(takeOfferFeeTxId);
if (numOfPeersSeenTx > 2)
{

View File

@ -14,6 +14,7 @@ public class VerifyTakerAccount
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, BlockChainFacade blockChainFacade, String peersAccountId, BankAccount peersBankAccount)
{
log.trace("Run task");
VerifyPeerAccount.run(resultHandler, faultHandler, blockChainFacade, peersAccountId, peersBankAccount);
}

View File

@ -29,6 +29,7 @@ public class CreateAndSignContract
BankAccount peersBankAccount,
ECKey registrationKey)
{
log.trace("Run task");
try
{
Contract contract = new Contract(offer, tradeAmount, takeOfferFeeTxId, peersAccountId, accountId, peersBankAccount, bankAccount, peersMessagePubKeyAsHex, messagePubKeyAsHex);

View File

@ -13,6 +13,7 @@ public class GetPeerAddress
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, MessageFacade messageFacade, String messagePubKeyAsHex)
{
log.trace("Run task");
messageFacade.getPeerAddress(messagePubKeyAsHex, new GetPeerAddressListener()
{
@Override

View File

@ -23,6 +23,7 @@ public class PayDeposit
String offererPubKey,
String preparedOffererDepositTxAsHex)
{
log.trace("Run task");
try
{
BigInteger amountToPay = tradeAmount.add(collateral);

View File

@ -14,7 +14,7 @@ public class PayTakeOfferFee
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, WalletFacade walletFacade, String tradeId)
{
log.trace("execute");
log.trace("Run task");
try
{
walletFacade.payTakeOfferFee(tradeId, new FutureCallback<Transaction>()

View File

@ -48,9 +48,7 @@ public class ProtocolForTakerAsSeller
CreateAndSignContract,
PayDeposit,
SendSignedTakerDepositTxAsHex,
onDepositTxPublishedMessage,
onBankTransferInitedMessage,
onUIEventFiatReceived,
SignAndPublishPayoutTx,
SendPayoutTxToOfferer
}
@ -64,7 +62,6 @@ public class ProtocolForTakerAsSeller
private final CryptoFacade cryptoFacade;
// derived
private final String id;
private final Offer offer;
private final String tradeId;
private final BankAccount bankAccount;
@ -97,6 +94,7 @@ public class ProtocolForTakerAsSeller
// state
private State state;
private int position = 0;
///////////////////////////////////////////////////////////////////////////////////////////
@ -124,39 +122,37 @@ public class ProtocolForTakerAsSeller
collateral = trade.getCollateralAmount();
arbitratorPubKey = trade.getOffer().getArbitrator().getPubKeyAsHex();
pubKeyForThatTrade = walletFacade.getAddressInfoByTradeID(tradeId).getPubKeyAsHexString();
peersMessagePubKey = offer.getMessagePubKeyAsHex();
bankAccount = user.getBankAccount(offer.getBankAccountId());
accountId = user.getAccountId();
messagePubKey = user.getMessagePubKeyAsHex();
peersMessagePubKey = offer.getMessagePubKeyAsHex();
pubKeyForThatTrade = walletFacade.getAddressInfoByTradeID(tradeId).getPubKeyAsHexString();
accountKey = walletFacade.getRegistrationAddressInfo().getKey();
id = trade.getId();
state = State.Init;
}
public void start()
{
log.debug("start called");
GetPeerAddress.run(this::onResultGetPeerAddress, this::onFault, messageFacade, peersMessagePubKey);
log.debug("start called " + position++);
state = State.GetPeerAddress;
GetPeerAddress.run(this::onResultGetPeerAddress, this::onFault, messageFacade, peersMessagePubKey);
}
public void onResultGetPeerAddress(PeerAddress peerAddress)
{
log.debug(" called");
log.debug("onResultGetPeerAddress called " + position++);
this.peerAddress = peerAddress;
RequestTakeOffer.run(this::onResultRequestTakeOffer, this::onFault, peerAddress, messageFacade, tradeId);
state = State.RequestTakeOffer;
RequestTakeOffer.run(this::onResultRequestTakeOffer, this::onFault, peerAddress, messageFacade, tradeId);
}
public void onResultRequestTakeOffer()
{
log.debug(" called");
log.debug("onResultRequestTakeOffer called " + position++);
listener.onWaitingForPeerResponse(state);
}
@ -167,14 +163,15 @@ public class ProtocolForTakerAsSeller
public void onRespondToTakeOfferRequestMessage(RespondToTakeOfferRequestMessage message)
{
log.debug("onRespondToTakeOfferRequestMessage called");
log.debug("onRespondToTakeOfferRequestMessage called " + position++);
log.debug("state " + state);
checkState(state == State.RequestTakeOffer);
checkArgument(tradeId.equals(message.getTradeId()));
if (message.isTakeOfferRequestAccepted())
{
PayTakeOfferFee.run(this::onResultPayTakeOfferFee, this::onFault, walletFacade, tradeId);
state = State.PayTakeOfferFee;
PayTakeOfferFee.run(this::onResultPayTakeOfferFee, this::onFault, walletFacade, tradeId);
}
else
{
@ -184,16 +181,16 @@ public class ProtocolForTakerAsSeller
public void onResultPayTakeOfferFee(String takeOfferFeeTxId)
{
log.debug("onResultPayTakeOfferFee called");
log.debug("onResultPayTakeOfferFee called " + position++);
trade.setTakeOfferFeeTxID(takeOfferFeeTxId);
SendTakeOfferFeePayedTxId.run(this::onResultSendTakeOfferFeePayedTxId, this::onFault, peerAddress, messageFacade, tradeId, takeOfferFeeTxId, tradeAmount, pubKeyForThatTrade);
state = State.SendTakeOfferFeePayedTxId;
SendTakeOfferFeePayedTxId.run(this::onResultSendTakeOfferFeePayedTxId, this::onFault, peerAddress, messageFacade, tradeId, takeOfferFeeTxId, tradeAmount, pubKeyForThatTrade);
}
public void onResultSendTakeOfferFeePayedTxId()
{
log.debug("onResultSendTakeOfferFeePayedTxId called");
log.debug("onResultSendTakeOfferFeePayedTxId called " + position++);
listener.onWaitingForPeerResponse(state);
}
@ -204,7 +201,8 @@ public class ProtocolForTakerAsSeller
public void onRequestTakerDepositPaymentMessage(RequestTakerDepositPaymentMessage message)
{
log.debug("onRequestTakerDepositPaymentMessage called");
log.debug("onRequestTakerDepositPaymentMessage called " + position++);
log.debug("state " + state);
// validation
checkState(state == State.SendTakeOfferFeePayedTxId);
@ -224,14 +222,15 @@ public class ProtocolForTakerAsSeller
this.peersTxOutIndex = offererTxOutIndex;
// next task
VerifyOffererAccount.run(this::onResultVerifyOffererAccount, this::onFault, blockChainFacade, peersAccountId, peersBankAccount);
state = State.VerifyOffererAccount;
VerifyOffererAccount.run(this::onResultVerifyOffererAccount, this::onFault, blockChainFacade, peersAccountId, peersBankAccount);
}
public void onResultVerifyOffererAccount()
{
log.debug("onResultVerifyOffererAccount called");
log.debug("onResultVerifyOffererAccount called " + position++);
String takeOfferFeeTxId = trade.getTakeOfferFeeTxId();
state = State.CreateAndSignContract;
CreateAndSignContract.run(this::onResultCreateAndSignContract,
this::onFault,
cryptoFacade,
@ -245,27 +244,27 @@ public class ProtocolForTakerAsSeller
peersAccountId,
peersBankAccount,
accountKey);
state = State.CreateAndSignContract;
}
public void onResultCreateAndSignContract(Contract contract, String contractAsJson, String signature)
{
log.debug("onResultCreateAndSignContract called");
log.debug("onResultCreateAndSignContract called " + position++);
trade.setContract(contract);
trade.setContractAsJson(contractAsJson);
trade.setContractTakerSignature(signature);
PayDeposit.run(this::onResultPayDeposit, this::onFault, walletFacade, collateral, tradeAmount, tradeId, pubKeyForThatTrade, arbitratorPubKey, peersPubKey, preparedPeersDepositTxAsHex);
state = State.PayDeposit;
PayDeposit.run(this::onResultPayDeposit, this::onFault, walletFacade, collateral, tradeAmount, tradeId, pubKeyForThatTrade, arbitratorPubKey, peersPubKey, preparedPeersDepositTxAsHex);
}
public void onResultPayDeposit(Transaction signedTakerDepositTx)
{
log.debug("onResultPayDeposit called");
log.debug("onResultPayDeposit called " + position++);
String contractAsJson = trade.getContractAsJson();
String takerSignature = trade.getTakerSignature();
state = State.SendSignedTakerDepositTxAsHex;
SendSignedTakerDepositTxAsHex.run(this::onResultSendSignedTakerDepositTxAsHex,
this::onFault,
peerAddress,
@ -279,12 +278,11 @@ public class ProtocolForTakerAsSeller
takerSignature,
signedTakerDepositTx,
peersTxOutIndex);
state = State.SendSignedTakerDepositTxAsHex;
}
public void onResultSendSignedTakerDepositTxAsHex()
{
log.debug(" called");
log.debug("onResultSendSignedTakerDepositTxAsHex called " + position++);
listener.onWaitingForPeerResponse(state);
}
@ -296,10 +294,10 @@ public class ProtocolForTakerAsSeller
// informational, does only trigger UI feedback/update
public void onDepositTxPublishedMessage(DepositTxPublishedMessage message)
{
log.debug("onDepositTxPublishedMessage called");
checkState(state.ordinal() > State.SendSignedTakerDepositTxAsHex.ordinal() && state.ordinal() < State.SignAndPublishPayoutTx.ordinal());
log.debug("onDepositTxPublishedMessage called " + position++);
log.debug("state " + state);
checkState(state.ordinal() >= State.SendSignedTakerDepositTxAsHex.ordinal());
checkArgument(tradeId.equals(message.getTradeId()));
state = State.onDepositTxPublishedMessage;
listener.onDepositTxPublished(walletFacade.takerCommitDepositTx(message.getDepositTxAsHex()));
}
@ -311,10 +309,10 @@ public class ProtocolForTakerAsSeller
// informational, store data for later, does only trigger UI feedback/update
public void onBankTransferInitedMessage(BankTransferInitedMessage message)
{
log.debug("onBankTransferInitedMessage called");
log.debug("onBankTransferInitedMessage called " + position++);
log.debug("state " + state);
// validate
checkState(state.ordinal() > State.SendSignedTakerDepositTxAsHex.ordinal() && state.ordinal() < State.SignAndPublishPayoutTx.ordinal());
checkState(state.ordinal() >= State.SendSignedTakerDepositTxAsHex.ordinal() && state.ordinal() < State.SignAndPublishPayoutTx.ordinal());
checkArgument(tradeId.equals(message.getTradeId()));
String depositTxAsHex = nonEmptyStringOf(message.getDepositTxAsHex());
String offererSignatureR = nonEmptyStringOf(message.getOffererSignatureR());
@ -343,11 +341,11 @@ public class ProtocolForTakerAsSeller
// User clicked the "bank transfer received" button, so we release the funds for pay out
public void onUIEventFiatReceived()
{
log.debug("onUIEventFiatReceived called");
checkState(state.ordinal() > State.SendSignedTakerDepositTxAsHex.ordinal() && state.ordinal() < State.SignAndPublishPayoutTx.ordinal());
state = State.onUIEventFiatReceived;
log.debug("onUIEventFiatReceived called " + position++);
log.debug("state " + state);
checkState(state == State.onBankTransferInitedMessage);
state = State.SignAndPublishPayoutTx;
SignAndPublishPayoutTx.run(this::onResultSignAndPublishPayoutTx,
this::onFault,
walletFacade,
@ -358,21 +356,20 @@ public class ProtocolForTakerAsSeller
offererPaybackAmount,
takerPaybackAmount,
offererPayoutAddress);
state = State.SignAndPublishPayoutTx;
}
public void onResultSignAndPublishPayoutTx(String transactionId, String payoutTxAsHex)
{
log.debug("onResultSignAndPublishPayoutTx called");
log.debug("onResultSignAndPublishPayoutTx called " + position++);
listener.onPayoutTxPublished(trade, transactionId);
SendPayoutTxToOfferer.run(this::onResultSendPayoutTxToOfferer, this::onFault, peerAddress, messageFacade, tradeId, payoutTxAsHex);
state = State.SendPayoutTxToOfferer;
SendPayoutTxToOfferer.run(this::onResultSendPayoutTxToOfferer, this::onFault, peerAddress, messageFacade, tradeId, payoutTxAsHex);
}
public void onResultSendPayoutTxToOfferer()
{
log.debug("onResultSendPayoutTxToOfferer called");
log.debug("onResultSendPayoutTxToOfferer called " + position++);
listener.onCompleted(state);
}
@ -383,7 +380,7 @@ public class ProtocolForTakerAsSeller
public String getId()
{
return id;
return tradeId;
}

View File

@ -14,6 +14,7 @@ public class RequestTakeOffer
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, PeerAddress peerAddress, MessageFacade messageFacade, String tradeId)
{
log.trace("Run task");
messageFacade.sendTradeMessage(peerAddress, new RequestTakeOfferMessage(tradeId), new OutgoingTradeMessageListener()
{
@Override

View File

@ -14,6 +14,7 @@ public class SendPayoutTxToOfferer
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, PeerAddress peerAddress, MessageFacade messageFacade, String tradeId, String payoutTxAsHex)
{
log.trace("Run task");
PayoutTxPublishedMessage tradeMessage = new PayoutTxPublishedMessage(tradeId, payoutTxAsHex);
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener()
{

View File

@ -30,6 +30,7 @@ public class SendSignedTakerDepositTxAsHex
Transaction signedTakerDepositTx,
long offererTxOutIndex)
{
log.trace("Run task");
long takerTxOutIndex = signedTakerDepositTx.getInput(1).getOutpoint().getIndex();
RequestOffererPublishDepositTxMessage tradeMessage = new RequestOffererPublishDepositTxMessage(tradeId,

View File

@ -22,6 +22,7 @@ public class SendTakeOfferFeePayedTxId
BigInteger tradeAmount,
String pubKeyForThatTradeAsHex)
{
log.trace("Run task");
TakeOfferFeePayedMessage msg = new TakeOfferFeePayedMessage(tradeId, takeOfferFeeTxId, tradeAmount, pubKeyForThatTradeAsHex);
messageFacade.sendTradeMessage(peerAddress, msg, new OutgoingTradeMessageListener()

View File

@ -24,6 +24,7 @@ public class SignAndPublishPayoutTx
BigInteger takerPaybackAmount,
String offererPayoutAddress)
{
log.trace("Run task");
try
{

View File

@ -14,6 +14,7 @@ public class VerifyOffererAccount
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, BlockChainFacade blockChainFacade, String peersAccountId, BankAccount peersBankAccount)
{
log.trace("Run task");
VerifyPeerAccount.run(resultHandler, faultHandler, blockChainFacade, peersAccountId, peersBankAccount);
}
}