use of bisq.core.trade.messages.DepositTxPublishedMessage in project bisq-core by bisq-network.
the class TakerSendDepositTxPublishedMessage method run.
@Override
protected void run() {
try {
runInterceptHook();
if (trade.getDepositTx() != null) {
final String id = processModel.getOfferId();
DepositTxPublishedMessage message = new DepositTxPublishedMessage(processModel.getOfferId(), trade.getDepositTx().bitcoinSerialize(), processModel.getMyNodeAddress(), UUID.randomUUID().toString());
trade.setState(Trade.State.TAKER_SENT_DEPOSIT_TX_PUBLISHED_MSG);
processModel.getP2PService().sendEncryptedMailboxMessage(trade.getTradingPeerNodeAddress(), processModel.getTradingPeer().getPubKeyRing(), message, new SendMailboxMessageListener() {
@Override
public void onArrived() {
log.info("Message arrived at peer. tradeId={}", id);
trade.setState(Trade.State.TAKER_SAW_ARRIVED_DEPOSIT_TX_PUBLISHED_MSG);
complete();
}
@Override
public void onStoredInMailbox() {
log.info("Message stored in mailbox. tradeId={}", id);
trade.setState(Trade.State.TAKER_STORED_IN_MAILBOX_DEPOSIT_TX_PUBLISHED_MSG);
complete();
}
@Override
public void onFault(String errorMessage) {
log.error("sendEncryptedMailboxMessage failed. message=" + message);
trade.setState(Trade.State.TAKER_SEND_FAILED_DEPOSIT_TX_PUBLISHED_MSG);
appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage);
failed();
}
});
} else {
log.error("trade.getDepositTx() = " + trade.getDepositTx());
failed("DepositTx is null");
}
} catch (Throwable t) {
failed(t);
}
}
use of bisq.core.trade.messages.DepositTxPublishedMessage in project bisq-core by bisq-network.
the class SellerAsMakerProtocol method doApplyMailboxMessage.
// /////////////////////////////////////////////////////////////////////////////////////////
// Mailbox
// /////////////////////////////////////////////////////////////////////////////////////////
@Override
public void doApplyMailboxMessage(NetworkEnvelope networkEnvelop, Trade trade) {
this.trade = trade;
NodeAddress peerNodeAddress = ((MailboxMessage) networkEnvelop).getSenderNodeAddress();
if (networkEnvelop instanceof DepositTxPublishedMessage)
handle((DepositTxPublishedMessage) networkEnvelop, peerNodeAddress);
else if (networkEnvelop instanceof CounterCurrencyTransferStartedMessage)
handle((CounterCurrencyTransferStartedMessage) networkEnvelop, peerNodeAddress);
else
log.error("We received an unhandled MailboxMessage" + networkEnvelop.toString());
}
use of bisq.core.trade.messages.DepositTxPublishedMessage in project bisq-core by bisq-network.
the class BuyerAsMakerProtocol method doApplyMailboxMessage.
// /////////////////////////////////////////////////////////////////////////////////////////
// Mailbox
// /////////////////////////////////////////////////////////////////////////////////////////
@Override
public void doApplyMailboxMessage(NetworkEnvelope networkEnvelop, Trade trade) {
this.trade = trade;
if (networkEnvelop instanceof MailboxMessage) {
MailboxMessage mailboxMessage = (MailboxMessage) networkEnvelop;
NodeAddress peerNodeAddress = mailboxMessage.getSenderNodeAddress();
if (networkEnvelop instanceof DepositTxPublishedMessage)
handle((DepositTxPublishedMessage) networkEnvelop, peerNodeAddress);
else if (networkEnvelop instanceof PayoutTxPublishedMessage)
handle((PayoutTxPublishedMessage) networkEnvelop, peerNodeAddress);
else
log.error("We received an unhandled MailboxMessage" + networkEnvelop.toString());
}
}
use of bisq.core.trade.messages.DepositTxPublishedMessage in project bisq-core by bisq-network.
the class MakerProcessDepositTxPublishedMessage method run.
@Override
protected void run() {
try {
runInterceptHook();
log.debug("current trade state " + trade.getState());
DepositTxPublishedMessage message = (DepositTxPublishedMessage) processModel.getTradeMessage();
Validator.checkTradeId(processModel.getOfferId(), message);
checkNotNull(message);
checkArgument(message.getDepositTx() != null);
// To access tx confidence we need to add that tx into our wallet.
Transaction txFromSerializedTx = processModel.getBtcWalletService().getTxFromSerializedTx(message.getDepositTx());
// update with full tx
Transaction walletTx = processModel.getTradeWalletService().addTxToWallet(txFromSerializedTx);
trade.setDepositTx(walletTx);
BtcWalletService.printTx("depositTx received from peer", walletTx);
// update to the latest peer address of our peer if the message is correct
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
processModel.removeMailboxMessageAfterProcessing(trade);
// If we got already the confirmation we don't want to apply an earlier state
if (trade.getState() != Trade.State.MAKER_SAW_DEPOSIT_TX_IN_NETWORK)
trade.setState(Trade.State.MAKER_RECEIVED_DEPOSIT_TX_PUBLISHED_MSG);
processModel.getBtcWalletService().swapTradeEntryToAvailableEntry(trade.getId(), AddressEntry.Context.RESERVED_FOR_TRADE);
complete();
} catch (Throwable t) {
failed(t);
}
}
Aggregations