Merge pull request #5292 from ghubstan/00-fix-corecontext-usage

Fix singleton CoreContext usage
This commit is contained in:
sqrrm 2021-03-11 17:24:55 +01:00 committed by GitHub
commit edbac95f7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 8 deletions

View file

@ -65,6 +65,7 @@ class CoreOffersService {
private final Supplier<Comparator<Offer>> priceComparator = () -> comparing(Offer::getPrice);
private final Supplier<Comparator<Offer>> reversePriceComparator = () -> comparing(Offer::getPrice).reversed();
private final CoreContext coreContext;
private final KeyRing keyRing;
// Dependencies on core api services in this package must be kept to an absolute
// minimum, but some trading functions require an unlocked wallet's key, so an
@ -76,7 +77,6 @@ class CoreOffersService {
private final OpenOfferManager openOfferManager;
private final OfferUtil offerUtil;
private final User user;
private final boolean isApiUser;
@Inject
public CoreOffersService(CoreContext coreContext,
@ -88,6 +88,7 @@ class CoreOffersService {
OpenOfferManager openOfferManager,
OfferUtil offerUtil,
User user) {
this.coreContext = coreContext;
this.keyRing = keyRing;
this.coreWalletsService = coreWalletsService;
this.createOfferService = createOfferService;
@ -96,14 +97,13 @@ class CoreOffersService {
this.openOfferManager = openOfferManager;
this.offerUtil = offerUtil;
this.user = user;
this.isApiUser = coreContext.isApiUser();
}
Offer getOffer(String id) {
return offerBookService.getOffers().stream()
.filter(o -> o.getId().equals(id))
.filter(o -> !o.isMyOffer(keyRing))
.filter(o -> offerFilter.canTakeOffer(o, isApiUser).isValid())
.filter(o -> offerFilter.canTakeOffer(o, coreContext.isApiUser()).isValid())
.findAny().orElseThrow(() ->
new IllegalStateException(format("offer with id '%s' not found", id)));
}
@ -120,7 +120,7 @@ class CoreOffersService {
return offerBookService.getOffers().stream()
.filter(o -> !o.isMyOffer(keyRing))
.filter(o -> offerMatchesDirectionAndCurrency(o, direction, currencyCode))
.filter(o -> offerFilter.canTakeOffer(o, isApiUser).isValid())
.filter(o -> offerFilter.canTakeOffer(o, coreContext.isApiUser()).isValid())
.sorted(priceComparator(direction))
.collect(Collectors.toList());
}

View file

@ -49,11 +49,11 @@ import static java.lang.String.format;
@Slf4j
class CoreTradesService {
private final CoreContext coreContext;
// Dependencies on core api services in this package must be kept to an absolute
// minimum, but some trading functions require an unlocked wallet's key, so an
// exception is made in this case.
private final CoreWalletsService coreWalletsService;
private final BtcWalletService btcWalletService;
private final OfferUtil offerUtil;
private final ClosedTradableManager closedTradableManager;
@ -61,7 +61,6 @@ class CoreTradesService {
private final TradeManager tradeManager;
private final TradeUtil tradeUtil;
private final User user;
private final boolean isApiUser;
@Inject
public CoreTradesService(CoreContext coreContext,
@ -73,6 +72,7 @@ class CoreTradesService {
TradeManager tradeManager,
TradeUtil tradeUtil,
User user) {
this.coreContext = coreContext;
this.coreWalletsService = coreWalletsService;
this.btcWalletService = btcWalletService;
this.offerUtil = offerUtil;
@ -81,7 +81,6 @@ class CoreTradesService {
this.tradeManager = tradeManager;
this.tradeUtil = tradeUtil;
this.user = user;
this.isApiUser = coreContext.isApiUser();
}
void takeOffer(Offer offer,
@ -113,7 +112,7 @@ class CoreTradesService {
offer,
paymentAccountId,
useSavingsWallet,
isApiUser,
coreContext.isApiUser(),
resultHandler::accept,
errorMessage -> {
log.error(errorMessage);