Search in sources :

Example 11 with NodeAddress

use of bisq.network.p2p.NodeAddress in project bisq-core by bisq-network.

the class OfferPayload method fromProto.

public static OfferPayload fromProto(PB.OfferPayload proto) {
    checkArgument(!proto.getOfferFeePaymentTxId().isEmpty(), "OfferFeePaymentTxId must be set in PB.OfferPayload");
    List<String> acceptedBankIds = proto.getAcceptedBankIdsList().isEmpty() ? null : proto.getAcceptedBankIdsList().stream().collect(Collectors.toList());
    List<String> acceptedCountryCodes = proto.getAcceptedCountryCodesList().isEmpty() ? null : proto.getAcceptedCountryCodesList().stream().collect(Collectors.toList());
    String hashOfChallenge = ProtoUtil.stringOrNullFromProto(proto.getHashOfChallenge());
    Map<String, String> extraDataMapMap = CollectionUtils.isEmpty(proto.getExtraDataMap()) ? null : proto.getExtraDataMap();
    return new OfferPayload(proto.getId(), proto.getDate(), NodeAddress.fromProto(proto.getOwnerNodeAddress()), PubKeyRing.fromProto(proto.getPubKeyRing()), OfferPayload.Direction.fromProto(proto.getDirection()), proto.getPrice(), proto.getMarketPriceMargin(), proto.getUseMarketBasedPrice(), proto.getAmount(), proto.getMinAmount(), proto.getBaseCurrencyCode(), proto.getCounterCurrencyCode(), proto.getArbitratorNodeAddressesList().stream().map(NodeAddress::fromProto).collect(Collectors.toList()), proto.getMediatorNodeAddressesList().stream().map(NodeAddress::fromProto).collect(Collectors.toList()), proto.getPaymentMethodId(), proto.getMakerPaymentAccountId(), proto.getOfferFeePaymentTxId(), ProtoUtil.stringOrNullFromProto(proto.getCountryCode()), acceptedCountryCodes, ProtoUtil.stringOrNullFromProto(proto.getBankId()), acceptedBankIds, proto.getVersionNr(), proto.getBlockHeightAtOfferCreation(), proto.getTxFee(), proto.getMakerFee(), proto.getIsCurrencyForMakerFeeBtc(), proto.getBuyerSecurityDeposit(), proto.getSellerSecurityDeposit(), proto.getMaxTradeLimit(), proto.getMaxTradePeriod(), proto.getUseAutoClose(), proto.getUseReOpenAfterAutoClose(), proto.getLowerClosePrice(), proto.getUpperClosePrice(), proto.getIsPrivateOffer(), hashOfChallenge, extraDataMapMap, proto.getProtocolVersion());
}
Also used : NodeAddress(bisq.network.p2p.NodeAddress) ToString(lombok.ToString)

Example 12 with NodeAddress

use of bisq.network.p2p.NodeAddress in project bisq-core by bisq-network.

the class OpenOfferManager method handleOfferAvailabilityRequest.

// /////////////////////////////////////////////////////////////////////////////////////////
// OfferPayload Availability
// /////////////////////////////////////////////////////////////////////////////////////////
private void handleOfferAvailabilityRequest(OfferAvailabilityRequest message, NodeAddress sender) {
    log.trace("handleNewMessage: message = " + message.getClass().getSimpleName() + " from " + sender);
    if (p2PService.isBootstrapped()) {
        if (!stopped) {
            try {
                Validator.nonEmptyStringOf(message.offerId);
                checkNotNull(message.getPubKeyRing());
            } catch (Throwable t) {
                log.warn("Invalid message " + message.toString());
                return;
            }
            Optional<OpenOffer> openOfferOptional = findOpenOffer(message.offerId);
            AvailabilityResult availabilityResult;
            if (openOfferOptional.isPresent()) {
                if (openOfferOptional.get().getState() == OpenOffer.State.AVAILABLE) {
                    final Offer offer = openOfferOptional.get().getOffer();
                    if (!preferences.getIgnoreTradersList().stream().filter(i -> i.equals(offer.getMakerNodeAddress().getHostNameWithoutPostFix())).findAny().isPresent()) {
                        availabilityResult = AvailabilityResult.AVAILABLE;
                        // TODO mediators not impl yet
                        List<NodeAddress> acceptedArbitrators = user.getAcceptedArbitratorAddresses();
                        if (acceptedArbitrators != null && !acceptedArbitrators.isEmpty()) {
                            // losses and therefore an outdated market price.
                            try {
                                offer.checkTradePriceTolerance(message.getTakersTradePrice());
                            } catch (TradePriceOutOfToleranceException e) {
                                log.warn("Trade price check failed because takers price is outside out tolerance.");
                                availabilityResult = AvailabilityResult.PRICE_OUT_OF_TOLERANCE;
                            } catch (MarketPriceNotAvailableException e) {
                                log.warn(e.getMessage());
                                availabilityResult = AvailabilityResult.MARKET_PRICE_NOT_AVAILABLE;
                            } catch (Throwable e) {
                                log.warn("Trade price check failed. " + e.getMessage());
                                availabilityResult = AvailabilityResult.UNKNOWN_FAILURE;
                            }
                        } else {
                            log.warn("acceptedArbitrators is null or empty: acceptedArbitrators=" + acceptedArbitrators);
                            availabilityResult = AvailabilityResult.NO_ARBITRATORS;
                        }
                    } else {
                        availabilityResult = AvailabilityResult.USER_IGNORED;
                    }
                } else {
                    availabilityResult = AvailabilityResult.OFFER_TAKEN;
                }
            } else {
                log.warn("handleOfferAvailabilityRequest: openOffer not found. That should never happen.");
                availabilityResult = AvailabilityResult.OFFER_TAKEN;
            }
            try {
                p2PService.sendEncryptedDirectMessage(sender, message.getPubKeyRing(), new OfferAvailabilityResponse(message.offerId, availabilityResult), new SendDirectMessageListener() {

                    @Override
                    public void onArrived() {
                        log.trace("OfferAvailabilityResponse successfully arrived at peer");
                    }

                    @Override
                    public void onFault() {
                        log.debug("Sending OfferAvailabilityResponse failed.");
                    }
                });
            } catch (Throwable t) {
                t.printStackTrace();
                log.debug("Exception at handleRequestIsOfferAvailableMessage " + t.getMessage());
            }
        } else {
            log.debug("We have stopped already. We ignore that handleOfferAvailabilityRequest call.");
        }
    } else {
        log.info("We got a handleOfferAvailabilityRequest but we have not bootstrapped yet.");
    }
}
Also used : BtcWalletService(bisq.core.btc.wallet.BtcWalletService) PlaceOfferProtocol(bisq.core.offer.placeoffer.PlaceOfferProtocol) Coin(org.bitcoinj.core.Coin) LoggerFactory(org.slf4j.LoggerFactory) Timer(bisq.common.Timer) User(bisq.core.user.User) PersistenceProtoResolver(bisq.common.proto.persistable.PersistenceProtoResolver) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) TradePriceOutOfToleranceException(bisq.core.exceptions.TradePriceOutOfToleranceException) BootstrapListener(bisq.network.p2p.BootstrapListener) ErrorMessageHandler(bisq.common.handlers.ErrorMessageHandler) Named(javax.inject.Named) PlaceOfferModel(bisq.core.offer.placeoffer.PlaceOfferModel) Validator(bisq.core.util.Validator) Nullable(javax.annotation.Nullable) OfferAvailabilityResponse(bisq.core.offer.messages.OfferAvailabilityResponse) ClosedTradableManager(bisq.core.trade.closed.ClosedTradableManager) PeerManager(bisq.network.p2p.peers.PeerManager) NetworkEnvelope(bisq.common.proto.network.NetworkEnvelope) Logger(org.slf4j.Logger) OfferAvailabilityRequest(bisq.core.offer.messages.OfferAvailabilityRequest) P2PService(bisq.network.p2p.P2PService) TransactionResultHandler(bisq.core.trade.handlers.TransactionResultHandler) PersistedDataHost(bisq.common.proto.persistable.PersistedDataHost) ResultHandler(bisq.common.handlers.ResultHandler) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) Log(bisq.common.app.Log) Collectors(java.util.stream.Collectors) TradableList(bisq.core.trade.TradableList) File(java.io.File) BsqWalletService(bisq.core.btc.wallet.BsqWalletService) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) PriceFeedService(bisq.core.provider.price.PriceFeedService) TradeWalletService(bisq.core.btc.wallet.TradeWalletService) NodeAddress(bisq.network.p2p.NodeAddress) SendDirectMessageListener(bisq.network.p2p.SendDirectMessageListener) Storage(bisq.common.storage.Storage) Preferences(bisq.core.user.Preferences) UserThread(bisq.common.UserThread) Optional(java.util.Optional) KeyRing(bisq.common.crypto.KeyRing) ObservableList(javafx.collections.ObservableList) DecryptedDirectMessageListener(bisq.network.p2p.DecryptedDirectMessageListener) DecryptedMessageWithPubKey(bisq.network.p2p.DecryptedMessageWithPubKey) NotNull(org.jetbrains.annotations.NotNull) TradePriceOutOfToleranceException(bisq.core.exceptions.TradePriceOutOfToleranceException) OfferAvailabilityResponse(bisq.core.offer.messages.OfferAvailabilityResponse) SendDirectMessageListener(bisq.network.p2p.SendDirectMessageListener) NodeAddress(bisq.network.p2p.NodeAddress)

Example 13 with NodeAddress

use of bisq.network.p2p.NodeAddress 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());
}
Also used : CounterCurrencyTransferStartedMessage(bisq.core.trade.messages.CounterCurrencyTransferStartedMessage) SellerProcessCounterCurrencyTransferStartedMessage(bisq.core.trade.protocol.tasks.seller.SellerProcessCounterCurrencyTransferStartedMessage) MakerProcessDepositTxPublishedMessage(bisq.core.trade.protocol.tasks.maker.MakerProcessDepositTxPublishedMessage) DepositTxPublishedMessage(bisq.core.trade.messages.DepositTxPublishedMessage) NodeAddress(bisq.network.p2p.NodeAddress) MailboxMessage(bisq.network.p2p.MailboxMessage)

Example 14 with NodeAddress

use of bisq.network.p2p.NodeAddress in project bisq-core by bisq-network.

the class SellerAsTakerProtocol method doApplyMailboxMessage.

// /////////////////////////////////////////////////////////////////////////////////////////
// Mailbox
// /////////////////////////////////////////////////////////////////////////////////////////
@Override
public void doApplyMailboxMessage(NetworkEnvelope networkEnvelop, Trade trade) {
    this.trade = trade;
    if (networkEnvelop instanceof MailboxMessage) {
        NodeAddress peerNodeAddress = ((MailboxMessage) networkEnvelop).getSenderNodeAddress();
        if (networkEnvelop instanceof PublishDepositTxRequest)
            handle((PublishDepositTxRequest) networkEnvelop, peerNodeAddress);
        else if (networkEnvelop instanceof CounterCurrencyTransferStartedMessage)
            handle((CounterCurrencyTransferStartedMessage) networkEnvelop, peerNodeAddress);
        else
            log.error("We received an unhandled MailboxMessage" + networkEnvelop.toString());
    }
}
Also used : CounterCurrencyTransferStartedMessage(bisq.core.trade.messages.CounterCurrencyTransferStartedMessage) SellerProcessCounterCurrencyTransferStartedMessage(bisq.core.trade.protocol.tasks.seller.SellerProcessCounterCurrencyTransferStartedMessage) NodeAddress(bisq.network.p2p.NodeAddress) MailboxMessage(bisq.network.p2p.MailboxMessage) TakerProcessPublishDepositTxRequest(bisq.core.trade.protocol.tasks.taker.TakerProcessPublishDepositTxRequest) PublishDepositTxRequest(bisq.core.trade.messages.PublishDepositTxRequest)

Example 15 with NodeAddress

use of bisq.network.p2p.NodeAddress 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());
    }
}
Also used : MakerProcessDepositTxPublishedMessage(bisq.core.trade.protocol.tasks.maker.MakerProcessDepositTxPublishedMessage) DepositTxPublishedMessage(bisq.core.trade.messages.DepositTxPublishedMessage) PayoutTxPublishedMessage(bisq.core.trade.messages.PayoutTxPublishedMessage) BuyerProcessPayoutTxPublishedMessage(bisq.core.trade.protocol.tasks.buyer.BuyerProcessPayoutTxPublishedMessage) NodeAddress(bisq.network.p2p.NodeAddress) MailboxMessage(bisq.network.p2p.MailboxMessage)

Aggregations

NodeAddress (bisq.network.p2p.NodeAddress)32 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)6 Contract (bisq.core.trade.Contract)5 Test (org.junit.Test)5 PubKeyRing (bisq.common.crypto.PubKeyRing)4 AddressEntry (bisq.core.btc.AddressEntry)4 Offer (bisq.core.offer.Offer)4 PaymentAccountPayload (bisq.core.payment.payload.PaymentAccountPayload)4 SendMailboxMessageListener (bisq.network.p2p.SendMailboxMessageListener)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Insets (javafx.geometry.Insets)4 PeerInfoIcon (bisq.desktop.components.PeerInfoIcon)3 MailboxMessage (bisq.network.p2p.MailboxMessage)3 List (java.util.List)3 TableCell (javafx.scene.control.TableCell)3 TableColumn (javafx.scene.control.TableColumn)3 ErrorMessageHandler (bisq.common.handlers.ErrorMessageHandler)2 ResultHandler (bisq.common.handlers.ResultHandler)2 BisqEnvironment (bisq.core.app.BisqEnvironment)2