revert getters for peer and arbitrator node addresses to avoid NPEs

This commit is contained in:
woodser 2022-10-02 17:04:21 -04:00
parent 767f4cf8c0
commit 79021dc9c6
11 changed files with 27 additions and 22 deletions

View file

@ -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

View file

@ -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();

View file

@ -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();

View file

@ -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);
}
}

View file

@ -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.
*

View file

@ -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);

View file

@ -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