Skip to content

Commit 3ad4481

Browse files
committed
use single character flag in trade stats, always provide fixed prices
1 parent 98b1875 commit 3ad4481

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

core/src/main/java/haveno/core/trade/Trade.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import haveno.core.trade.protocol.TradeListener;
6666
import haveno.core.trade.protocol.TradePeer;
6767
import haveno.core.trade.protocol.TradeProtocol;
68+
import haveno.core.util.PriceUtil;
6869
import haveno.core.util.VolumeUtil;
6970
import haveno.core.xmr.model.XmrAddressEntry;
7071
import haveno.core.xmr.wallet.XmrWalletBase;
@@ -2360,7 +2361,10 @@ public BigInteger getReservedAmount() {
23602361
}
23612362

23622363
public Price getPrice() {
2363-
return Price.valueOf(offer.getCurrencyCode(), price);
2364+
2365+
// return uninverted price
2366+
boolean isInverted = getOffer().currenciesInverted();
2367+
return Price.valueOf(offer.getCurrencyCode(), isInverted ? PriceUtil.invertLongPrice(price, offer.getCurrencyCode()) : price);
23642368
}
23652369

23662370
@Nullable

core/src/main/java/haveno/core/trade/statistics/TradeStatistics3.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayload, PersistableNetworkPayload,
7070
CapabilityRequiringPayload, DateSortedTruncatablePayload {
7171

72+
private static final String VERSION_KEY = "v"; // single character key which can be used for versioning if needed
73+
7274
@JsonExclude
7375
private transient static final ZoneId ZONE_ID = ZoneId.systemDefault();
7476

@@ -94,10 +96,11 @@ private static TradeStatistics3 from(Trade trade,
9496
extraDataMap.put(OfferPayload.REFERRAL_ID, referralId);
9597
}
9698

97-
// Store protocol version in order to invert prices of legacy crypto stats.
98-
// This can be removed in the future after all trades use trade protocol version 3+,
99-
// then invert only stats which are missing this field prior to then.
100-
extraDataMap.put(Trade.PROTOCOL_VERSION, trade.getOffer().getOfferPayload().getProtocolVersion() + "");
99+
// Store a key to indicate that crypto prices are not inverted in this version.
100+
// This can be removed in the future after all stats are expected to not be inverted,
101+
// then only stats which are missing this field prior to then need to be uninverted.
102+
boolean isCryptoCurrency = CurrencyUtil.isCryptoCurrency(trade.getOffer().getCurrencyCode());
103+
if (isCryptoCurrency) extraDataMap.put(VERSION_KEY, ""); // value is not currently needed
101104

102105
NodeAddress arbitratorNodeAddress = checkNotNull(trade.getArbitrator().getNodeAddress(), "Arbitrator address is null", trade.getClass().getSimpleName(), trade.getId());
103106

@@ -416,8 +419,7 @@ public Price getTradePrice() {
416419
public long getPrice() {
417420
boolean isInverted = CurrencyUtil.isCryptoCurrency(currency) &&
418421
(extraDataMap == null ||
419-
!extraDataMap.containsKey(Trade.PROTOCOL_VERSION) ||
420-
Integer.parseInt(extraDataMap.get(Trade.PROTOCOL_VERSION)) < 3);
422+
!extraDataMap.containsKey(VERSION_KEY)); // price is inverted if missing key
421423
return isInverted ? PriceUtil.invertLongPrice(price, currency) : price;
422424
}
423425

0 commit comments

Comments
 (0)