mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 18:03:12 +01:00
Use hash at conversion also for local data to avoid duplicates.
This commit is contained in:
parent
3687a03695
commit
1f0590dc95
@ -102,7 +102,7 @@ public class TradeStatisticsConverter {
|
|||||||
// We listen to old TradeStatistics2 objects, convert and store them and rebroadcast.
|
// We listen to old TradeStatistics2 objects, convert and store them and rebroadcast.
|
||||||
p2PDataStorage.addAppendOnlyDataStoreListener(payload -> {
|
p2PDataStorage.addAppendOnlyDataStoreListener(payload -> {
|
||||||
if (payload instanceof TradeStatistics2) {
|
if (payload instanceof TradeStatistics2) {
|
||||||
TradeStatistics3 tradeStatistics3 = convertToTradeStatistics3((TradeStatistics2) payload, true);
|
TradeStatistics3 tradeStatistics3 = convertToTradeStatistics3((TradeStatistics2) payload);
|
||||||
// We add it to the p2PDataStorage, which handles to get the data stored in the maps and maybe
|
// We add it to the p2PDataStorage, which handles to get the data stored in the maps and maybe
|
||||||
// re-broadcast as tradeStatistics3 object if not already received.
|
// re-broadcast as tradeStatistics3 object if not already received.
|
||||||
p2PDataStorage.addPersistableNetworkPayload(tradeStatistics3, null, true);
|
p2PDataStorage.addPersistableNetworkPayload(tradeStatistics3, null, true);
|
||||||
@ -133,7 +133,7 @@ public class TradeStatisticsConverter {
|
|||||||
log.info("We convert the existing {} trade statistics objects to the new format.", mapWithoutDuplicates.size());
|
log.info("We convert the existing {} trade statistics objects to the new format.", mapWithoutDuplicates.size());
|
||||||
|
|
||||||
mapWithoutDuplicates.values().stream()
|
mapWithoutDuplicates.values().stream()
|
||||||
.map(e -> convertToTradeStatistics3(e, false))
|
.map(TradeStatisticsConverter::convertToTradeStatistics3)
|
||||||
.filter(TradeStatistics3::isValid)
|
.filter(TradeStatistics3::isValid)
|
||||||
.forEach(list::add);
|
.forEach(list::add);
|
||||||
|
|
||||||
@ -151,25 +151,22 @@ public class TradeStatisticsConverter {
|
|||||||
tradeStatistics3.pruneOptionalData();
|
tradeStatistics3.pruneOptionalData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TradeStatistics3 convertToTradeStatistics3(TradeStatistics2 tradeStatistics2, boolean fromNetwork) {
|
private static TradeStatistics3 convertToTradeStatistics3(TradeStatistics2 tradeStatistics2) {
|
||||||
Map<String, String> extraDataMap = tradeStatistics2.getExtraDataMap();
|
Map<String, String> extraDataMap = tradeStatistics2.getExtraDataMap();
|
||||||
String mediator = extraDataMap != null ? extraDataMap.get(TradeStatistics2.MEDIATOR_ADDRESS) : null;
|
String mediator = extraDataMap != null ? extraDataMap.get(TradeStatistics2.MEDIATOR_ADDRESS) : null;
|
||||||
String refundAgent = extraDataMap != null ? extraDataMap.get(TradeStatistics2.REFUND_AGENT_ADDRESS) : null;
|
String refundAgent = extraDataMap != null ? extraDataMap.get(TradeStatistics2.REFUND_AGENT_ADDRESS) : null;
|
||||||
long time = tradeStatistics2.getTradeDate().getTime();
|
long time = tradeStatistics2.getTradeDate().getTime();
|
||||||
byte[] hash = null;
|
// We need to avoid that we duplicate tradeStatistics2 objects in case both traders have not updated yet.
|
||||||
if (fromNetwork) {
|
// Before v1.4.0 both traders published the trade statistics. If one trader has updated he will check
|
||||||
// We need to avoid that we duplicate tradeStatistics2 objects in case both traders have not udpated yet.
|
// the capabilities of the peer and if the peer has not updated he will leave publishing to the peer, so we
|
||||||
// Before v1.4.0 both traders published the trade statistics. If one trader has updated he will check
|
// do not have the problem of duplicated objects.
|
||||||
// the capabilities of the peer and if the peer has not updated he will leave publishing to the peer, so we
|
// Also at conversion of locally stored old trade statistics we need to avoid duplicated entries.
|
||||||
// do not have the problem of duplicated objects.
|
// To ensure we add only one object we will use the hash of the tradeStatistics2 object which is the same
|
||||||
// To ensure we add only one object we will use the hash of the tradeStatistics2 object which is the same
|
// for both traders as it excluded the trade date which is different for both.
|
||||||
// for both traders as it excluded the trade date which is different for both.
|
byte[] hash = tradeStatistics2.getHash();
|
||||||
hash = tradeStatistics2.getHash();
|
|
||||||
}
|
|
||||||
return new TradeStatistics3(tradeStatistics2.getCurrencyCode(),
|
return new TradeStatistics3(tradeStatistics2.getCurrencyCode(),
|
||||||
tradeStatistics2.getTradePrice().getValue(),
|
tradeStatistics2.getTradePrice().getValue(),
|
||||||
tradeStatistics2.getTradeAmount().getValue(),
|
tradeStatistics2.getTradeAmount().getValue(),
|
||||||
|
Loading…
Reference in New Issue
Block a user