mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-10-01 01:35:48 -04:00
randomize completed trade info, fixes #1099
This commit is contained in:
parent
8e3e91c7cc
commit
db6cb237bf
@ -54,6 +54,8 @@ import java.util.Date;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
@ -88,13 +90,27 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
|
|||||||
Offer offer = checkNotNull(trade.getOffer());
|
Offer offer = checkNotNull(trade.getOffer());
|
||||||
return new TradeStatistics3(offer.getCurrencyCode(),
|
return new TradeStatistics3(offer.getCurrencyCode(),
|
||||||
trade.getPrice().getValue(),
|
trade.getPrice().getValue(),
|
||||||
trade.getAmount().longValueExact(),
|
fuzzTradeAmount(trade.getAmount().longValueExact()),
|
||||||
offer.getPaymentMethod().getId(),
|
offer.getPaymentMethod().getId(),
|
||||||
trade.getTakeOfferDate().getTime(),
|
fuzzTradeDate(trade.getTakeOfferDate().getTime()),
|
||||||
truncatedArbitratorNodeAddress,
|
truncatedArbitratorNodeAddress,
|
||||||
extraDataMap);
|
extraDataMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static long fuzzTradeAmount(long exactAmount) { // randomize completed trade info #1099
|
||||||
|
long adjustedAmount = (long) ThreadLocalRandom.current().nextDouble(
|
||||||
|
exactAmount * 0.95, exactAmount * 1.05);
|
||||||
|
log.info("fuzzed trade amount from {} to {}", exactAmount, adjustedAmount);
|
||||||
|
return adjustedAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long fuzzTradeDate(long originalTimestamp) { // randomize completed trade info #1099
|
||||||
|
long adjustedTimestamp = ThreadLocalRandom.current().nextLong(
|
||||||
|
originalTimestamp-TimeUnit.HOURS.toMillis(24), originalTimestamp);
|
||||||
|
log.info("fuzzed trade datestamp from {} to {}", new Date(originalTimestamp), new Date(adjustedTimestamp));
|
||||||
|
return adjustedTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
// This enum must not change the order as we use the ordinal for storage to reduce data size.
|
// This enum must not change the order as we use the ordinal for storage to reduce data size.
|
||||||
// The payment method string can be quite long and would consume 15% more space.
|
// The payment method string can be quite long and would consume 15% more space.
|
||||||
// When we get a new payment method we can add it to the enum at the end. Old users would add it as string if not
|
// When we get a new payment method we can add it to the enum at the end. Old users would add it as string if not
|
||||||
|
Loading…
Reference in New Issue
Block a user