use of bisq.network.p2p.SendMailboxMessageListener in project bisq-core by bisq-network.
the class DisputeManager method sendDisputeDirectMessage.
// traders send msg to the arbitrator or arbitrator to 1 trader (trader to trader is not allowed)
public DisputeCommunicationMessage sendDisputeDirectMessage(Dispute dispute, String text, ArrayList<Attachment> attachments) {
DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(dispute.getTradeId(), dispute.getTraderPubKeyRing().hashCode(), isTrader(dispute), text, null, p2PService.getAddress(), new Date().getTime(), false, false, UUID.randomUUID().toString());
disputeCommunicationMessage.addAllAttachments(attachments);
PubKeyRing receiverPubKeyRing = null;
NodeAddress peerNodeAddress = null;
if (isTrader(dispute)) {
dispute.addDisputeMessage(disputeCommunicationMessage);
receiverPubKeyRing = dispute.getArbitratorPubKeyRing();
peerNodeAddress = dispute.getContract().getArbitratorNodeAddress();
} else if (isArbitrator(dispute)) {
if (!disputeCommunicationMessage.isSystemMessage())
dispute.addDisputeMessage(disputeCommunicationMessage);
receiverPubKeyRing = dispute.getTraderPubKeyRing();
Contract contract = dispute.getContract();
if (contract.getBuyerPubKeyRing().equals(receiverPubKeyRing))
peerNodeAddress = contract.getBuyerNodeAddress();
else
peerNodeAddress = contract.getSellerNodeAddress();
} else {
log.error("That must not happen. Trader cannot communicate to other trader.");
}
if (receiverPubKeyRing != null) {
log.trace("sendDisputeDirectMessage to peerAddress " + peerNodeAddress);
p2PService.sendEncryptedMailboxMessage(peerNodeAddress, receiverPubKeyRing, disputeCommunicationMessage, new SendMailboxMessageListener() {
@Override
public void onArrived() {
log.info("Message arrived at peer. tradeId={}", disputeCommunicationMessage.getTradeId());
disputeCommunicationMessage.setArrived(true);
}
@Override
public void onStoredInMailbox() {
log.info("Message stored in mailbox. tradeId={}", disputeCommunicationMessage.getTradeId());
disputeCommunicationMessage.setStoredInMailbox(true);
}
@Override
public void onFault(String errorMessage) {
log.error("sendEncryptedMailboxMessage failed. disputeCommunicationMessage=" + disputeCommunicationMessage);
}
});
}
return disputeCommunicationMessage;
}
use of bisq.network.p2p.SendMailboxMessageListener in project bisq-core by bisq-network.
the class DisputeManager method sendDisputeResultMessage.
// arbitrator send result to trader
public void sendDisputeResultMessage(DisputeResult disputeResult, Dispute dispute, String text) {
DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(dispute.getTradeId(), dispute.getTraderPubKeyRing().hashCode(), false, text, null, p2PService.getAddress(), new Date().getTime(), false, false, UUID.randomUUID().toString());
dispute.addDisputeMessage(disputeCommunicationMessage);
disputeResult.setDisputeCommunicationMessage(disputeCommunicationMessage);
NodeAddress peerNodeAddress;
Contract contract = dispute.getContract();
if (contract.getBuyerPubKeyRing().equals(dispute.getTraderPubKeyRing()))
peerNodeAddress = contract.getBuyerNodeAddress();
else
peerNodeAddress = contract.getSellerNodeAddress();
p2PService.sendEncryptedMailboxMessage(peerNodeAddress, dispute.getTraderPubKeyRing(), new DisputeResultMessage(disputeResult, p2PService.getAddress(), UUID.randomUUID().toString()), new SendMailboxMessageListener() {
@Override
public void onArrived() {
log.info("Message arrived at peer. tradeId={}", disputeCommunicationMessage.getTradeId());
disputeCommunicationMessage.setArrived(true);
}
@Override
public void onStoredInMailbox() {
log.info("Message stored in mailbox. tradeId={}", disputeCommunicationMessage.getTradeId());
disputeCommunicationMessage.setStoredInMailbox(true);
}
@Override
public void onFault(String errorMessage) {
log.error("sendEncryptedMailboxMessage failed. disputeCommunicationMessage=" + disputeCommunicationMessage);
}
});
}
use of bisq.network.p2p.SendMailboxMessageListener in project bisq-desktop by bisq-network.
the class SendPrivateNotificationWindow method addContent.
private void addContent() {
InputTextField keyInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("shared.unlock"), 10).second;
if (useDevPrivilegeKeys)
keyInputTextField.setText(DevEnv.DEV_PRIVILEGE_PRIV_KEY);
Tuple2<Label, TextArea> labelTextAreaTuple2 = addLabelTextArea(gridPane, ++rowIndex, Res.get("sendPrivateNotificationWindow.privateNotification"), Res.get("sendPrivateNotificationWindow.enterNotification"));
TextArea alertMessageTextArea = labelTextAreaTuple2.second;
Label first = labelTextAreaTuple2.first;
first.setMinWidth(200);
Button sendButton = new AutoTooltipButton(Res.get("sendPrivateNotificationWindow.send"));
sendButton.setOnAction(e -> {
if (alertMessageTextArea.getText().length() > 0 && keyInputTextField.getText().length() > 0) {
if (!sendPrivateNotificationHandler.handle(new PrivateNotificationPayload(alertMessageTextArea.getText()), pubKeyRing, nodeAddress, keyInputTextField.getText(), new SendMailboxMessageListener() {
@Override
public void onArrived() {
log.info("PrivateNotificationMessage arrived at peer.");
new Popup<>().feedback(Res.get("shared.messageArrived")).onClose(SendPrivateNotificationWindow.this::hide).show();
}
@Override
public void onStoredInMailbox() {
log.info("PrivateNotificationMessage was stored in mailbox.");
new Popup<>().feedback(Res.get("shared.messageStoredInMailbox")).onClose(SendPrivateNotificationWindow.this::hide).show();
}
@Override
public void onFault(String errorMessage) {
log.error("sendEncryptedMailboxMessage failed. message=" + message);
new Popup<>().feedback(Res.get("shared.messageSendingFailed", errorMessage)).onClose(SendPrivateNotificationWindow.this::hide).show();
}
}))
new Popup<>().warning(Res.get("shared.invalidKey")).width(300).onClose(this::blurAgain).show();
}
});
closeButton = new AutoTooltipButton(Res.get("shared.close"));
closeButton.setOnAction(e -> {
hide();
closeHandlerOptional.ifPresent(Runnable::run);
});
HBox hBox = new HBox();
hBox.setSpacing(10);
GridPane.setRowIndex(hBox, ++rowIndex);
GridPane.setColumnIndex(hBox, 1);
hBox.getChildren().addAll(sendButton, closeButton);
gridPane.getChildren().add(hBox);
GridPane.setMargin(hBox, new Insets(10, 0, 0, 0));
}
use of bisq.network.p2p.SendMailboxMessageListener in project bisq-core by bisq-network.
the class SellerSendPayoutTxPublishedMessage method run.
@Override
protected void run() {
try {
runInterceptHook();
if (trade.getPayoutTx() != null) {
final String id = processModel.getOfferId();
final PayoutTxPublishedMessage message = new PayoutTxPublishedMessage(id, trade.getPayoutTx().bitcoinSerialize(), processModel.getMyNodeAddress(), UUID.randomUUID().toString());
trade.setState(Trade.State.SELLER_SENT_PAYOUT_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.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG);
complete();
}
@Override
public void onStoredInMailbox() {
log.info("Message stored in mailbox. tradeId={}", id);
trade.setState(Trade.State.SELLER_STORED_IN_MAILBOX_PAYOUT_TX_PUBLISHED_MSG);
complete();
}
@Override
public void onFault(String errorMessage) {
log.error("sendEncryptedMailboxMessage failed. message=" + message);
trade.setState(Trade.State.SELLER_SEND_FAILED_PAYOUT_TX_PUBLISHED_MSG);
appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage);
failed(errorMessage);
}
});
} else {
log.error("trade.getPayoutTx() = " + trade.getPayoutTx());
failed("PayoutTx is null");
}
} catch (Throwable t) {
failed(t);
}
}
use of bisq.network.p2p.SendMailboxMessageListener in project bisq-core by bisq-network.
the class BuyerSendCounterCurrencyTransferStartedMessage method run.
@Override
protected void run() {
try {
runInterceptHook();
BtcWalletService walletService = processModel.getBtcWalletService();
final String id = processModel.getOfferId();
AddressEntry payoutAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT);
final CounterCurrencyTransferStartedMessage message = new CounterCurrencyTransferStartedMessage(id, payoutAddressEntry.getAddressString(), processModel.getMyNodeAddress(), processModel.getPayoutTxSignature(), trade.getCounterCurrencyTxId(), UUID.randomUUID().toString());
log.info("Send message to peer. tradeId={}, message{}", id, message);
trade.setState(Trade.State.BUYER_SENT_FIAT_PAYMENT_INITIATED_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.BUYER_SAW_ARRIVED_FIAT_PAYMENT_INITIATED_MSG);
complete();
}
@Override
public void onStoredInMailbox() {
log.info("Message stored in mailbox. tradeId={}", id);
trade.setState(Trade.State.BUYER_STORED_IN_MAILBOX_FIAT_PAYMENT_INITIATED_MSG);
complete();
}
@Override
public void onFault(String errorMessage) {
log.error("sendEncryptedMailboxMessage failed. message=" + message);
trade.setState(Trade.State.BUYER_SEND_FAILED_FIAT_PAYMENT_INITIATED_MSG);
appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage);
failed(errorMessage);
}
});
} catch (Throwable t) {
failed(t);
}
}
Aggregations