Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert setting of null to deposit tx id #3958

Merged
merged 3 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected void run() {
trade.getTradePrice(),
trade.getTradeAmount(),
trade.getDate(),
null,
trade.getDepositTxId(),
extraDataMap);
processModel.getP2PService().addPersistableNetworkPayload(tradeStatistics, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import com.google.common.base.Charsets;

import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Map;
import java.util.Optional;

Expand All @@ -71,8 +70,6 @@ public final class TradeStatistics2 implements ProcessOncePersistableNetworkPayl
public static final String MEDIATOR_ADDRESS = "medAddr";
public static final String REFUND_AGENT_ADDRESS = "refAddr";

public static final Date CUT_OFF_DATE_FOR_DEPOSIT_TX_ID = Utilities.getUTCDate(2019, GregorianCalendar.FEBRUARY, 13);

private final OfferPayload.Direction direction;
private final String baseCurrency;
private final String counterCurrency;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -81,6 +82,9 @@ public void onAllServicesInitialized() {
Set<TradeStatistics2> collect = tradeStatistics2StorageService.getMap().values().stream()
.filter(e -> e instanceof TradeStatistics2)
.map(e -> (TradeStatistics2) e)
.map(WrapperTradeStatistics2::new)
.distinct()
.map(WrapperTradeStatistics2::unwrap)
.filter(TradeStatistics2::isValid)
.collect(Collectors.toSet());
observableTradeStatisticsSet.addAll(collect);
Expand Down Expand Up @@ -150,4 +154,29 @@ private void dump() {
jsonFileManager.writeToDisc(Utilities.objectToJson(array), "trade_statistics");
}
}

static class WrapperTradeStatistics2 {
private TradeStatistics2 tradeStatistics;

public WrapperTradeStatistics2(TradeStatistics2 tradeStatistics) {
this.tradeStatistics = tradeStatistics;
}

public TradeStatistics2 unwrap() {
return this.tradeStatistics;
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
var wrapper = (WrapperTradeStatistics2) obj;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need a check that obj is actually a WrapperTradeStatistics2 here? Could cause an exception otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add it to make it safer if it is reused somewhere.
Atm using it like that should not cause this case to ever happen.

.map(WrapperTradeStatistics2::new)
.distinct()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But will add a check to be sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah wait - I've added it already 😉

 if (obj == null || getClass() != obj.getClass()) return false;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right, that's right, missed it.

return Objects.equals(tradeStatistics.getOfferId(), wrapper.tradeStatistics.getOfferId());
}

@Override
public int hashCode() {
return Objects.hash(tradeStatistics.getOfferId());
}
}
}