synchronize closed and failed trade managers

This commit is contained in:
woodser 2023-02-21 11:12:08 -05:00
parent 28c07e966b
commit 86511b4e21
2 changed files with 67 additions and 37 deletions

View file

@ -109,53 +109,68 @@ public class ClosedTradableManager implements PersistedDataHost {
}
public void add(Tradable tradable) {
synchronized (closedTradables) {
if (closedTradables.add(tradable)) {
maybeClearSensitiveData();
requestPersistence();
}
}
}
public void remove(Tradable tradable) {
synchronized (closedTradables) {
if (closedTradables.remove(tradable)) {
requestPersistence();
}
}
}
public boolean wasMyOffer(Offer offer) {
return offer.isMyOffer(keyRing);
}
public ObservableList<Tradable> getObservableList() {
synchronized (closedTradables) {
return closedTradables.getObservableList();
}
}
public List<Tradable> getTradableList() {
return ImmutableList.copyOf(new ArrayList<>(getObservableList()));
}
public List<Trade> getClosedTrades() {
synchronized (closedTradables) {
return ImmutableList.copyOf(getObservableList().stream()
.filter(e -> e instanceof Trade)
.map(e -> (Trade) e)
.collect(Collectors.toList()));
}
}
public List<OpenOffer> getCanceledOpenOffers() {
synchronized (closedTradables) {
return ImmutableList.copyOf(getObservableList().stream()
.filter(e -> (e instanceof OpenOffer) && ((OpenOffer) e).getState().equals(CANCELED))
.map(e -> (OpenOffer) e)
.collect(Collectors.toList()));
}
}
public Optional<Tradable> getTradableById(String id) {
synchronized (closedTradables) {
return closedTradables.stream().filter(e -> e.getId().equals(id)).findFirst();
}
}
public Optional<Tradable> getTradeById(String id) {
synchronized (closedTradables) {
return closedTradables.stream().filter(e -> e instanceof Trade && e.getId().equals(id)).findFirst();
}
}
public void maybeClearSensitiveData() {
synchronized (closedTradables) {
log.info("checking closed trades eligibility for having sensitive data cleared");
closedTradables.stream()
.filter(e -> e instanceof Trade)
@ -164,14 +179,17 @@ public class ClosedTradableManager implements PersistedDataHost {
.forEach(Trade::maybeClearSensitiveData);
requestPersistence();
}
}
public boolean canTradeHaveSensitiveDataCleared(String tradeId) {
Instant safeDate = getSafeDateForSensitiveDataClearing();
synchronized (closedTradables) {
return closedTradables.stream()
.filter(e -> e.getId().equals(tradeId))
.filter(e -> e.getDate().toInstant().isBefore(safeDate))
.count() > 0;
}
}
public Instant getSafeDateForSensitiveDataClearing() {
return Instant.ofEpochSecond(Instant.now().getEpochSecond()

View file

@ -88,35 +88,46 @@ public class FailedTradesManager implements PersistedDataHost {
}
public void add(Trade trade) {
synchronized (failedTrades) {
if (failedTrades.add(trade)) {
requestPersistence();
}
}
}
public void removeTrade(Trade trade) {
synchronized (failedTrades) {
if (failedTrades.remove(trade)) {
requestPersistence();
}
}
}
public boolean wasMyOffer(Offer offer) {
return offer.isMyOffer(keyRing);
}
public ObservableList<Trade> getObservableList() {
synchronized (failedTrades) {
return failedTrades.getObservableList();
}
}
public Optional<Trade> getTradeById(String id) {
synchronized (failedTrades) {
return failedTrades.stream().filter(e -> e.getId().equals(id)).findFirst();
}
}
public Stream<Trade> getTradesStreamWithFundsLockedIn() {
synchronized (failedTrades) {
return failedTrades.stream()
.filter(Trade::isFundsLockedIn);
}
}
public void unFailTrade(Trade trade) {
synchronized (failedTrades) {
if (unFailTradeCallback == null)
return;
@ -127,6 +138,7 @@ public class FailedTradesManager implements PersistedDataHost {
}
}
}
}
public String checkUnFail(Trade trade) {
var addresses = tradeUtil.getTradeAddresses(trade);