Add delegate methods to offer

Remove unused methods
This commit is contained in:
chimp1984 2021-10-20 12:49:11 +02:00
parent 8768345b74
commit d1d1706a7f
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3
10 changed files with 46 additions and 44 deletions

View File

@ -642,7 +642,7 @@ public class AccountAgeWitnessService {
checkNotNull(offer);
final String currencyCode = offer.getCurrencyCode();
final Coin defaultMaxTradeLimit = PaymentMethod.getPaymentMethodById(
offer.getOfferPayload().getPaymentMethodId()).getMaxTradeLimitAsCoin(currencyCode);
offer.getPaymentMethodId()).getMaxTradeLimitAsCoin(currencyCode);
long peersCurrentTradeLimit = defaultMaxTradeLimit.value;
if (!hasTradeLimitException(peersWitness)) {
final long accountSignAge = getWitnessSignAge(peersWitness, peersCurrentDate);

View File

@ -256,7 +256,7 @@ class CoreOffersService {
editedMarketPriceMargin,
editType);
Offer editedOffer = new Offer(editedPayload);
priceFeedService.setCurrencyCode(openOffer.getOffer().getOfferPayload().getCurrencyCode());
priceFeedService.setCurrencyCode(openOffer.getOffer().getCurrencyCode());
editedOffer.setPriceFeedService(priceFeedService);
editedOffer.setState(State.AVAILABLE);
openOfferManager.editOpenOfferStart(openOffer,
@ -302,7 +302,7 @@ class CoreOffersService {
// code fields. Note: triggerPrice isDeactivated fields are in OpenOffer, not
// in OfferPayload.
Offer offer = openOffer.getOffer();
String currencyCode = offer.getOfferPayload().getCurrencyCode();
String currencyCode = offer.getCurrencyCode();
boolean isEditingPrice = editType.equals(FIXED_PRICE_ONLY) || editType.equals(FIXED_PRICE_AND_ACTIVATION_STATE);
Price editedPrice;
if (isEditingPrice) {
@ -320,15 +320,15 @@ class CoreOffersService {
Objects.requireNonNull(editedPrice).getValue(),
isUsingMktPriceMargin ? exactMultiply(editedMarketPriceMargin, 0.01) : 0.00,
isUsingMktPriceMargin,
offer.getOfferPayload().getBaseCurrencyCode(),
offer.getOfferPayload().getCounterCurrencyCode(),
offer.getBaseCurrencyCode(),
offer.getCounterCurrencyCode(),
offer.getPaymentMethod().getId(),
offer.getMakerPaymentAccountId(),
offer.getOfferPayload().getCountryCode(),
offer.getOfferPayload().getAcceptedCountryCodes(),
offer.getOfferPayload().getBankId(),
offer.getOfferPayload().getAcceptedBankIds(),
offer.getOfferPayload().getExtraDataMap());
offer.getCountryCode(),
offer.getAcceptedCountryCodes(),
offer.getBankId(),
offer.getAcceptedBankIds(),
offer.getExtraDataMap());
log.info("Merging OfferPayload with {}", mutableOfferPayloadFields);
return offerUtil.getMergedOfferPayload(openOffer, mutableOfferPayloadFields);
}
@ -336,7 +336,7 @@ class CoreOffersService {
private void verifyPaymentAccountIsValidForNewOffer(Offer offer, PaymentAccount paymentAccount) {
if (!isPaymentAccountValidForOffer(offer, paymentAccount)) {
String error = format("cannot create %s offer with payment account %s",
offer.getOfferPayload().getCounterCurrencyCode(),
offer.getCounterCurrencyCode(),
paymentAccount.getId());
throw new IllegalStateException(error);
}
@ -346,7 +346,7 @@ class CoreOffersService {
String direction,
String currencyCode) {
var offerOfWantedDirection = offer.getDirection().name().equalsIgnoreCase(direction);
var offerInWantedCurrency = offer.getOfferPayload().getCounterCurrencyCode()
var offerInWantedCurrency = offer.getCounterCurrencyCode()
.equalsIgnoreCase(currencyCode);
return offerOfWantedDirection && offerInWantedCurrency;
}

View File

@ -144,8 +144,8 @@ public class OfferInfo implements Payload {
.withPaymentAccountId(offer.getMakerPaymentAccountId())
.withPaymentMethodId(offer.getPaymentMethod().getId())
.withPaymentMethodShortName(offer.getPaymentMethod().getShortName())
.withBaseCurrencyCode(offer.getOfferPayload().getBaseCurrencyCode())
.withCounterCurrencyCode(offer.getOfferPayload().getCounterCurrencyCode())
.withBaseCurrencyCode(offer.getBaseCurrencyCode())
.withCounterCurrencyCode(offer.getCounterCurrencyCode())
.withDate(offer.getDate().getTime())
.withState(offer.getState().name())
.withIsMyOffer(isMyOffer);

View File

@ -109,7 +109,7 @@ public class MarketAlerts {
// % price get multiplied by 10000 to have 0.12% be converted to 12. For fixed price we have precision of 8 for
// altcoins and precision of 4 for fiat.
private String getAlertId(Offer offer) {
double price = offer.isUseMarketBasedPrice() ? offer.getMarketPriceMargin() * 10000 : offer.getOfferPayload().getPrice();
double price = offer.isUseMarketBasedPrice() ? offer.getMarketPriceMargin() * 10000 : offer.getFixedPrice();
String priceString = String.valueOf((long) price);
return offer.getId() + "|" + priceString;
}

View File

@ -205,6 +205,10 @@ public class Offer implements NetworkPayload, PersistablePayload {
}
}
public long getFixedPrice() {
return offerPayload.getPrice();
}
public void checkTradePriceTolerance(long takersTradePrice) throws TradePriceOutOfToleranceException,
MarketPriceNotAvailableException, IllegalArgumentException {
Price tradePrice = Price.valueOf(getCurrencyCode(), takersTradePrice);
@ -351,7 +355,6 @@ public class Offer implements NetworkPayload, PersistablePayload {
return getPubKeyRing().equals(keyRing.getPubKeyRing());
}
public Optional<String> getAccountAgeWitnessHashAsHex() {
Map<String, String> extraDataMap = getExtraDataMap();
if (extraDataMap != null && extraDataMap.containsKey(OfferPayload.ACCOUNT_AGE_WITNESS_HASH))
@ -435,12 +438,24 @@ public class Offer implements NetworkPayload, PersistablePayload {
return currencyCode;
}
currencyCode = offerPayload.getBaseCurrencyCode().equals("BTC") ?
offerPayload.getCounterCurrencyCode() :
offerPayload.getBaseCurrencyCode();
currencyCode = getBaseCurrencyCode().equals("BTC") ?
getCounterCurrencyCode() :
getBaseCurrencyCode();
return currencyCode;
}
public String getCounterCurrencyCode() {
return offerPayload.getCounterCurrencyCode();
}
public String getBaseCurrencyCode() {
return offerPayload.getBaseCurrencyCode();
}
public String getPaymentMethodId() {
return offerPayload.getPaymentMethodId();
}
public long getProtocolVersion() {
return offerPayload.getProtocolVersion();
}
@ -495,27 +510,10 @@ public class Offer implements NetworkPayload, PersistablePayload {
return offerPayload.isUseAutoClose();
}
public long getBlockHeightAtOfferCreation() {
return offerPayload.getBlockHeightAtOfferCreation();
}
@Nullable
public String getHashOfChallenge() {
return offerPayload.getHashOfChallenge();
}
public boolean isPrivateOffer() {
return offerPayload.isPrivateOffer();
}
public long getUpperClosePrice() {
return offerPayload.getUpperClosePrice();
}
public long getLowerClosePrice() {
return offerPayload.getLowerClosePrice();
}
public boolean isUseReOpenAfterAutoClose() {
return offerPayload.isUseReOpenAfterAutoClose();
}
@ -535,6 +533,10 @@ public class Offer implements NetworkPayload, PersistablePayload {
return getCurrencyCode().equals("XMR");
}
public byte[] getOfferPayloadHash() {
return offerPayload.getHash();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -42,7 +42,7 @@ public class OfferRestrictions {
public static Coin TOLERATED_SMALL_TRADE_AMOUNT = Coin.parseCoin("0.01");
static boolean hasOfferMandatoryCapability(Offer offer, Capability mandatoryCapability) {
Map<String, String> extraDataMap = offer.getOfferPayload().getExtraDataMap();
Map<String, String> extraDataMap = offer.getExtraDataMap();
if (extraDataMap != null && extraDataMap.containsKey(OfferPayload.CAPABILITIES)) {
String commaSeparatedOrdinals = extraDataMap.get(OfferPayload.CAPABILITIES);
Capabilities capabilities = Capabilities.fromStringList(commaSeparatedOrdinals);

View File

@ -211,8 +211,8 @@ public class MarketView extends ActivatableView<TabPane, Void> {
private String getAllOffersWithReferralId() {
List<String> list = offerBook.getOfferBookListItems().stream()
.map(OfferBookListItem::getOffer)
.filter(offer -> offer.getOfferPayload().getExtraDataMap() != null)
.filter(offer -> offer.getOfferPayload().getExtraDataMap().get(OfferPayload.REFERRAL_ID) != null)
.filter(offer -> offer.getExtraDataMap() != null)
.filter(offer -> offer.getExtraDataMap().get(OfferPayload.REFERRAL_ID) != null)
.map(offer -> {
StringBuilder sb = new StringBuilder();
sb.append("Offer ID: ").append(offer.getId()).append("\n")
@ -221,7 +221,7 @@ public class MarketView extends ActivatableView<TabPane, Void> {
.append("Price: ").append(FormattingUtils.formatPrice(offer.getPrice())).append("\n")
.append("Amount: ").append(DisplayUtils.formatAmount(offer, formatter)).append(" BTC\n")
.append("Payment method: ").append(Res.get(offer.getPaymentMethod().getId())).append("\n")
.append("ReferralID: ").append(offer.getOfferPayload().getExtraDataMap().get(OfferPayload.REFERRAL_ID));
.append("ReferralID: ").append(offer.getExtraDataMap().get(OfferPayload.REFERRAL_ID));
return sb.toString();
})
.collect(Collectors.toList());

View File

@ -140,7 +140,7 @@ public class OfferBook {
offer.setState(Offer.State.REMOVED);
offer.cancelAvailabilityRequest();
P2PDataStorage.ByteArray hashOfPayload = new P2PDataStorage.ByteArray(offer.getOfferPayload().getHash());
P2PDataStorage.ByteArray hashOfPayload = new P2PDataStorage.ByteArray(offer.getOfferPayloadHash());
if (log.isDebugEnabled()) { // TODO delete debug stmt in future PR.
log.debug("onRemoved: id = {}\n"

View File

@ -66,7 +66,7 @@ public class OfferBookListItem {
public OfferBookListItem(Offer offer) {
this.offer = offer;
this.hashOfPayload = new P2PDataStorage.ByteArray(offer.getOfferPayload().getHash());
this.hashOfPayload = new P2PDataStorage.ByteArray(offer.getOfferPayloadHash());
}
public WitnessAgeData getWitnessAgeData(AccountAgeWitnessService accountAgeWitnessService,

View File

@ -1076,11 +1076,11 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
button.setStyle("-fx-text-fill: white");
if (isSellOffer) {
title = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ?
Res.get("offerbook.takeOfferToBuy", offer.getOfferPayload().getBaseCurrencyCode()) :
Res.get("offerbook.takeOfferToBuy", offer.getBaseCurrencyCode()) :
Res.get("offerbook.takeOfferToSell", offer.getCurrencyCode());
} else {
title = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ?
Res.get("offerbook.takeOfferToSell", offer.getOfferPayload().getBaseCurrencyCode()) :
Res.get("offerbook.takeOfferToSell", offer.getBaseCurrencyCode()) :
Res.get("offerbook.takeOfferToBuy", offer.getCurrencyCode());
}
button.setTooltip(new Tooltip(Res.get("offerbook.takeOfferButton.tooltip", model.getDirectionLabelTooltip(offer))));