mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-22 19:49:32 +00:00
revert getters for peer and arbitrator node addresses to avoid NPEs
This commit is contained in:
parent
767f4cf8c0
commit
79021dc9c6
11 changed files with 27 additions and 22 deletions
|
@ -42,14 +42,14 @@ public class TradeInfo implements Payload {
|
|||
// view and interact with trades.
|
||||
|
||||
private static final Function<Trade, String> toPeerNodeAddress = (trade) ->
|
||||
trade.getTradingPeer() == null || trade.getTradingPeer().getNodeAddress() == null
|
||||
trade.getTradingPeerNodeAddress() == null
|
||||
? ""
|
||||
: trade.getTradingPeer().getNodeAddress().getFullAddress();
|
||||
: trade.getTradingPeerNodeAddress().getFullAddress();
|
||||
|
||||
private static final Function<Trade, String> toArbitratorNodeAddress = (trade) ->
|
||||
trade.getArbitrator() == null || trade.getArbitrator().getNodeAddress() == null
|
||||
trade.getArbitratorNodeAddress() == null
|
||||
? ""
|
||||
: trade.getArbitrator().getNodeAddress().getFullAddress();
|
||||
: trade.getArbitratorNodeAddress().getFullAddress();
|
||||
|
||||
private static final Function<Trade, String> toRoundedVolume = (trade) ->
|
||||
trade.getVolume() == null
|
||||
|
|
|
@ -139,7 +139,7 @@ public class Balances {
|
|||
if (trade.getContract() == null) continue;
|
||||
Long reservedAmt;
|
||||
OfferPayload offerPayload = trade.getContract().getOfferPayload();
|
||||
if (trade.getArbitrator().getNodeAddress().equals(P2PService.getMyNodeAddress())) { // TODO (woodser): this only works if node address does not change
|
||||
if (trade.getArbitratorNodeAddress().equals(P2PService.getMyNodeAddress())) { // TODO (woodser): this only works if node address does not change
|
||||
reservedAmt = offerPayload.getAmount() + offerPayload.getBuyerSecurityDeposit() + offerPayload.getSellerSecurityDeposit(); // arbitrator reserved balance is sum of amounts sent to multisig
|
||||
} else {
|
||||
reservedAmt = trade.getContract().isMyRoleBuyer(tradeManager.getKeyRing().getPubKeyRing()) ? offerPayload.getBuyerSecurityDeposit() : offerPayload.getAmount() + offerPayload.getSellerSecurityDeposit();
|
||||
|
|
|
@ -22,7 +22,6 @@ import bisq.core.monetary.Volume;
|
|||
import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OpenOffer;
|
||||
import bisq.core.provider.price.PriceFeedService;
|
||||
import bisq.core.trade.protocol.TradingPeer;
|
||||
import bisq.core.trade.statistics.TradeStatisticsManager;
|
||||
import bisq.core.user.Preferences;
|
||||
|
||||
|
@ -192,10 +191,9 @@ public class ClosedTradableManager implements PersistedDataHost {
|
|||
if (isOpenOffer(tradable)) {
|
||||
return 0;
|
||||
}
|
||||
NodeAddress addressInTrade = castToTradeModel(tradable).getTradingPeer().getNodeAddress();
|
||||
NodeAddress addressInTrade = castToTradeModel(tradable).getTradingPeerNodeAddress();
|
||||
return (int) getTradeModelStream()
|
||||
.map(Trade::getTradingPeer)
|
||||
.map(TradingPeer::getNodeAddress)
|
||||
.map(Trade::getTradingPeerNodeAddress)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(address -> address.equals(addressInTrade))
|
||||
.count();
|
||||
|
|
|
@ -76,6 +76,6 @@ public interface Tradable extends PersistablePayload {
|
|||
}
|
||||
|
||||
default Optional<NodeAddress> getOptionalTradingPeerNodeAddress() {
|
||||
return asTradeModel().map(Trade::getTradingPeer).map(TradingPeer::getNodeAddress);
|
||||
return asTradeModel().map(Trade::getTradingPeerNodeAddress);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -600,7 +600,7 @@ public abstract class Trade implements Tradable, Model {
|
|||
}
|
||||
|
||||
public void initialize(ProcessModelServiceProvider serviceProvider) {
|
||||
serviceProvider.getArbitratorManager().getDisputeAgentByNodeAddress(getArbitrator().getNodeAddress()).ifPresent(arbitrator -> {
|
||||
serviceProvider.getArbitratorManager().getDisputeAgentByNodeAddress(getArbitratorNodeAddress()).ifPresent(arbitrator -> {
|
||||
getArbitrator().setPubKeyRing(arbitrator.getPubKeyRing());
|
||||
});
|
||||
|
||||
|
@ -616,6 +616,14 @@ public abstract class Trade implements Tradable, Model {
|
|||
getSelf().setNodeAddress(P2PService.getMyNodeAddress());
|
||||
}
|
||||
|
||||
public NodeAddress getTradingPeerNodeAddress() {
|
||||
return getTradingPeer() == null ? null : getTradingPeer().getNodeAddress();
|
||||
}
|
||||
|
||||
public NodeAddress getArbitratorNodeAddress() {
|
||||
return getArbitrator() == null ? null : getArbitrator().getNodeAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a contract based on the current state.
|
||||
*
|
||||
|
|
|
@ -837,7 +837,6 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
|
|||
|
||||
// If trade was completed (closed without fault but might be closed by a dispute) we move it to the closed trades
|
||||
public void onTradeCompleted(Trade trade) {
|
||||
if (trade.getState() == Trade.State.WITHDRAW_COMPLETED) return;
|
||||
closedTradableManager.add(trade);
|
||||
trade.setState(Trade.State.WITHDRAW_COMPLETED);
|
||||
maybeRemoveTrade(trade);
|
||||
|
|
|
@ -81,7 +81,7 @@ public final class TradeStatistics2 implements ProcessOncePersistableNetworkPayl
|
|||
extraDataMap.put(OfferPayload.REFERRAL_ID, referralId);
|
||||
}
|
||||
|
||||
NodeAddress arbitratorNodeAddress = trade.getArbitrator().getNodeAddress();
|
||||
NodeAddress arbitratorNodeAddress = trade.getArbitratorNodeAddress();
|
||||
if (arbitratorNodeAddress != null) {
|
||||
// The first 4 chars are sufficient to identify a arbitrator.
|
||||
// For testing with regtest/localhost we use the full address as its localhost and would result in
|
||||
|
|
|
@ -208,7 +208,7 @@ public class TradeDetailsWindow extends Overlay<TradeDetailsWindow> {
|
|||
rows++;
|
||||
if (trade.hasFailed())
|
||||
rows += 2;
|
||||
if (trade.getTradingPeer().getNodeAddress() != null)
|
||||
if (trade.getTradingPeerNodeAddress() != null)
|
||||
rows++;
|
||||
if (showXmrProofResult)
|
||||
rows++;
|
||||
|
@ -232,16 +232,16 @@ public class TradeDetailsWindow extends Overlay<TradeDetailsWindow> {
|
|||
Res.get("shared.takerTxFee", formatter.formatCoinWithCode(trade.getTxFee().multiply(3)));
|
||||
addConfirmationLabelTextField(gridPane, ++rowIndex, Res.get("tradeDetailsWindow.txFee"), txFee);
|
||||
|
||||
NodeAddress arbitratorNodeAddress = trade.getArbitrator().getNodeAddress();
|
||||
NodeAddress arbitratorNodeAddress = trade.getArbitratorNodeAddress();
|
||||
if (arbitratorNodeAddress != null) {
|
||||
addConfirmationLabelTextField(gridPane, ++rowIndex,
|
||||
Res.get("tradeDetailsWindow.agentAddresses"),
|
||||
arbitratorNodeAddress.getFullAddress());
|
||||
}
|
||||
|
||||
if (trade.getTradingPeer().getNodeAddress() != null)
|
||||
if (trade.getTradingPeerNodeAddress() != null)
|
||||
addConfirmationLabelTextField(gridPane, ++rowIndex, Res.get("tradeDetailsWindow.tradingPeersOnion"),
|
||||
trade.getTradingPeer().getNodeAddress().getFullAddress());
|
||||
trade.getTradingPeerNodeAddress().getFullAddress());
|
||||
|
||||
if (showXmrProofResult) {
|
||||
// As the window is already overloaded we replace the tradingPeersPubKeyHash field with the auto-conf state
|
||||
|
|
|
@ -501,7 +501,7 @@ public class ClosedTradesView extends ActivatableViewAndModel<VBox, ClosedTrades
|
|||
if (!empty && item != null && item.getTradable() instanceof Trade) {
|
||||
Trade tradeModel = (Trade) item.getTradable();
|
||||
int numPastTrades = item.getNumPastTrades();
|
||||
NodeAddress tradingPeerNodeAddress = tradeModel.getTradingPeer().getNodeAddress();
|
||||
NodeAddress tradingPeerNodeAddress = tradeModel.getTradingPeerNodeAddress();
|
||||
String role = Res.get("peerInfoIcon.tooltip.tradePeer");
|
||||
Node peerInfoIcon = new PeerInfoIconTrading(tradingPeerNodeAddress,
|
||||
role,
|
||||
|
|
|
@ -849,7 +849,7 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
|||
super.updateItem(newItem, empty);
|
||||
if (!empty && newItem != null) {
|
||||
final Trade trade = newItem.getTrade();
|
||||
final NodeAddress tradingPeerNodeAddress = trade.getTradingPeer() == null ? null : trade.getTradingPeer().getNodeAddress();
|
||||
final NodeAddress tradingPeerNodeAddress = trade.getTradingPeerNodeAddress();
|
||||
int numPastTrades = model.getNumPastTrades(trade);
|
||||
String role = Res.get("peerInfoIcon.tooltip.tradePeer");
|
||||
Node peerInfoIcon = new PeerInfoIconTrading(tradingPeerNodeAddress, // TODO: display maker and taker node addresses for arbitrator
|
||||
|
|
|
@ -372,9 +372,9 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
|
|||
.filter(e -> {
|
||||
if (e instanceof Trade) {
|
||||
Trade t = (Trade) e;
|
||||
return t.getTradingPeer().getNodeAddress() != null &&
|
||||
trade.getTradingPeer().getNodeAddress() != null &&
|
||||
t.getTradingPeer().getNodeAddress().getFullAddress().equals(trade.getTradingPeer().getNodeAddress().getFullAddress());
|
||||
return t.getTradingPeerNodeAddress() != null &&
|
||||
trade.getTradingPeerNodeAddress() != null &&
|
||||
t.getTradingPeerNodeAddress().getFullAddress().equals(trade.getTradingPeerNodeAddress().getFullAddress());
|
||||
} else
|
||||
return false;
|
||||
|
||||
|
|
Loading…
Reference in a new issue