use of io.bitsquare.trade.protocol.trade.messages.FinalizePayoutTxRequest 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);
}
}
}
use of io.bitsquare.trade.protocol.trade.messages.FinalizePayoutTxRequest in project bitsquare by bitsquare.
the class SendFinalizePayoutTxRequest method run.
@Override
protected void run() {
try {
runInterceptHook();
if (trade.getTradingPeerNodeAddress() != null) {
WalletService walletService = processModel.getWalletService();
AddressEntry sellerPayoutAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
FinalizePayoutTxRequest message = new FinalizePayoutTxRequest(processModel.getId(), processModel.getPayoutTxSignature(), sellerPayoutAddressEntry.getAddressString(), trade.getLockTimeAsBlockHeight(), processModel.getMyNodeAddress());
processModel.getP2PService().sendEncryptedMailboxMessage(trade.getTradingPeerNodeAddress(), processModel.tradingPeer.getPubKeyRing(), message, new SendMailboxMessageListener() {
@Override
public void onArrived() {
log.trace("Message arrived at peer.");
trade.setState(Trade.State.SELLER_SENT_FIAT_PAYMENT_RECEIPT_MSG);
complete();
}
@Override
public void onStoredInMailbox() {
log.trace("Message stored in mailbox.");
trade.setState(Trade.State.SELLER_SENT_FIAT_PAYMENT_RECEIPT_MSG);
complete();
}
@Override
public void onFault(String errorMessage) {
appendToErrorMessage("FinalizePayoutTxRequest sending failed. errorMessage=" + errorMessage);
failed(errorMessage);
}
});
} else {
log.error("trade.getTradingPeerAddress() = " + trade.getTradingPeerNodeAddress());
failed("A needed dependency is null");
}
} catch (Throwable t) {
failed(t);
}
}
use of io.bitsquare.trade.protocol.trade.messages.FinalizePayoutTxRequest in project bitsquare by bitsquare.
the class ProcessFinalizePayoutTxRequest method run.
@Override
protected void run() {
try {
runInterceptHook();
log.debug("current trade state " + trade.getState());
FinalizePayoutTxRequest message = (FinalizePayoutTxRequest) processModel.getTradeMessage();
checkTradeId(processModel.getId(), message);
checkNotNull(message);
processModel.tradingPeer.setSignature(checkNotNull(message.sellerSignature));
processModel.tradingPeer.setPayoutAddressString(nonEmptyStringOf(message.sellerPayoutAddress));
trade.setLockTimeAsBlockHeight(nonNegativeLongOf(message.lockTimeAsBlockHeight));
// update to the latest peer address of our peer if the message is correct
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
removeMailboxMessageAfterProcessing();
trade.setState(Trade.State.BUYER_RECEIVED_FIAT_PAYMENT_RECEIPT_MSG);
complete();
} catch (Throwable t) {
failed(t);
}
}
Aggregations