use of bisq.common.crypto.PubKeyRing in project bisq-core by bisq-network.
the class DisputeManager method sendPeerPublishedPayoutTxMessage.
// winner (or buyer in case of 50/50) sends tx to other peer
private void sendPeerPublishedPayoutTxMessage(Transaction transaction, Dispute dispute, Contract contract) {
PubKeyRing peersPubKeyRing = dispute.isDisputeOpenerIsBuyer() ? contract.getSellerPubKeyRing() : contract.getBuyerPubKeyRing();
NodeAddress peerNodeAddress = dispute.isDisputeOpenerIsBuyer() ? contract.getSellerNodeAddress() : contract.getBuyerNodeAddress();
log.trace("sendPeerPublishedPayoutTxMessage to peerAddress " + peerNodeAddress);
final PeerPublishedDisputePayoutTxMessage message = new PeerPublishedDisputePayoutTxMessage(transaction.bitcoinSerialize(), dispute.getTradeId(), p2PService.getAddress(), UUID.randomUUID().toString());
p2PService.sendEncryptedMailboxMessage(peerNodeAddress, peersPubKeyRing, message, new SendMailboxMessageListener() {
@Override
public void onArrived() {
log.info("Message arrived at peer. tradeId={}", message.getTradeId());
}
@Override
public void onStoredInMailbox() {
log.info("Message stored in mailbox. tradeId={}", message.getTradeId());
}
@Override
public void onFault(String errorMessage) {
log.error("sendEncryptedMailboxMessage failed. message=" + message);
}
});
}
use of bisq.common.crypto.PubKeyRing in project bisq-core by bisq-network.
the class DisputeManager method sendPeerOpenedDisputeMessage.
// arbitrator sends that to trading peer when he received openDispute request
private void sendPeerOpenedDisputeMessage(Dispute disputeFromOpener) {
Contract contractFromOpener = disputeFromOpener.getContract();
PubKeyRing pubKeyRing = disputeFromOpener.isDisputeOpenerIsBuyer() ? contractFromOpener.getSellerPubKeyRing() : contractFromOpener.getBuyerPubKeyRing();
Dispute dispute = new Dispute(disputeStorage, disputeFromOpener.getTradeId(), pubKeyRing.hashCode(), !disputeFromOpener.isDisputeOpenerIsBuyer(), !disputeFromOpener.isDisputeOpenerIsMaker(), pubKeyRing, disputeFromOpener.getTradeDate().getTime(), contractFromOpener, disputeFromOpener.getContractHash(), disputeFromOpener.getDepositTxSerialized(), disputeFromOpener.getPayoutTxSerialized(), disputeFromOpener.getDepositTxId(), disputeFromOpener.getPayoutTxId(), disputeFromOpener.getContractAsJson(), disputeFromOpener.getMakerContractSignature(), disputeFromOpener.getTakerContractSignature(), disputeFromOpener.getArbitratorPubKeyRing(), disputeFromOpener.isSupportTicket());
final Optional<Dispute> storedDisputeOptional = findDispute(dispute.getTradeId(), dispute.getTraderId());
if (!storedDisputeOptional.isPresent()) {
String sysMsg = dispute.isSupportTicket() ? Res.get("support.peerOpenedTicket") : Res.get("support.peerOpenedDispute", disputeInfo);
DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(dispute.getTradeId(), keyRing.getPubKeyRing().hashCode(), false, Res.get("support.systemMsg", sysMsg), null, p2PService.getAddress(), new Date().getTime(), false, false, UUID.randomUUID().toString());
disputeCommunicationMessage.setSystemMessage(true);
dispute.addDisputeMessage(disputeCommunicationMessage);
disputes.add(dispute);
// we mirrored dispute already!
Contract contract = dispute.getContract();
PubKeyRing peersPubKeyRing = dispute.isDisputeOpenerIsBuyer() ? contract.getBuyerPubKeyRing() : contract.getSellerPubKeyRing();
NodeAddress peerNodeAddress = dispute.isDisputeOpenerIsBuyer() ? contract.getBuyerNodeAddress() : contract.getSellerNodeAddress();
log.trace("sendPeerOpenedDisputeMessage to peerAddress " + peerNodeAddress);
p2PService.sendEncryptedMailboxMessage(peerNodeAddress, peersPubKeyRing, new PeerOpenedDisputeMessage(dispute, 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);
}
});
} else {
log.warn("We got a dispute already open for that trade and trading peer.\n" + "TradeId = " + dispute.getTradeId());
}
}
use of bisq.common.crypto.PubKeyRing in project bisq-core by bisq-network.
the class VerifyPeersAccountAgeWitness method run.
@Override
protected void run() {
try {
runInterceptHook();
if (CurrencyUtil.isFiatCurrency(trade.getOffer().getCurrencyCode())) {
final AccountAgeWitnessService accountAgeWitnessService = processModel.getAccountAgeWitnessService();
final TradingPeer tradingPeer = processModel.getTradingPeer();
final PaymentAccountPayload peersPaymentAccountPayload = checkNotNull(tradingPeer.getPaymentAccountPayload(), "Peers peersPaymentAccountPayload must not be null");
final PubKeyRing peersPubKeyRing = checkNotNull(tradingPeer.getPubKeyRing(), "peersPubKeyRing must not be null");
byte[] nonce = tradingPeer.getAccountAgeWitnessNonce();
byte[] signature = tradingPeer.getAccountAgeWitnessSignature();
if (nonce != null && signature != null) {
final String[] errorMsg = new String[1];
long currentDateAsLong = tradingPeer.getCurrentDate();
// In case the peer has an older version we get 0, so we use our time instead
final Date peersCurrentDate = currentDateAsLong > 0 ? new Date(currentDateAsLong) : new Date();
boolean result = accountAgeWitnessService.verifyAccountAgeWitness(trade, peersPaymentAccountPayload, peersCurrentDate, peersPubKeyRing, nonce, signature, errorMessage -> errorMsg[0] = errorMessage);
if (result)
complete();
else
failed(errorMsg[0]);
} else {
String msg = "Seems that offer was created with an application before v0.6 which did not support the account age witness verification.";
msg += "\nTrade ID=" + trade.getId();
if (new Date().after(AccountAgeWitnessService.FULL_ACTIVATION)) {
msg = "The account age witness verification failed.\nReason: " + msg + "\nAfter first of Feb. 2018 we don't support old offers without account age witness verification anymore.";
log.error(msg);
failed(msg);
} else {
log.warn(msg + "\nWe tolerate offers without account age witness until first of Feb. 2018");
complete();
}
}
} else {
complete();
}
} catch (Throwable t) {
failed(t);
}
}
use of bisq.common.crypto.PubKeyRing in project bisq-desktop by bisq-network.
the class TraderDisputeView method initialize.
@Override
public void initialize() {
Label label = new AutoTooltipLabel(Res.get("support.filter"));
HBox.setMargin(label, new Insets(5, 0, 0, 0));
filterTextField = new InputTextField();
filterTextField.setText("open");
filterTextFieldListener = (observable, oldValue, newValue) -> applyFilteredListPredicate(filterTextField.getText());
filterBox = new HBox();
filterBox.setSpacing(5);
filterBox.getChildren().addAll(label, filterTextField);
VBox.setVgrow(filterBox, Priority.NEVER);
filterBox.setVisible(false);
filterBox.setManaged(false);
tableView = new TableView<>();
VBox.setVgrow(tableView, Priority.SOMETIMES);
tableView.setMinHeight(150);
root.getChildren().addAll(filterBox, tableView);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
Label placeholder = new AutoTooltipLabel(Res.get("support.noTickets"));
placeholder.setWrapText(true);
tableView.setPlaceholder(placeholder);
tableView.getSelectionModel().clearSelection();
tableView.getColumns().add(getSelectColumn());
TableColumn<Dispute, Dispute> contractColumn = getContractColumn();
tableView.getColumns().add(contractColumn);
TableColumn<Dispute, Dispute> dateColumn = getDateColumn();
tableView.getColumns().add(dateColumn);
TableColumn<Dispute, Dispute> tradeIdColumn = getTradeIdColumn();
tableView.getColumns().add(tradeIdColumn);
TableColumn<Dispute, Dispute> buyerOnionAddressColumn = getBuyerOnionAddressColumn();
tableView.getColumns().add(buyerOnionAddressColumn);
TableColumn<Dispute, Dispute> sellerOnionAddressColumn = getSellerOnionAddressColumn();
tableView.getColumns().add(sellerOnionAddressColumn);
TableColumn<Dispute, Dispute> marketColumn = getMarketColumn();
tableView.getColumns().add(marketColumn);
TableColumn<Dispute, Dispute> roleColumn = getRoleColumn();
tableView.getColumns().add(roleColumn);
TableColumn<Dispute, Dispute> stateColumn = getStateColumn();
tableView.getColumns().add(stateColumn);
tradeIdColumn.setComparator((o1, o2) -> o1.getTradeId().compareTo(o2.getTradeId()));
dateColumn.setComparator((o1, o2) -> o1.getOpeningDate().compareTo(o2.getOpeningDate()));
buyerOnionAddressColumn.setComparator((o1, o2) -> getBuyerOnionAddressColumnLabel(o1).compareTo(getBuyerOnionAddressColumnLabel(o2)));
sellerOnionAddressColumn.setComparator((o1, o2) -> getSellerOnionAddressColumnLabel(o1).compareTo(getSellerOnionAddressColumnLabel(o2)));
marketColumn.setComparator((o1, o2) -> formatter.getCurrencyPair(o1.getContract().getOfferPayload().getCurrencyCode()).compareTo(o2.getContract().getOfferPayload().getCurrencyCode()));
dateColumn.setSortType(TableColumn.SortType.DESCENDING);
tableView.getSortOrder().add(dateColumn);
/*inputTextAreaListener = (observable, oldValue, newValue) ->
sendButton.setDisable(newValue.length() == 0
&& tempAttachments.size() == 0 &&
selectedDispute.disputeResultProperty().get() == null);*/
selectedDisputeClosedPropertyListener = (observable, oldValue, newValue) -> {
messagesInputBox.setVisible(!newValue);
messagesInputBox.setManaged(!newValue);
AnchorPane.setBottomAnchor(messageListView, newValue ? 0d : 120d);
};
disputeDirectMessageListListener = c -> scrollToBottom();
keyEventEventHandler = event -> {
if (Utilities.isAltOrCtrlPressed(KeyCode.L, event)) {
Map<String, List<Dispute>> map = new HashMap<>();
disputeManager.getDisputesAsObservableList().stream().forEach(dispute -> {
String tradeId = dispute.getTradeId();
List<Dispute> list;
if (!map.containsKey(tradeId))
map.put(tradeId, new ArrayList<>());
list = map.get(tradeId);
list.add(dispute);
});
List<List<Dispute>> disputeGroups = new ArrayList<>();
map.entrySet().stream().forEach(entry -> disputeGroups.add(entry.getValue()));
disputeGroups.sort((o1, o2) -> !o1.isEmpty() && !o2.isEmpty() ? o1.get(0).getOpeningDate().compareTo(o2.get(0).getOpeningDate()) : 0);
StringBuilder stringBuilder = new StringBuilder();
// We don't translate that as it is not intended for the public
stringBuilder.append("Summary of all disputes (No. of disputes: ").append(disputeGroups.size()).append(")\n\n");
disputeGroups.stream().forEach(disputeGroup -> {
Dispute dispute0 = disputeGroup.get(0);
stringBuilder.append("##########################################################################################/\n").append("## Trade ID: ").append(dispute0.getTradeId()).append("\n").append("## Date: ").append(formatter.formatDateTime(dispute0.getOpeningDate())).append("\n").append("## Is support ticket: ").append(dispute0.isSupportTicket()).append("\n");
if (dispute0.disputeResultProperty().get() != null && dispute0.disputeResultProperty().get().getReason() != null) {
stringBuilder.append("## Reason: ").append(dispute0.disputeResultProperty().get().getReason()).append("\n");
}
stringBuilder.append("##########################################################################################/\n").append("\n");
disputeGroup.stream().forEach(dispute -> {
stringBuilder.append("*******************************************************************************************\n").append("** Trader's ID: ").append(dispute.getTraderId()).append("\n*******************************************************************************************\n").append("\n");
dispute.getDisputeCommunicationMessages().stream().forEach(m -> {
String role = m.isSenderIsTrader() ? ">> Trader's msg: " : "<< Arbitrator's msg: ";
stringBuilder.append(role).append(m.getMessage()).append("\n");
});
stringBuilder.append("\n");
});
stringBuilder.append("\n");
});
String message = stringBuilder.toString();
// We don't translate that as it is not intended for the public
new Popup<>().headLine("All disputes (" + disputeGroups.size() + ")").information(message).width(1000).actionButtonText("Copy").onAction(() -> Utilities.copyToClipboard(message)).show();
} else if (Utilities.isAltOrCtrlPressed(KeyCode.U, event)) {
// Hidden shortcut to re-open a dispute. Allow it also for traders not only arbitrator.
if (selectedDispute != null) {
if (selectedDisputeClosedPropertyListener != null)
selectedDispute.isClosedProperty().removeListener(selectedDisputeClosedPropertyListener);
selectedDispute.setIsClosed(false);
}
} else if (Utilities.isAltOrCtrlPressed(KeyCode.R, event)) {
if (selectedDispute != null) {
PubKeyRing pubKeyRing = selectedDispute.getTraderPubKeyRing();
NodeAddress nodeAddress;
if (pubKeyRing.equals(selectedDispute.getContract().getBuyerPubKeyRing()))
nodeAddress = selectedDispute.getContract().getBuyerNodeAddress();
else
nodeAddress = selectedDispute.getContract().getSellerNodeAddress();
new SendPrivateNotificationWindow(pubKeyRing, nodeAddress, useDevPrivilegeKeys).onAddAlertMessage(privateNotificationManager::sendPrivateNotificationMessageIfKeyIsValid).show();
}
} else if (Utilities.isAltOrCtrlPressed(KeyCode.ENTER, event)) {
if (selectedDispute != null && messagesInputBox.isVisible() && inputTextArea.isFocused())
onTrySendMessage();
}
};
}
use of bisq.common.crypto.PubKeyRing in project bisq-desktop by bisq-network.
the class PendingTradesDataModel method doOpenDispute.
private void doOpenDispute(boolean isSupportTicket, Transaction depositTx) {
Log.traceCall("depositTx=" + depositTx);
byte[] depositTxSerialized = null;
byte[] payoutTxSerialized = null;
String depositTxHashAsString = null;
String payoutTxHashAsString = null;
if (depositTx != null) {
depositTxSerialized = depositTx.bitcoinSerialize();
depositTxHashAsString = depositTx.getHashAsString();
} else {
log.warn("depositTx is null");
}
Trade trade = getTrade();
if (trade != null) {
Transaction payoutTx = trade.getPayoutTx();
if (payoutTx != null) {
payoutTxSerialized = payoutTx.bitcoinSerialize();
payoutTxHashAsString = payoutTx.getHashAsString();
} else {
log.debug("payoutTx is null at doOpenDispute");
}
final PubKeyRing arbitratorPubKeyRing = trade.getArbitratorPubKeyRing();
checkNotNull(arbitratorPubKeyRing, "arbitratorPubKeyRing must no tbe null");
Dispute dispute = new Dispute(disputeManager.getDisputeStorage(), trade.getId(), // traderId
keyRing.getPubKeyRing().hashCode(), trade.getOffer().getDirection() == OfferPayload.Direction.BUY ? isMaker : !isMaker, isMaker, keyRing.getPubKeyRing(), trade.getDate().getTime(), trade.getContract(), trade.getContractHash(), depositTxSerialized, payoutTxSerialized, depositTxHashAsString, payoutTxHashAsString, trade.getContractAsJson(), trade.getMakerContractSignature(), trade.getTakerContractSignature(), arbitratorPubKeyRing, isSupportTicket);
trade.setDisputeState(Trade.DisputeState.DISPUTE_REQUESTED);
if (p2PService.isBootstrapped()) {
sendOpenNewDisputeMessage(dispute, false);
} else {
new Popup<>().information(Res.get("popup.warning.notFullyConnected")).show();
}
} else {
log.warn("trade is null at doOpenDispute");
}
}
Aggregations