use of io.bitsquare.trade.protocol.trade.messages.DepositTxPublishedMessage in project bitsquare by bitsquare.
the class SendDepositTxPublishedMessage method run.
@Override
protected void run() {
try {
runInterceptHook();
if (trade.getDepositTx() != null) {
DepositTxPublishedMessage tradeMessage = new DepositTxPublishedMessage(processModel.getId(), trade.getDepositTx().bitcoinSerialize(), processModel.getMyNodeAddress());
processModel.getP2PService().sendEncryptedMailboxMessage(trade.getTradingPeerNodeAddress(), processModel.tradingPeer.getPubKeyRing(), tradeMessage, new SendMailboxMessageListener() {
@Override
public void onArrived() {
log.trace("Message arrived at peer.");
trade.setState(Trade.State.TAKER_SENT_DEPOSIT_TX_PUBLISHED_MSG);
complete();
}
@Override
public void onStoredInMailbox() {
log.trace("Message stored in mailbox.");
trade.setState(Trade.State.TAKER_SENT_DEPOSIT_TX_PUBLISHED_MSG);
complete();
}
@Override
public void onFault(String errorMessage) {
appendToErrorMessage("DepositTxPublishedMessage sending failed");
failed();
}
});
} else {
log.error("trade.getDepositTx() = " + trade.getDepositTx());
failed("DepositTx is null");
}
} catch (Throwable t) {
failed(t);
}
}
use of io.bitsquare.trade.protocol.trade.messages.DepositTxPublishedMessage in project bitsquare by bitsquare.
the class ProcessDepositTxPublishedMessage method run.
@Override
protected void run() {
try {
runInterceptHook();
log.debug("current trade state " + trade.getState());
DepositTxPublishedMessage message = (DepositTxPublishedMessage) processModel.getTradeMessage();
checkTradeId(processModel.getId(), message);
checkNotNull(message);
checkArgument(message.depositTx != null);
// To access tx confidence we need to add that tx into our wallet.
Transaction transactionFromSerializedTx = processModel.getWalletService().getTransactionFromSerializedTx(message.depositTx);
// update with full tx
trade.setDepositTx(processModel.getTradeWalletService().addTransactionToWallet(transactionFromSerializedTx));
if (trade instanceof OffererTrade)
processModel.getOpenOfferManager().closeOpenOffer(trade.getOffer());
// update to the latest peer address of our peer if the message is correct
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
removeMailboxMessageAfterProcessing();
trade.setState(Trade.State.OFFERER_RECEIVED_DEPOSIT_TX_PUBLISHED_MSG);
complete();
} catch (Throwable t) {
failed(t);
}
}
use of io.bitsquare.trade.protocol.trade.messages.DepositTxPublishedMessage in project bitsquare by bitsquare.
the class BuyerAsOffererProtocol method doApplyMailboxMessage.
///////////////////////////////////////////////////////////////////////////////////////////
// Mailbox
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void doApplyMailboxMessage(Message message, Trade trade) {
this.trade = trade;
if (message instanceof MailboxMessage) {
MailboxMessage mailboxMessage = (MailboxMessage) message;
NodeAddress peerNodeAddress = mailboxMessage.getSenderNodeAddress();
if (message instanceof FinalizePayoutTxRequest) {
handle((FinalizePayoutTxRequest) message, peerNodeAddress);
} else if (message instanceof DepositTxPublishedMessage) {
handle((DepositTxPublishedMessage) message, peerNodeAddress);
}
}
}
Aggregations