Change OfferInfo proto's 'price' field type to string

Much less ambiguous field value at cost of breaking backward compat in API.
This commit is contained in:
ghubstan 2022-02-17 17:27:15 -03:00
parent 135a42ba45
commit 461edff631
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
3 changed files with 13 additions and 12 deletions

View File

@ -28,6 +28,7 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import static bisq.core.util.PriceUtil.reformatMarketPrice;
import static java.util.Objects.requireNonNull;
@EqualsAndHashCode
@ -41,7 +42,7 @@ public class OfferInfo implements Payload {
private final String id;
private final String direction;
private final long price;
private final String price;
private final boolean useMarketBasedPrice;
private final double marketPriceMargin;
private final long amount;
@ -136,10 +137,13 @@ public class OfferInfo implements Payload {
}
private static OfferInfoBuilder getBuilder(Offer offer, boolean isMyOffer) {
var preciseOfferPrice = reformatMarketPrice(
requireNonNull(offer.getPrice()).toPlainString(),
offer.getCurrencyCode());
return new OfferInfoBuilder()
.withId(offer.getId())
.withDirection(offer.getDirection().name())
.withPrice(requireNonNull(offer.getPrice()).getValue())
.withPrice(preciseOfferPrice)
.withUseMarketBasedPrice(offer.isUseMarketBasedPrice())
.withMarketPriceMargin(offer.getMarketPriceMargin())
.withAmount(offer.getAmount().value)

View File

@ -32,7 +32,7 @@ public final class OfferInfoBuilder {
private String id;
private String direction;
private long price;
private String price;
private boolean useMarketBasedPrice;
private double marketPriceMargin;
private long amount;
@ -72,7 +72,7 @@ public final class OfferInfoBuilder {
return this;
}
public OfferInfoBuilder withPrice(long price) {
public OfferInfoBuilder withPrice(String price) {
this.price = price;
return this;
}

View File

@ -242,8 +242,8 @@ message EditOfferRequest {
// 0 = disable
// 1 = enable
sint32 enable = 6;
// The EditType determines and constricts what offer details can
// be modified by the request, simplifying param validation.
// The EditType determines and constricts what offer details can be modified by the request, simplifying param
// validation. (The CLI need to infer this detail from 'editoffer' command options, other clients do not.)
enum EditType {
// Edit only the offer's activation state (enabled or disabled).
ACTIVATION_STATE_ONLY = 0;
@ -286,12 +286,9 @@ message OfferInfo {
string id = 1;
// The offer's BUY (BTC) or SELL (BTC) direction.
string direction = 2;
// For fiat offers: a long representing the BTC price of the offer to 4 decimal places.
// A USD fiat price of 45000.4321 USD is represented as 450004321.
// For altcoin offers: a long representing the BTC price of the offer in satoshis.
// An altcoin price of five hundred thousand satoshis is represented as 500000.
// TODO: Change to string type.
uint64 price = 3;
// For fiat offers: the fiat price for 1 BTC to 4 decimal places, e.g., 45000 EUR is "45000.0000".
// For altcoin offers: the altcoin price for 1 BTC to 8 decimal places, e.g., 0.5 BTC is "0.00005000".
string price = 3;
// Whether the offer price is fixed, or market price margin based.
bool useMarketBasedPrice = 4;
// The offer's market price margin above or below the current market BTC price, represented as a decimal.