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

Refactor EditOfferDataModel for new editoffer api method #5571

Merged
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
89 changes: 89 additions & 0 deletions core/src/main/java/bisq/core/offer/MutableOfferPayloadFields.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.offer;

import java.util.List;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.annotation.Nullable;

/**
* The set of editable OfferPayload fields.
*/
@Getter
@Setter
@ToString
public final class MutableOfferPayloadFields {

private final long price;
private final double marketPriceMargin;
private final boolean useMarketBasedPrice;
private final String baseCurrencyCode;
private final String counterCurrencyCode;
private final String paymentMethodId;
private final String makerPaymentAccountId;
@Nullable
private final String countryCode;
@Nullable
private final List<String> acceptedCountryCodes;
@Nullable
private final String bankId;
@Nullable
private final List<String> acceptedBankIds;

public MutableOfferPayloadFields(OfferPayload offerPayload) {
this(offerPayload.getPrice(),
offerPayload.getMarketPriceMargin(),
offerPayload.isUseMarketBasedPrice(),
offerPayload.getBaseCurrencyCode(),
offerPayload.getCounterCurrencyCode(),
offerPayload.getPaymentMethodId(),
offerPayload.getMakerPaymentAccountId(),
offerPayload.getCountryCode(),
offerPayload.getAcceptedCountryCodes(),
offerPayload.getBankId(),
offerPayload.getAcceptedBankIds());
}

public MutableOfferPayloadFields(long price,
double marketPriceMargin,
boolean useMarketBasedPrice,
String baseCurrencyCode,
String counterCurrencyCode,
String paymentMethodId,
String makerPaymentAccountId,
@Nullable String countryCode,
@Nullable List<String> acceptedCountryCodes,
@Nullable String bankId,
@Nullable List<String> acceptedBankIds) {
this.price = price;
this.marketPriceMargin = marketPriceMargin;
this.useMarketBasedPrice = useMarketBasedPrice;
this.baseCurrencyCode = baseCurrencyCode;
this.counterCurrencyCode = counterCurrencyCode;
this.paymentMethodId = paymentMethodId;
this.makerPaymentAccountId = makerPaymentAccountId;
this.countryCode = countryCode;
this.acceptedCountryCodes = acceptedCountryCodes;
this.bankId = bankId;
this.acceptedBankIds = acceptedBankIds;
}
}
47 changes: 47 additions & 0 deletions core/src/main/java/bisq/core/offer/OfferUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,53 @@ public void validateOfferData(double buyerSecurityDeposit,
Res.get("offerbook.warning.paymentMethodBanned"));
}

// Returns an edited payload: a merge of the original offerPayload and
// editedOfferPayload fields. Mutable fields are sourced from
// mutableOfferPayloadFields param, e.g., payment account details, price, etc.
// Immutable fields are sourced from the original openOffer param.
ghubstan marked this conversation as resolved.
Show resolved Hide resolved
public OfferPayload getMergedOfferPayload(OpenOffer openOffer,
MutableOfferPayloadFields mutableOfferPayloadFields) {
OfferPayload originalOfferPayload = openOffer.getOffer().getOfferPayload();
return new OfferPayload(originalOfferPayload.getId(),
originalOfferPayload.getDate(),
originalOfferPayload.getOwnerNodeAddress(),
originalOfferPayload.getPubKeyRing(),
originalOfferPayload.getDirection(),
mutableOfferPayloadFields.getPrice(),
mutableOfferPayloadFields.getMarketPriceMargin(),
mutableOfferPayloadFields.isUseMarketBasedPrice(),
originalOfferPayload.getAmount(),
originalOfferPayload.getMinAmount(),
mutableOfferPayloadFields.getBaseCurrencyCode(),
mutableOfferPayloadFields.getCounterCurrencyCode(),
originalOfferPayload.getArbitratorNodeAddresses(),
originalOfferPayload.getMediatorNodeAddresses(),
mutableOfferPayloadFields.getPaymentMethodId(),
mutableOfferPayloadFields.getMakerPaymentAccountId(),
originalOfferPayload.getOfferFeePaymentTxId(),
mutableOfferPayloadFields.getCountryCode(),
mutableOfferPayloadFields.getAcceptedCountryCodes(),
mutableOfferPayloadFields.getBankId(),
mutableOfferPayloadFields.getAcceptedBankIds(),
originalOfferPayload.getVersionNr(),
originalOfferPayload.getBlockHeightAtOfferCreation(),
originalOfferPayload.getTxFee(),
originalOfferPayload.getMakerFee(),
originalOfferPayload.isCurrencyForMakerFeeBtc(),
originalOfferPayload.getBuyerSecurityDeposit(),
originalOfferPayload.getSellerSecurityDeposit(),
originalOfferPayload.getMaxTradeLimit(),
originalOfferPayload.getMaxTradePeriod(),
originalOfferPayload.isUseAutoClose(),
originalOfferPayload.isUseReOpenAfterAutoClose(),
originalOfferPayload.getLowerClosePrice(),
originalOfferPayload.getUpperClosePrice(),
originalOfferPayload.isPrivateOffer(),
originalOfferPayload.getHashOfChallenge(),
originalOfferPayload.getExtraDataMap(),
originalOfferPayload.getProtocolVersion());
}

private Optional<Volume> getFeeInUserFiatCurrency(Coin makerFee,
boolean isCurrencyForMakerFeeBtc,
String userCurrencyCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.TradeCurrency;
import bisq.core.offer.CreateOfferService;
import bisq.core.offer.MutableOfferPayloadFields;
import bisq.core.offer.Offer;
import bisq.core.offer.OfferPayload;
import bisq.core.offer.OfferUtil;
Expand Down Expand Up @@ -182,54 +183,12 @@ public void onStartEditOffer(ErrorMessageHandler errorMessageHandler) {
}

public void onPublishOffer(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
// editedPayload is a merge of the original offerPayload and newOfferPayload
// fields which are editable are merged in from newOfferPayload (such as payment account details)
// fields which cannot change (most importantly BTC amount) are sourced from the original offerPayload
final OfferPayload offerPayload = openOffer.getOffer().getOfferPayload();
final OfferPayload newOfferPayload = createAndGetOffer().getOfferPayload();
final OfferPayload editedPayload = new OfferPayload(offerPayload.getId(),
offerPayload.getDate(),
offerPayload.getOwnerNodeAddress(),
offerPayload.getPubKeyRing(),
offerPayload.getDirection(),
newOfferPayload.getPrice(),
newOfferPayload.getMarketPriceMargin(),
newOfferPayload.isUseMarketBasedPrice(),
offerPayload.getAmount(),
offerPayload.getMinAmount(),
newOfferPayload.getBaseCurrencyCode(),
newOfferPayload.getCounterCurrencyCode(),
offerPayload.getArbitratorNodeAddresses(),
offerPayload.getMediatorNodeAddresses(),
newOfferPayload.getPaymentMethodId(),
newOfferPayload.getMakerPaymentAccountId(),
offerPayload.getOfferFeePaymentTxId(),
newOfferPayload.getCountryCode(),
newOfferPayload.getAcceptedCountryCodes(),
newOfferPayload.getBankId(),
newOfferPayload.getAcceptedBankIds(),
offerPayload.getVersionNr(),
offerPayload.getBlockHeightAtOfferCreation(),
offerPayload.getTxFee(),
offerPayload.getMakerFee(),
offerPayload.isCurrencyForMakerFeeBtc(),
offerPayload.getBuyerSecurityDeposit(),
offerPayload.getSellerSecurityDeposit(),
offerPayload.getMaxTradeLimit(),
offerPayload.getMaxTradePeriod(),
offerPayload.isUseAutoClose(),
offerPayload.isUseReOpenAfterAutoClose(),
offerPayload.getLowerClosePrice(),
offerPayload.getUpperClosePrice(),
offerPayload.isPrivateOffer(),
offerPayload.getHashOfChallenge(),
offerPayload.getExtraDataMap(),
offerPayload.getProtocolVersion());

MutableOfferPayloadFields mutableOfferPayloadFields =
new MutableOfferPayloadFields(createAndGetOffer().getOfferPayload());
final OfferPayload editedPayload = offerUtil.getMergedOfferPayload(openOffer, mutableOfferPayloadFields);
final Offer editedOffer = new Offer(editedPayload);
editedOffer.setPriceFeedService(priceFeedService);
editedOffer.setState(Offer.State.AVAILABLE);

openOfferManager.editOpenOfferPublish(editedOffer, triggerPrice, initialState, () -> {
openOffer = null;
resultHandler.handleResult();
Expand Down