mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-22 13:39:39 -04:00
trade protocol fixed states
This commit is contained in:
parent
fd1f23ea62
commit
16e1267c08
26 changed files with 104 additions and 106 deletions
|
@ -10,41 +10,19 @@ import javafx.fxml.FXMLLoader;
|
||||||
*/
|
*/
|
||||||
public class GuiceFXMLLoader extends FXMLLoader
|
public class GuiceFXMLLoader extends FXMLLoader
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
private static Injector injector = null;
|
private static Injector injector = null;
|
||||||
|
|
||||||
// not used yet
|
public static void setInjector(Injector injector)
|
||||||
/* public GuiceFXMLLoader()
|
|
||||||
{
|
{
|
||||||
super();
|
GuiceFXMLLoader.injector = injector;
|
||||||
setupControllerFactory();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
public GuiceFXMLLoader(URL url, ResourceBundle resourceBundle)
|
||||||
{
|
{
|
||||||
super(url, resourceBundle);
|
super(url, resourceBundle);
|
||||||
setupControllerFactory();
|
setupControllerFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void setInjector(Injector injector)
|
|
||||||
{
|
|
||||||
GuiceFXMLLoader.injector = injector;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupControllerFactory()
|
private void setupControllerFactory()
|
||||||
{
|
{
|
||||||
if (GuiceFXMLLoader.injector != null)
|
if (GuiceFXMLLoader.injector != null)
|
||||||
|
|
|
@ -163,7 +163,9 @@ public class PendingTradeController implements Initializable, ChildController, H
|
||||||
initCopyIcons();
|
initCopyIcons();
|
||||||
|
|
||||||
// select
|
// 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())
|
if (currentTradeItemOptional.isPresent())
|
||||||
{
|
{
|
||||||
openTradesTable.getSelectionModel().select(currentTradeItemOptional.get());
|
openTradesTable.getSelectionModel().select(currentTradeItemOptional.get());
|
||||||
|
|
|
@ -320,9 +320,6 @@ public class Trading
|
||||||
{
|
{
|
||||||
// log.trace("processTradingMessage TradeId " + tradeMessage.getTradeId());
|
// log.trace("processTradingMessage TradeId " + tradeMessage.getTradeId());
|
||||||
log.trace("processTradingMessage instance " + tradeMessage.getClass().getSimpleName());
|
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();
|
String tradeId = tradeMessage.getTradeId();
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,7 @@ public class OrderBook implements OrderBookListener
|
||||||
@Override
|
@Override
|
||||||
public void onOfferRemoved(Data offerData, boolean success)
|
public void onOfferRemoved(Data offerData, boolean success)
|
||||||
{
|
{
|
||||||
if (success)
|
if (success && offerData != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,6 +21,7 @@ public class CreateDepositTx
|
||||||
String takerMultiSigPubKey,
|
String takerMultiSigPubKey,
|
||||||
String arbitratorPubKeyAsHex)
|
String arbitratorPubKeyAsHex)
|
||||||
{
|
{
|
||||||
|
log.trace("Run task");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String offererPubKey = walletFacade.getAddressInfoByTradeID(tradeId).getPubKeyAsHexString();
|
String offererPubKey = walletFacade.getAddressInfoByTradeID(tradeId).getPubKeyAsHexString();
|
||||||
|
|
|
@ -14,6 +14,7 @@ public class HandleTakeOfferRequest
|
||||||
|
|
||||||
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, PeerAddress peerAddress, MessageFacade messageFacade, Trade.State tradeState, String tradeId)
|
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;
|
boolean takeOfferRequestAccepted = tradeState == Trade.State.OPEN;
|
||||||
if (!takeOfferRequestAccepted)
|
if (!takeOfferRequestAccepted)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,14 +35,6 @@ public class ProtocolForOffererAsBuyer
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(ProtocolForOffererAsBuyer.class);
|
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
|
public enum State
|
||||||
{
|
{
|
||||||
|
@ -68,6 +60,7 @@ public class ProtocolForOffererAsBuyer
|
||||||
onPayoutTxPublishedMessage
|
onPayoutTxPublishedMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// provided
|
||||||
private final Trade trade;
|
private final Trade trade;
|
||||||
private final PeerAddress peerAddress;
|
private final PeerAddress peerAddress;
|
||||||
private final MessageFacade messageFacade;
|
private final MessageFacade messageFacade;
|
||||||
|
@ -76,11 +69,15 @@ public class ProtocolForOffererAsBuyer
|
||||||
private final CryptoFacade cryptoFacade;
|
private final CryptoFacade cryptoFacade;
|
||||||
private final ProtocolForOffererAsBuyerListener listener;
|
private final ProtocolForOffererAsBuyerListener listener;
|
||||||
|
|
||||||
private final String id;
|
// derived
|
||||||
private final String tradeId;
|
private final String tradeId;
|
||||||
private final Offer offer;
|
private final Offer offer;
|
||||||
|
private final String arbitratorPubKey;
|
||||||
private State state;
|
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
|
// data written/read by tasks
|
||||||
private String preparedOffererDepositTxAsHex;
|
private String preparedOffererDepositTxAsHex;
|
||||||
|
@ -99,6 +96,10 @@ public class ProtocolForOffererAsBuyer
|
||||||
private String txScriptSigAsHex;
|
private String txScriptSigAsHex;
|
||||||
private long takerTxOutIndex;
|
private long takerTxOutIndex;
|
||||||
|
|
||||||
|
// state
|
||||||
|
private State state;
|
||||||
|
private int position = 0;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
|
@ -121,18 +122,18 @@ public class ProtocolForOffererAsBuyer
|
||||||
this.blockChainFacade = blockChainFacade;
|
this.blockChainFacade = blockChainFacade;
|
||||||
this.cryptoFacade = cryptoFacade;
|
this.cryptoFacade = cryptoFacade;
|
||||||
|
|
||||||
id = trade.getId();
|
|
||||||
|
|
||||||
tradeId = trade.getId();
|
tradeId = trade.getId();
|
||||||
offer = trade.getOffer();
|
offer = trade.getOffer();
|
||||||
|
|
||||||
arbitratorPubKey = offer.getArbitrator().getPubKeyAsHex();
|
arbitratorPubKey = offer.getArbitrator().getPubKeyAsHex();
|
||||||
collateral = trade.getCollateralAmount();
|
|
||||||
bankAccount = user.getBankAccount(trade.getOffer().getBankAccountId());
|
bankAccount = user.getBankAccount(trade.getOffer().getBankAccountId());
|
||||||
accountId = user.getAccountId();
|
accountId = user.getAccountId();
|
||||||
tradeAmount = trade.getTradeAmount();
|
|
||||||
messagePubKey = user.getMessagePubKeyAsHex();
|
messagePubKey = user.getMessagePubKeyAsHex();
|
||||||
|
|
||||||
accountKey = walletFacade.getRegistrationAddressInfo().getKey();
|
accountKey = walletFacade.getRegistrationAddressInfo().getKey();
|
||||||
payoutAddress = walletFacade.getAddressInfoByTradeID(tradeId).getAddressString();
|
payoutAddress = walletFacade.getAddressInfoByTradeID(tradeId).getAddressString();
|
||||||
|
|
||||||
state = State.Init;
|
state = State.Init;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,8 +141,8 @@ public class ProtocolForOffererAsBuyer
|
||||||
public void start()
|
public void start()
|
||||||
{
|
{
|
||||||
log.debug("start called ");
|
log.debug("start called ");
|
||||||
HandleTakeOfferRequest.run(this::onResultHandleTakeOfferRequest, this::onFault, peerAddress, messageFacade, trade.getState(), tradeId);
|
|
||||||
state = State.HandleTakeOfferRequest;
|
state = State.HandleTakeOfferRequest;
|
||||||
|
HandleTakeOfferRequest.run(this::onResultHandleTakeOfferRequest, this::onFault, peerAddress, messageFacade, trade.getState(), tradeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultHandleTakeOfferRequest(boolean takeOfferRequestAccepted)
|
public void onResultHandleTakeOfferRequest(boolean takeOfferRequestAccepted)
|
||||||
|
@ -168,6 +169,7 @@ public class ProtocolForOffererAsBuyer
|
||||||
public void onTakeOfferFeePayedMessage(@NotNull TakeOfferFeePayedMessage message)
|
public void onTakeOfferFeePayedMessage(@NotNull TakeOfferFeePayedMessage message)
|
||||||
{
|
{
|
||||||
log.debug("onTakeOfferFeePayedMessage called ");
|
log.debug("onTakeOfferFeePayedMessage called ");
|
||||||
|
log.debug("state " + state);
|
||||||
|
|
||||||
// validation
|
// validation
|
||||||
checkState(state == State.HandleTakeOfferRequest);
|
checkState(state == State.HandleTakeOfferRequest);
|
||||||
|
@ -184,17 +186,18 @@ public class ProtocolForOffererAsBuyer
|
||||||
trade.setTradeAmount(tradeAmount);
|
trade.setTradeAmount(tradeAmount);
|
||||||
|
|
||||||
// next task
|
// next task
|
||||||
VerifyTakeOfferFeePayment.run(this::onResultVerifyTakeOfferFeePayment, this::onFault, walletFacade, this.takeOfferFeeTxId);
|
|
||||||
state = State.VerifyTakeOfferFeePayment;
|
state = State.VerifyTakeOfferFeePayment;
|
||||||
|
VerifyTakeOfferFeePayment.run(this::onResultVerifyTakeOfferFeePayment, this::onFault, walletFacade, this.takeOfferFeeTxId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultVerifyTakeOfferFeePayment()
|
public void onResultVerifyTakeOfferFeePayment()
|
||||||
{
|
{
|
||||||
log.debug("onResultVerifyTakeOfferFeePayment called ");
|
log.debug("onResultVerifyTakeOfferFeePayment called ");
|
||||||
|
|
||||||
|
BigInteger collateral = trade.getCollateralAmount();
|
||||||
|
state = State.CreateDepositTx;
|
||||||
CreateDepositTx.run(this::onResultCreateDepositTx, this::onFault, walletFacade, tradeId, collateral, takerPubKey, arbitratorPubKey);
|
CreateDepositTx.run(this::onResultCreateDepositTx, this::onFault, walletFacade, tradeId, collateral, takerPubKey, arbitratorPubKey);
|
||||||
|
|
||||||
state = State.CreateDepositTx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultCreateDepositTx(String offererPubKey, String preparedOffererDepositTxAsHex, long offererTxOutIndex)
|
public void onResultCreateDepositTx(String offererPubKey, String preparedOffererDepositTxAsHex, long offererTxOutIndex)
|
||||||
|
@ -203,7 +206,7 @@ public class ProtocolForOffererAsBuyer
|
||||||
this.preparedOffererDepositTxAsHex = preparedOffererDepositTxAsHex;
|
this.preparedOffererDepositTxAsHex = preparedOffererDepositTxAsHex;
|
||||||
this.offererTxOutIndex = offererTxOutIndex;
|
this.offererTxOutIndex = offererTxOutIndex;
|
||||||
|
|
||||||
|
state = State.RequestTakerDepositPayment;
|
||||||
RequestTakerDepositPayment.run(this::onResultRequestTakerDepositPayment,
|
RequestTakerDepositPayment.run(this::onResultRequestTakerDepositPayment,
|
||||||
this::onFault,
|
this::onFault,
|
||||||
peerAddress,
|
peerAddress,
|
||||||
|
@ -214,8 +217,6 @@ public class ProtocolForOffererAsBuyer
|
||||||
offererPubKey,
|
offererPubKey,
|
||||||
preparedOffererDepositTxAsHex,
|
preparedOffererDepositTxAsHex,
|
||||||
offererTxOutIndex);
|
offererTxOutIndex);
|
||||||
|
|
||||||
state = State.RequestTakerDepositPayment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultRequestTakerDepositPayment()
|
public void onResultRequestTakerDepositPayment()
|
||||||
|
@ -232,6 +233,7 @@ public class ProtocolForOffererAsBuyer
|
||||||
public void onRequestOffererPublishDepositTxMessage(RequestOffererPublishDepositTxMessage message)
|
public void onRequestOffererPublishDepositTxMessage(RequestOffererPublishDepositTxMessage message)
|
||||||
{
|
{
|
||||||
log.debug("onRequestOffererPublishDepositTxMessage called ");
|
log.debug("onRequestOffererPublishDepositTxMessage called ");
|
||||||
|
log.debug("state " + state);
|
||||||
|
|
||||||
// validation
|
// validation
|
||||||
checkState(state == State.RequestTakerDepositPayment);
|
checkState(state == State.RequestTakerDepositPayment);
|
||||||
|
@ -259,14 +261,16 @@ public class ProtocolForOffererAsBuyer
|
||||||
this.takerTxOutIndex = takerTxOutIndex;
|
this.takerTxOutIndex = takerTxOutIndex;
|
||||||
|
|
||||||
// next task
|
// next task
|
||||||
VerifyTakerAccount.run(this::onResultVerifyTakerAccount, this::onFault, blockChainFacade, this.peersAccountId, this.peersBankAccount);
|
|
||||||
state = State.VerifyTakerAccount;
|
state = State.VerifyTakerAccount;
|
||||||
|
VerifyTakerAccount.run(this::onResultVerifyTakerAccount, this::onFault, blockChainFacade, this.peersAccountId, this.peersBankAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultVerifyTakerAccount()
|
public void onResultVerifyTakerAccount()
|
||||||
{
|
{
|
||||||
log.debug("onResultVerifyTakerAccount called ");
|
log.debug("onResultVerifyTakerAccount called ");
|
||||||
|
|
||||||
|
BigInteger tradeAmount = trade.getTradeAmount();
|
||||||
|
state = State.VerifyAndSignContract;
|
||||||
VerifyAndSignContract.run(this::onResultVerifyAndSignContract,
|
VerifyAndSignContract.run(this::onResultVerifyAndSignContract,
|
||||||
this::onFault,
|
this::onFault,
|
||||||
cryptoFacade,
|
cryptoFacade,
|
||||||
|
@ -281,8 +285,6 @@ public class ProtocolForOffererAsBuyer
|
||||||
peersMessagePubKey,
|
peersMessagePubKey,
|
||||||
peersContractAsJson,
|
peersContractAsJson,
|
||||||
accountKey);
|
accountKey);
|
||||||
|
|
||||||
state = State.VerifyAndSignContract;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultVerifyAndSignContract(Contract contract, String contractAsJson, String signature)
|
public void onResultVerifyAndSignContract(Contract contract, String contractAsJson, String signature)
|
||||||
|
@ -292,7 +294,7 @@ public class ProtocolForOffererAsBuyer
|
||||||
trade.setContract(contract);
|
trade.setContract(contract);
|
||||||
trade.setContractAsJson(contractAsJson);
|
trade.setContractAsJson(contractAsJson);
|
||||||
trade.setContractTakerSignature(signature);
|
trade.setContractTakerSignature(signature);
|
||||||
|
state = State.SignAndPublishDepositTx;
|
||||||
SignAndPublishDepositTx.run(this::onResultSignAndPublishDepositTx,
|
SignAndPublishDepositTx.run(this::onResultSignAndPublishDepositTx,
|
||||||
this::onFault,
|
this::onFault,
|
||||||
walletFacade,
|
walletFacade,
|
||||||
|
@ -302,7 +304,6 @@ public class ProtocolForOffererAsBuyer
|
||||||
txScriptSigAsHex,
|
txScriptSigAsHex,
|
||||||
offererTxOutIndex,
|
offererTxOutIndex,
|
||||||
takerTxOutIndex);
|
takerTxOutIndex);
|
||||||
state = State.SignAndPublishDepositTx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultSignAndPublishDepositTx(Transaction depositTransaction)
|
public void onResultSignAndPublishDepositTx(Transaction depositTransaction)
|
||||||
|
@ -312,16 +313,16 @@ public class ProtocolForOffererAsBuyer
|
||||||
trade.setDepositTransaction(depositTransaction);
|
trade.setDepositTransaction(depositTransaction);
|
||||||
listener.onDepositTxPublished(depositTransaction.getHashAsString());
|
listener.onDepositTxPublished(depositTransaction.getHashAsString());
|
||||||
|
|
||||||
SendDepositTxIdToTaker.run(this::onResultSendDepositTxIdToTaker, this::onFault, peerAddress, messageFacade, tradeId, depositTransaction);
|
|
||||||
state = State.SendDepositTxIdToTaker;
|
state = State.SendDepositTxIdToTaker;
|
||||||
|
SendDepositTxIdToTaker.run(this::onResultSendDepositTxIdToTaker, this::onFault, peerAddress, messageFacade, tradeId, depositTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultSendDepositTxIdToTaker()
|
public void onResultSendDepositTxIdToTaker()
|
||||||
{
|
{
|
||||||
log.debug("onResultSendDepositTxIdToTaker called ");
|
log.debug("onResultSendDepositTxIdToTaker called ");
|
||||||
|
|
||||||
SetupListenerForBlockChainConfirmation.run(this::onResultSetupListenerForBlockChainConfirmation, this::onFault, trade.getDepositTransaction(), listener);
|
|
||||||
state = State.SetupListenerForBlockChainConfirmation;
|
state = State.SetupListenerForBlockChainConfirmation;
|
||||||
|
SetupListenerForBlockChainConfirmation.run(this::onResultSetupListenerForBlockChainConfirmation, this::onFault, trade.getDepositTransaction(), listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultSetupListenerForBlockChainConfirmation()
|
public void onResultSetupListenerForBlockChainConfirmation()
|
||||||
|
@ -341,16 +342,18 @@ public class ProtocolForOffererAsBuyer
|
||||||
public void onUIEventBankTransferInited()
|
public void onUIEventBankTransferInited()
|
||||||
{
|
{
|
||||||
log.debug("onUIEventBankTransferInited called ");
|
log.debug("onUIEventBankTransferInited called ");
|
||||||
|
log.debug("state " + state);
|
||||||
|
|
||||||
// validation
|
// validation
|
||||||
checkState(state == State.onResultSetupListenerForBlockChainConfirmation);
|
checkState(state.ordinal() >= State.SignAndPublishDepositTx.ordinal() && state.ordinal() <= State.onResultSetupListenerForBlockChainConfirmation.ordinal());
|
||||||
|
|
||||||
|
|
||||||
state = State.onUIEventBankTransferInited;
|
state = State.onUIEventBankTransferInited;
|
||||||
|
|
||||||
// next task
|
// next task
|
||||||
String depositTransactionId = trade.getDepositTransaction().getHashAsString();
|
String depositTransactionId = trade.getDepositTransaction().getHashAsString();
|
||||||
|
BigInteger tradeAmount = trade.getTradeAmount();
|
||||||
|
BigInteger collateral = trade.getCollateralAmount();
|
||||||
|
state = State.SendSignedPayoutTx;
|
||||||
SendSignedPayoutTx.run(this::onResultSendSignedPayoutTx,
|
SendSignedPayoutTx.run(this::onResultSendSignedPayoutTx,
|
||||||
this::onFault,
|
this::onFault,
|
||||||
peerAddress,
|
peerAddress,
|
||||||
|
@ -362,7 +365,6 @@ public class ProtocolForOffererAsBuyer
|
||||||
depositTransactionId,
|
depositTransactionId,
|
||||||
collateral,
|
collateral,
|
||||||
tradeAmount);
|
tradeAmount);
|
||||||
state = State.SendSignedPayoutTx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultSendSignedPayoutTx()
|
public void onResultSendSignedPayoutTx()
|
||||||
|
@ -380,6 +382,7 @@ public class ProtocolForOffererAsBuyer
|
||||||
public void onPayoutTxPublishedMessage(PayoutTxPublishedMessage message)
|
public void onPayoutTxPublishedMessage(PayoutTxPublishedMessage message)
|
||||||
{
|
{
|
||||||
log.debug("onPayoutTxPublishedMessage called ");
|
log.debug("onPayoutTxPublishedMessage called ");
|
||||||
|
log.debug("state " + state);
|
||||||
|
|
||||||
// validation
|
// validation
|
||||||
checkState(state == State.SendSignedPayoutTx);
|
checkState(state == State.SendSignedPayoutTx);
|
||||||
|
@ -400,7 +403,7 @@ public class ProtocolForOffererAsBuyer
|
||||||
|
|
||||||
public String getId()
|
public String getId()
|
||||||
{
|
{
|
||||||
return id;
|
return tradeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ public class RequestTakerDepositPayment
|
||||||
String preparedOffererDepositTxAsHex,
|
String preparedOffererDepositTxAsHex,
|
||||||
long offererTxOutIndex)
|
long offererTxOutIndex)
|
||||||
{
|
{
|
||||||
|
log.trace("Run task");
|
||||||
RequestTakerDepositPaymentMessage tradeMessage = new RequestTakerDepositPaymentMessage(tradeId, bankAccount, accountId, offererPubKey, preparedOffererDepositTxAsHex, offererTxOutIndex);
|
RequestTakerDepositPaymentMessage tradeMessage = new RequestTakerDepositPaymentMessage(tradeId, bankAccount, accountId, offererPubKey, preparedOffererDepositTxAsHex, offererTxOutIndex);
|
||||||
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener()
|
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener()
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,7 @@ public class SendDepositTxIdToTaker
|
||||||
|
|
||||||
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, PeerAddress peerAddress, MessageFacade messageFacade, String tradeId, Transaction depositTransaction)
|
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()));
|
DepositTxPublishedMessage tradeMessage = new DepositTxPublishedMessage(tradeId, Utils.bytesToHexString(depositTransaction.bitcoinSerialize()));
|
||||||
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener()
|
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener()
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,6 +28,7 @@ public class SendSignedPayoutTx
|
||||||
BigInteger collateral,
|
BigInteger collateral,
|
||||||
BigInteger tradeAmount)
|
BigInteger tradeAmount)
|
||||||
{
|
{
|
||||||
|
log.trace("Run task");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BigInteger offererPaybackAmount = tradeAmount.add(collateral);
|
BigInteger offererPaybackAmount = tradeAmount.add(collateral);
|
||||||
|
|
|
@ -12,7 +12,9 @@ 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, FaultHandler faultHandler, Transaction depositTransaction, ProtocolForOffererAsBuyerListener listener)
|
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, Transaction depositTransaction, ProtocolForOffererAsBuyerListener listener)
|
||||||
{ //TODO
|
{
|
||||||
|
log.trace("Run task");
|
||||||
|
//TODO
|
||||||
// sharedModel.offererPaymentProtocolListener.onDepositTxConfirmedInBlockchain();
|
// sharedModel.offererPaymentProtocolListener.onDepositTxConfirmedInBlockchain();
|
||||||
|
|
||||||
depositTransaction.getConfidence().addEventListener(new TransactionConfidence.Listener()
|
depositTransaction.getConfidence().addEventListener(new TransactionConfidence.Listener()
|
||||||
|
|
|
@ -21,6 +21,7 @@ public class SignAndPublishDepositTx
|
||||||
long offererTxOutIndex,
|
long offererTxOutIndex,
|
||||||
long takerTxOutIndex)
|
long takerTxOutIndex)
|
||||||
{
|
{
|
||||||
|
log.trace("Run task");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
walletFacade.offererSignAndPublishTx(preparedOffererDepositTxAsHex,
|
walletFacade.offererSignAndPublishTx(preparedOffererDepositTxAsHex,
|
||||||
|
|
|
@ -30,6 +30,7 @@ public class VerifyAndSignContract
|
||||||
String peersContractAsJson,
|
String peersContractAsJson,
|
||||||
ECKey registrationKey)
|
ECKey registrationKey)
|
||||||
{
|
{
|
||||||
|
log.trace("Run task");
|
||||||
Contract contract = new Contract(offer, tradeAmount, takeOfferFeeTxId, accountId, peersAccountId, bankAccount, peersBankAccount, messagePubKeyAsHex, takerMessagePubKey);
|
Contract contract = new Contract(offer, tradeAmount, takeOfferFeeTxId, accountId, peersAccountId, bankAccount, peersBankAccount, messagePubKeyAsHex, takerMessagePubKey);
|
||||||
|
|
||||||
String contractAsJson = Utilities.objectToJson(contract);
|
String contractAsJson = Utilities.objectToJson(contract);
|
||||||
|
|
|
@ -11,7 +11,9 @@ public class VerifyTakeOfferFeePayment
|
||||||
private static final Logger log = LoggerFactory.getLogger(VerifyTakeOfferFeePayment.class);
|
private static final Logger log = LoggerFactory.getLogger(VerifyTakeOfferFeePayment.class);
|
||||||
|
|
||||||
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, WalletFacade walletFacade, String takeOfferFeeTxId)
|
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);
|
int numOfPeersSeenTx = walletFacade.getNumOfPeersSeenTx(takeOfferFeeTxId);
|
||||||
if (numOfPeersSeenTx > 2)
|
if (numOfPeersSeenTx > 2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,6 +14,7 @@ public class VerifyTakerAccount
|
||||||
|
|
||||||
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, BlockChainFacade blockChainFacade, String peersAccountId, BankAccount peersBankAccount)
|
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);
|
VerifyPeerAccount.run(resultHandler, faultHandler, blockChainFacade, peersAccountId, peersBankAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class CreateAndSignContract
|
||||||
BankAccount peersBankAccount,
|
BankAccount peersBankAccount,
|
||||||
ECKey registrationKey)
|
ECKey registrationKey)
|
||||||
{
|
{
|
||||||
|
log.trace("Run task");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Contract contract = new Contract(offer, tradeAmount, takeOfferFeeTxId, peersAccountId, accountId, peersBankAccount, bankAccount, peersMessagePubKeyAsHex, messagePubKeyAsHex);
|
Contract contract = new Contract(offer, tradeAmount, takeOfferFeeTxId, peersAccountId, accountId, peersBankAccount, bankAccount, peersMessagePubKeyAsHex, messagePubKeyAsHex);
|
||||||
|
|
|
@ -13,6 +13,7 @@ public class GetPeerAddress
|
||||||
|
|
||||||
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, MessageFacade messageFacade, String messagePubKeyAsHex)
|
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, MessageFacade messageFacade, String messagePubKeyAsHex)
|
||||||
{
|
{
|
||||||
|
log.trace("Run task");
|
||||||
messageFacade.getPeerAddress(messagePubKeyAsHex, new GetPeerAddressListener()
|
messageFacade.getPeerAddress(messagePubKeyAsHex, new GetPeerAddressListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class PayDeposit
|
||||||
String offererPubKey,
|
String offererPubKey,
|
||||||
String preparedOffererDepositTxAsHex)
|
String preparedOffererDepositTxAsHex)
|
||||||
{
|
{
|
||||||
|
log.trace("Run task");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BigInteger amountToPay = tradeAmount.add(collateral);
|
BigInteger amountToPay = tradeAmount.add(collateral);
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class PayTakeOfferFee
|
||||||
|
|
||||||
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, WalletFacade walletFacade, String tradeId)
|
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, WalletFacade walletFacade, String tradeId)
|
||||||
{
|
{
|
||||||
log.trace("execute");
|
log.trace("Run task");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
walletFacade.payTakeOfferFee(tradeId, new FutureCallback<Transaction>()
|
walletFacade.payTakeOfferFee(tradeId, new FutureCallback<Transaction>()
|
||||||
|
|
|
@ -48,9 +48,7 @@ public class ProtocolForTakerAsSeller
|
||||||
CreateAndSignContract,
|
CreateAndSignContract,
|
||||||
PayDeposit,
|
PayDeposit,
|
||||||
SendSignedTakerDepositTxAsHex,
|
SendSignedTakerDepositTxAsHex,
|
||||||
onDepositTxPublishedMessage,
|
|
||||||
onBankTransferInitedMessage,
|
onBankTransferInitedMessage,
|
||||||
onUIEventFiatReceived,
|
|
||||||
SignAndPublishPayoutTx,
|
SignAndPublishPayoutTx,
|
||||||
SendPayoutTxToOfferer
|
SendPayoutTxToOfferer
|
||||||
}
|
}
|
||||||
|
@ -64,7 +62,6 @@ public class ProtocolForTakerAsSeller
|
||||||
private final CryptoFacade cryptoFacade;
|
private final CryptoFacade cryptoFacade;
|
||||||
|
|
||||||
// derived
|
// derived
|
||||||
private final String id;
|
|
||||||
private final Offer offer;
|
private final Offer offer;
|
||||||
private final String tradeId;
|
private final String tradeId;
|
||||||
private final BankAccount bankAccount;
|
private final BankAccount bankAccount;
|
||||||
|
@ -97,6 +94,7 @@ public class ProtocolForTakerAsSeller
|
||||||
|
|
||||||
// state
|
// state
|
||||||
private State state;
|
private State state;
|
||||||
|
private int position = 0;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -124,39 +122,37 @@ public class ProtocolForTakerAsSeller
|
||||||
collateral = trade.getCollateralAmount();
|
collateral = trade.getCollateralAmount();
|
||||||
arbitratorPubKey = trade.getOffer().getArbitrator().getPubKeyAsHex();
|
arbitratorPubKey = trade.getOffer().getArbitrator().getPubKeyAsHex();
|
||||||
|
|
||||||
pubKeyForThatTrade = walletFacade.getAddressInfoByTradeID(tradeId).getPubKeyAsHexString();
|
peersMessagePubKey = offer.getMessagePubKeyAsHex();
|
||||||
|
|
||||||
bankAccount = user.getBankAccount(offer.getBankAccountId());
|
bankAccount = user.getBankAccount(offer.getBankAccountId());
|
||||||
accountId = user.getAccountId();
|
accountId = user.getAccountId();
|
||||||
messagePubKey = user.getMessagePubKeyAsHex();
|
messagePubKey = user.getMessagePubKeyAsHex();
|
||||||
|
|
||||||
peersMessagePubKey = offer.getMessagePubKeyAsHex();
|
pubKeyForThatTrade = walletFacade.getAddressInfoByTradeID(tradeId).getPubKeyAsHexString();
|
||||||
accountKey = walletFacade.getRegistrationAddressInfo().getKey();
|
accountKey = walletFacade.getRegistrationAddressInfo().getKey();
|
||||||
|
|
||||||
id = trade.getId();
|
|
||||||
|
|
||||||
state = State.Init;
|
state = State.Init;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start()
|
public void start()
|
||||||
{
|
{
|
||||||
log.debug("start called");
|
log.debug("start called " + position++);
|
||||||
GetPeerAddress.run(this::onResultGetPeerAddress, this::onFault, messageFacade, peersMessagePubKey);
|
|
||||||
state = State.GetPeerAddress;
|
state = State.GetPeerAddress;
|
||||||
|
GetPeerAddress.run(this::onResultGetPeerAddress, this::onFault, messageFacade, peersMessagePubKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultGetPeerAddress(PeerAddress peerAddress)
|
public void onResultGetPeerAddress(PeerAddress peerAddress)
|
||||||
{
|
{
|
||||||
log.debug(" called");
|
log.debug("onResultGetPeerAddress called " + position++);
|
||||||
this.peerAddress = peerAddress;
|
this.peerAddress = peerAddress;
|
||||||
|
|
||||||
RequestTakeOffer.run(this::onResultRequestTakeOffer, this::onFault, peerAddress, messageFacade, tradeId);
|
|
||||||
state = State.RequestTakeOffer;
|
state = State.RequestTakeOffer;
|
||||||
|
RequestTakeOffer.run(this::onResultRequestTakeOffer, this::onFault, peerAddress, messageFacade, tradeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultRequestTakeOffer()
|
public void onResultRequestTakeOffer()
|
||||||
{
|
{
|
||||||
log.debug(" called");
|
log.debug("onResultRequestTakeOffer called " + position++);
|
||||||
listener.onWaitingForPeerResponse(state);
|
listener.onWaitingForPeerResponse(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,14 +163,15 @@ public class ProtocolForTakerAsSeller
|
||||||
|
|
||||||
public void onRespondToTakeOfferRequestMessage(RespondToTakeOfferRequestMessage message)
|
public void onRespondToTakeOfferRequestMessage(RespondToTakeOfferRequestMessage message)
|
||||||
{
|
{
|
||||||
log.debug("onRespondToTakeOfferRequestMessage called");
|
log.debug("onRespondToTakeOfferRequestMessage called " + position++);
|
||||||
|
log.debug("state " + state);
|
||||||
checkState(state == State.RequestTakeOffer);
|
checkState(state == State.RequestTakeOffer);
|
||||||
checkArgument(tradeId.equals(message.getTradeId()));
|
checkArgument(tradeId.equals(message.getTradeId()));
|
||||||
|
|
||||||
if (message.isTakeOfferRequestAccepted())
|
if (message.isTakeOfferRequestAccepted())
|
||||||
{
|
{
|
||||||
PayTakeOfferFee.run(this::onResultPayTakeOfferFee, this::onFault, walletFacade, tradeId);
|
|
||||||
state = State.PayTakeOfferFee;
|
state = State.PayTakeOfferFee;
|
||||||
|
PayTakeOfferFee.run(this::onResultPayTakeOfferFee, this::onFault, walletFacade, tradeId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -184,16 +181,16 @@ public class ProtocolForTakerAsSeller
|
||||||
|
|
||||||
public void onResultPayTakeOfferFee(String takeOfferFeeTxId)
|
public void onResultPayTakeOfferFee(String takeOfferFeeTxId)
|
||||||
{
|
{
|
||||||
log.debug("onResultPayTakeOfferFee called");
|
log.debug("onResultPayTakeOfferFee called " + position++);
|
||||||
trade.setTakeOfferFeeTxID(takeOfferFeeTxId);
|
trade.setTakeOfferFeeTxID(takeOfferFeeTxId);
|
||||||
|
|
||||||
SendTakeOfferFeePayedTxId.run(this::onResultSendTakeOfferFeePayedTxId, this::onFault, peerAddress, messageFacade, tradeId, takeOfferFeeTxId, tradeAmount, pubKeyForThatTrade);
|
|
||||||
state = State.SendTakeOfferFeePayedTxId;
|
state = State.SendTakeOfferFeePayedTxId;
|
||||||
|
SendTakeOfferFeePayedTxId.run(this::onResultSendTakeOfferFeePayedTxId, this::onFault, peerAddress, messageFacade, tradeId, takeOfferFeeTxId, tradeAmount, pubKeyForThatTrade);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultSendTakeOfferFeePayedTxId()
|
public void onResultSendTakeOfferFeePayedTxId()
|
||||||
{
|
{
|
||||||
log.debug("onResultSendTakeOfferFeePayedTxId called");
|
log.debug("onResultSendTakeOfferFeePayedTxId called " + position++);
|
||||||
listener.onWaitingForPeerResponse(state);
|
listener.onWaitingForPeerResponse(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +201,8 @@ public class ProtocolForTakerAsSeller
|
||||||
|
|
||||||
public void onRequestTakerDepositPaymentMessage(RequestTakerDepositPaymentMessage message)
|
public void onRequestTakerDepositPaymentMessage(RequestTakerDepositPaymentMessage message)
|
||||||
{
|
{
|
||||||
log.debug("onRequestTakerDepositPaymentMessage called");
|
log.debug("onRequestTakerDepositPaymentMessage called " + position++);
|
||||||
|
log.debug("state " + state);
|
||||||
|
|
||||||
// validation
|
// validation
|
||||||
checkState(state == State.SendTakeOfferFeePayedTxId);
|
checkState(state == State.SendTakeOfferFeePayedTxId);
|
||||||
|
@ -224,14 +222,15 @@ public class ProtocolForTakerAsSeller
|
||||||
this.peersTxOutIndex = offererTxOutIndex;
|
this.peersTxOutIndex = offererTxOutIndex;
|
||||||
|
|
||||||
// next task
|
// next task
|
||||||
VerifyOffererAccount.run(this::onResultVerifyOffererAccount, this::onFault, blockChainFacade, peersAccountId, peersBankAccount);
|
|
||||||
state = State.VerifyOffererAccount;
|
state = State.VerifyOffererAccount;
|
||||||
|
VerifyOffererAccount.run(this::onResultVerifyOffererAccount, this::onFault, blockChainFacade, peersAccountId, peersBankAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultVerifyOffererAccount()
|
public void onResultVerifyOffererAccount()
|
||||||
{
|
{
|
||||||
log.debug("onResultVerifyOffererAccount called");
|
log.debug("onResultVerifyOffererAccount called " + position++);
|
||||||
String takeOfferFeeTxId = trade.getTakeOfferFeeTxId();
|
String takeOfferFeeTxId = trade.getTakeOfferFeeTxId();
|
||||||
|
state = State.CreateAndSignContract;
|
||||||
CreateAndSignContract.run(this::onResultCreateAndSignContract,
|
CreateAndSignContract.run(this::onResultCreateAndSignContract,
|
||||||
this::onFault,
|
this::onFault,
|
||||||
cryptoFacade,
|
cryptoFacade,
|
||||||
|
@ -245,27 +244,27 @@ public class ProtocolForTakerAsSeller
|
||||||
peersAccountId,
|
peersAccountId,
|
||||||
peersBankAccount,
|
peersBankAccount,
|
||||||
accountKey);
|
accountKey);
|
||||||
state = State.CreateAndSignContract;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultCreateAndSignContract(Contract contract, String contractAsJson, String signature)
|
public void onResultCreateAndSignContract(Contract contract, String contractAsJson, String signature)
|
||||||
{
|
{
|
||||||
log.debug("onResultCreateAndSignContract called");
|
log.debug("onResultCreateAndSignContract called " + position++);
|
||||||
|
|
||||||
trade.setContract(contract);
|
trade.setContract(contract);
|
||||||
trade.setContractAsJson(contractAsJson);
|
trade.setContractAsJson(contractAsJson);
|
||||||
trade.setContractTakerSignature(signature);
|
trade.setContractTakerSignature(signature);
|
||||||
|
|
||||||
PayDeposit.run(this::onResultPayDeposit, this::onFault, walletFacade, collateral, tradeAmount, tradeId, pubKeyForThatTrade, arbitratorPubKey, peersPubKey, preparedPeersDepositTxAsHex);
|
|
||||||
state = State.PayDeposit;
|
state = State.PayDeposit;
|
||||||
|
PayDeposit.run(this::onResultPayDeposit, this::onFault, walletFacade, collateral, tradeAmount, tradeId, pubKeyForThatTrade, arbitratorPubKey, peersPubKey, preparedPeersDepositTxAsHex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultPayDeposit(Transaction signedTakerDepositTx)
|
public void onResultPayDeposit(Transaction signedTakerDepositTx)
|
||||||
{
|
{
|
||||||
log.debug("onResultPayDeposit called");
|
log.debug("onResultPayDeposit called " + position++);
|
||||||
String contractAsJson = trade.getContractAsJson();
|
String contractAsJson = trade.getContractAsJson();
|
||||||
String takerSignature = trade.getTakerSignature();
|
String takerSignature = trade.getTakerSignature();
|
||||||
|
|
||||||
|
state = State.SendSignedTakerDepositTxAsHex;
|
||||||
SendSignedTakerDepositTxAsHex.run(this::onResultSendSignedTakerDepositTxAsHex,
|
SendSignedTakerDepositTxAsHex.run(this::onResultSendSignedTakerDepositTxAsHex,
|
||||||
this::onFault,
|
this::onFault,
|
||||||
peerAddress,
|
peerAddress,
|
||||||
|
@ -279,12 +278,11 @@ public class ProtocolForTakerAsSeller
|
||||||
takerSignature,
|
takerSignature,
|
||||||
signedTakerDepositTx,
|
signedTakerDepositTx,
|
||||||
peersTxOutIndex);
|
peersTxOutIndex);
|
||||||
state = State.SendSignedTakerDepositTxAsHex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultSendSignedTakerDepositTxAsHex()
|
public void onResultSendSignedTakerDepositTxAsHex()
|
||||||
{
|
{
|
||||||
log.debug(" called");
|
log.debug("onResultSendSignedTakerDepositTxAsHex called " + position++);
|
||||||
listener.onWaitingForPeerResponse(state);
|
listener.onWaitingForPeerResponse(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,10 +294,10 @@ public class ProtocolForTakerAsSeller
|
||||||
// informational, does only trigger UI feedback/update
|
// informational, does only trigger UI feedback/update
|
||||||
public void onDepositTxPublishedMessage(DepositTxPublishedMessage message)
|
public void onDepositTxPublishedMessage(DepositTxPublishedMessage message)
|
||||||
{
|
{
|
||||||
log.debug("onDepositTxPublishedMessage called");
|
log.debug("onDepositTxPublishedMessage called " + position++);
|
||||||
checkState(state.ordinal() > State.SendSignedTakerDepositTxAsHex.ordinal() && state.ordinal() < State.SignAndPublishPayoutTx.ordinal());
|
log.debug("state " + state);
|
||||||
|
checkState(state.ordinal() >= State.SendSignedTakerDepositTxAsHex.ordinal());
|
||||||
checkArgument(tradeId.equals(message.getTradeId()));
|
checkArgument(tradeId.equals(message.getTradeId()));
|
||||||
state = State.onDepositTxPublishedMessage;
|
|
||||||
listener.onDepositTxPublished(walletFacade.takerCommitDepositTx(message.getDepositTxAsHex()));
|
listener.onDepositTxPublished(walletFacade.takerCommitDepositTx(message.getDepositTxAsHex()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,10 +309,10 @@ public class ProtocolForTakerAsSeller
|
||||||
// informational, store data for later, does only trigger UI feedback/update
|
// informational, store data for later, does only trigger UI feedback/update
|
||||||
public void onBankTransferInitedMessage(BankTransferInitedMessage message)
|
public void onBankTransferInitedMessage(BankTransferInitedMessage message)
|
||||||
{
|
{
|
||||||
log.debug("onBankTransferInitedMessage called");
|
log.debug("onBankTransferInitedMessage called " + position++);
|
||||||
|
log.debug("state " + state);
|
||||||
// validate
|
// 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()));
|
checkArgument(tradeId.equals(message.getTradeId()));
|
||||||
String depositTxAsHex = nonEmptyStringOf(message.getDepositTxAsHex());
|
String depositTxAsHex = nonEmptyStringOf(message.getDepositTxAsHex());
|
||||||
String offererSignatureR = nonEmptyStringOf(message.getOffererSignatureR());
|
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
|
// User clicked the "bank transfer received" button, so we release the funds for pay out
|
||||||
public void onUIEventFiatReceived()
|
public void onUIEventFiatReceived()
|
||||||
{
|
{
|
||||||
log.debug("onUIEventFiatReceived called");
|
log.debug("onUIEventFiatReceived called " + position++);
|
||||||
|
log.debug("state " + state);
|
||||||
checkState(state.ordinal() > State.SendSignedTakerDepositTxAsHex.ordinal() && state.ordinal() < State.SignAndPublishPayoutTx.ordinal());
|
checkState(state == State.onBankTransferInitedMessage);
|
||||||
state = State.onUIEventFiatReceived;
|
|
||||||
|
|
||||||
|
state = State.SignAndPublishPayoutTx;
|
||||||
SignAndPublishPayoutTx.run(this::onResultSignAndPublishPayoutTx,
|
SignAndPublishPayoutTx.run(this::onResultSignAndPublishPayoutTx,
|
||||||
this::onFault,
|
this::onFault,
|
||||||
walletFacade,
|
walletFacade,
|
||||||
|
@ -358,21 +356,20 @@ public class ProtocolForTakerAsSeller
|
||||||
offererPaybackAmount,
|
offererPaybackAmount,
|
||||||
takerPaybackAmount,
|
takerPaybackAmount,
|
||||||
offererPayoutAddress);
|
offererPayoutAddress);
|
||||||
state = State.SignAndPublishPayoutTx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultSignAndPublishPayoutTx(String transactionId, String payoutTxAsHex)
|
public void onResultSignAndPublishPayoutTx(String transactionId, String payoutTxAsHex)
|
||||||
{
|
{
|
||||||
log.debug("onResultSignAndPublishPayoutTx called");
|
log.debug("onResultSignAndPublishPayoutTx called " + position++);
|
||||||
listener.onPayoutTxPublished(trade, transactionId);
|
listener.onPayoutTxPublished(trade, transactionId);
|
||||||
|
|
||||||
SendPayoutTxToOfferer.run(this::onResultSendPayoutTxToOfferer, this::onFault, peerAddress, messageFacade, tradeId, payoutTxAsHex);
|
|
||||||
state = State.SendPayoutTxToOfferer;
|
state = State.SendPayoutTxToOfferer;
|
||||||
|
SendPayoutTxToOfferer.run(this::onResultSendPayoutTxToOfferer, this::onFault, peerAddress, messageFacade, tradeId, payoutTxAsHex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResultSendPayoutTxToOfferer()
|
public void onResultSendPayoutTxToOfferer()
|
||||||
{
|
{
|
||||||
log.debug("onResultSendPayoutTxToOfferer called");
|
log.debug("onResultSendPayoutTxToOfferer called " + position++);
|
||||||
listener.onCompleted(state);
|
listener.onCompleted(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +380,7 @@ public class ProtocolForTakerAsSeller
|
||||||
|
|
||||||
public String getId()
|
public String getId()
|
||||||
{
|
{
|
||||||
return id;
|
return tradeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ public class RequestTakeOffer
|
||||||
|
|
||||||
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, PeerAddress peerAddress, MessageFacade messageFacade, String tradeId)
|
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()
|
messageFacade.sendTradeMessage(peerAddress, new RequestTakeOfferMessage(tradeId), new OutgoingTradeMessageListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -14,6 +14,7 @@ public class SendPayoutTxToOfferer
|
||||||
|
|
||||||
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, PeerAddress peerAddress, MessageFacade messageFacade, String tradeId, String payoutTxAsHex)
|
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);
|
PayoutTxPublishedMessage tradeMessage = new PayoutTxPublishedMessage(tradeId, payoutTxAsHex);
|
||||||
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener()
|
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener()
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,6 +30,7 @@ public class SendSignedTakerDepositTxAsHex
|
||||||
Transaction signedTakerDepositTx,
|
Transaction signedTakerDepositTx,
|
||||||
long offererTxOutIndex)
|
long offererTxOutIndex)
|
||||||
{
|
{
|
||||||
|
log.trace("Run task");
|
||||||
long takerTxOutIndex = signedTakerDepositTx.getInput(1).getOutpoint().getIndex();
|
long takerTxOutIndex = signedTakerDepositTx.getInput(1).getOutpoint().getIndex();
|
||||||
|
|
||||||
RequestOffererPublishDepositTxMessage tradeMessage = new RequestOffererPublishDepositTxMessage(tradeId,
|
RequestOffererPublishDepositTxMessage tradeMessage = new RequestOffererPublishDepositTxMessage(tradeId,
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class SendTakeOfferFeePayedTxId
|
||||||
BigInteger tradeAmount,
|
BigInteger tradeAmount,
|
||||||
String pubKeyForThatTradeAsHex)
|
String pubKeyForThatTradeAsHex)
|
||||||
{
|
{
|
||||||
|
log.trace("Run task");
|
||||||
TakeOfferFeePayedMessage msg = new TakeOfferFeePayedMessage(tradeId, takeOfferFeeTxId, tradeAmount, pubKeyForThatTradeAsHex);
|
TakeOfferFeePayedMessage msg = new TakeOfferFeePayedMessage(tradeId, takeOfferFeeTxId, tradeAmount, pubKeyForThatTradeAsHex);
|
||||||
|
|
||||||
messageFacade.sendTradeMessage(peerAddress, msg, new OutgoingTradeMessageListener()
|
messageFacade.sendTradeMessage(peerAddress, msg, new OutgoingTradeMessageListener()
|
||||||
|
|
|
@ -24,6 +24,7 @@ public class SignAndPublishPayoutTx
|
||||||
BigInteger takerPaybackAmount,
|
BigInteger takerPaybackAmount,
|
||||||
String offererPayoutAddress)
|
String offererPayoutAddress)
|
||||||
{
|
{
|
||||||
|
log.trace("Run task");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ public class VerifyOffererAccount
|
||||||
|
|
||||||
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, BlockChainFacade blockChainFacade, String peersAccountId, BankAccount peersBankAccount)
|
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);
|
VerifyPeerAccount.run(resultHandler, faultHandler, blockChainFacade, peersAccountId, peersBankAccount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue