Partially adjust api proto wrappers for bsq-swap support

- Complete BsqSwapTradeInfo impl.
- Merge BsqSwapOfferInfo fields into OfferInfo and remove BsqSwapOfferInfo.
- Change all model builders to private static class Builder.
This commit is contained in:
ghubstan 2021-11-11 13:01:48 -03:00
parent c6aceb0458
commit 5d63fd7e39
No known key found for this signature in database
GPG key ID: E35592D6800A861E
5 changed files with 216 additions and 410 deletions

View file

@ -1,227 +0,0 @@
/*
* 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.api.model;
import bisq.core.offer.Offer;
import bisq.common.Payload;
import java.util.Objects;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@EqualsAndHashCode
@ToString
@Getter
public class BsqSwapOfferInfo implements Payload {
private final String id;
private final String direction;
private final long amount;
private final long minAmount;
private final long price;
private final String makerPaymentAccountId;
private final String paymentMethodId;
private final String paymentMethodShortName;
private final String baseCurrencyCode;
private final String counterCurrencyCode;
private final long date;
private final String ownerNodeAddress;
private final String pubKeyRing; // TODO ?
private final String versionNumber;
private final int protocolVersion;
public BsqSwapOfferInfo(BsqSwapOfferInfoBuilder builder) {
this.id = builder.id;
this.direction = builder.direction;
this.amount = builder.amount;
this.minAmount = builder.minAmount;
this.price = builder.price;
this.makerPaymentAccountId = builder.makerPaymentAccountId;
this.paymentMethodId = builder.paymentMethodId;
this.paymentMethodShortName = builder.paymentMethodShortName;
this.baseCurrencyCode = builder.baseCurrencyCode;
this.counterCurrencyCode = builder.counterCurrencyCode;
this.date = builder.date;
this.ownerNodeAddress = builder.ownerNodeAddress;
this.pubKeyRing = builder.pubKeyRing;
this.versionNumber = builder.versionNumber;
this.protocolVersion = builder.protocolVersion;
}
public static BsqSwapOfferInfo toBsqSwapOfferInfo(Offer offer) {
// TODO support triggerPrice
return getAtomicOfferInfoBuilder(offer).build();
}
private static BsqSwapOfferInfoBuilder getAtomicOfferInfoBuilder(Offer offer) {
return new BsqSwapOfferInfoBuilder()
.withId(offer.getId())
.withDirection(offer.getDirection().name())
.withAmount(offer.getAmount().value)
.withMinAmount(offer.getMinAmount().value)
.withPrice(Objects.requireNonNull(offer.getPrice()).getValue())
//.withMakerPaymentAccountId(offer.getOfferPayloadI().getMakerPaymentAccountId())
//.withPaymentMethodId(offer.getOfferPayloadI().getPaymentMethodId())
//.withPaymentMethodShortName(getPaymentMethodById(offer.getOfferPayloadI().getPaymentMethodId()).getShortName())
.withBaseCurrencyCode(offer.getOfferPayloadBase().getBaseCurrencyCode())
.withCounterCurrencyCode(offer.getOfferPayloadBase().getCounterCurrencyCode())
.withDate(offer.getDate().getTime())
.withOwnerNodeAddress(offer.getOfferPayloadBase().getOwnerNodeAddress().getFullAddress())
.withPubKeyRing(offer.getOfferPayloadBase().getPubKeyRing().toString())
.withVersionNumber(offer.getOfferPayloadBase().getVersionNr())
.withProtocolVersion(offer.getOfferPayloadBase().getProtocolVersion());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public bisq.proto.grpc.BsqSwapOfferInfo toProtoMessage() {
return bisq.proto.grpc.BsqSwapOfferInfo.newBuilder()
.setId(id)
.setDirection(direction)
.setAmount(amount)
.setMinAmount(minAmount)
.setPrice(price)
.setBaseCurrencyCode(baseCurrencyCode)
.setCounterCurrencyCode(counterCurrencyCode)
.setDate(date)
.setOwnerNodeAddress(ownerNodeAddress)
.setPubKeyRing(pubKeyRing)
.setVersionNr(versionNumber)
.setProtocolVersion(protocolVersion)
.build();
}
public static BsqSwapOfferInfo fromProto(bisq.proto.grpc.BsqSwapOfferInfo proto) {
return new BsqSwapOfferInfoBuilder()
.withId(proto.getId())
.withDirection(proto.getDirection())
.withAmount(proto.getAmount())
.withMinAmount(proto.getMinAmount())
.withPrice(proto.getPrice())
.withBaseCurrencyCode(proto.getBaseCurrencyCode())
.withCounterCurrencyCode(proto.getCounterCurrencyCode())
.withDate(proto.getDate())
.withOwnerNodeAddress(proto.getOwnerNodeAddress())
.withPubKeyRing(proto.getPubKeyRing())
.withVersionNumber(proto.getVersionNr())
.withProtocolVersion(proto.getProtocolVersion())
.build();
}
public static class BsqSwapOfferInfoBuilder {
private String id;
private String direction;
private long amount;
private long minAmount;
private long price;
private String makerPaymentAccountId;
private String paymentMethodId;
private String paymentMethodShortName;
private String baseCurrencyCode;
private String counterCurrencyCode;
private long date;
private String ownerNodeAddress;
private String pubKeyRing;
private String versionNumber;
private int protocolVersion;
public BsqSwapOfferInfoBuilder withId(String id) {
this.id = id;
return this;
}
public BsqSwapOfferInfoBuilder withDirection(String direction) {
this.direction = direction;
return this;
}
public BsqSwapOfferInfoBuilder withAmount(long amount) {
this.amount = amount;
return this;
}
public BsqSwapOfferInfoBuilder withMinAmount(long minAmount) {
this.minAmount = minAmount;
return this;
}
public BsqSwapOfferInfoBuilder withPrice(long price) {
this.price = price;
return this;
}
public BsqSwapOfferInfoBuilder withMakerPaymentAccountId(String makerPaymentAccountId) {
this.makerPaymentAccountId = makerPaymentAccountId;
return this;
}
public BsqSwapOfferInfoBuilder withPaymentMethodId(String paymentMethodId) {
this.paymentMethodId = paymentMethodId;
return this;
}
public BsqSwapOfferInfoBuilder withPaymentMethodShortName(String paymentMethodShortName) {
this.paymentMethodShortName = paymentMethodShortName;
return this;
}
public BsqSwapOfferInfoBuilder withBaseCurrencyCode(String baseCurrencyCode) {
this.baseCurrencyCode = baseCurrencyCode;
return this;
}
public BsqSwapOfferInfoBuilder withCounterCurrencyCode(String counterCurrencyCode) {
this.counterCurrencyCode = counterCurrencyCode;
return this;
}
public BsqSwapOfferInfoBuilder withDate(long date) {
this.date = date;
return this;
}
public BsqSwapOfferInfoBuilder withOwnerNodeAddress(String ownerNodeAddress) {
this.ownerNodeAddress = ownerNodeAddress;
return this;
}
public BsqSwapOfferInfoBuilder withPubKeyRing(String pubKeyRing) {
this.pubKeyRing = pubKeyRing;
return this;
}
public BsqSwapOfferInfoBuilder withVersionNumber(String versionNumber) {
this.versionNumber = versionNumber;
return this;
}
public BsqSwapOfferInfoBuilder withProtocolVersion(int protocolVersion) {
this.protocolVersion = protocolVersion;
return this;
}
public BsqSwapOfferInfo build() {
return new BsqSwapOfferInfo(this);
}
}
}

View file

@ -25,24 +25,21 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import static bisq.core.api.model.BsqSwapOfferInfo.toBsqSwapOfferInfo;
import static bisq.core.api.model.OfferInfo.toMyOfferInfo;
import static bisq.core.api.model.OfferInfo.toOfferInfo;
@EqualsAndHashCode
@ToString
@Getter
public class BsqSwapTradeInfo implements Payload {
private final BsqSwapOfferInfo bsqSwapOffer;
private final OfferInfo bsqSwapOffer;
private final String tradeId;
private final String tempTradingPeerNodeAddress;
private final String peerNodeAddress;
private final String txId;
private final long bsqTradeAmount;
private final long bsqMaxTradeAmount;
private final long bsqMinTradeAmount;
private final long btcTradeAmount;
private final long btcMaxTradeAmount;
private final long btcMinTradeAmount;
private final long tradePrice;
private final long bsqMakerTradeFee;
private final long bsqTakerTradeFee;
@ -53,21 +50,18 @@ public class BsqSwapTradeInfo implements Payload {
private final String takerBsqAddress;
private final String takerBtcAddress;
private final long takeOfferDate;
private final String role;
private final String state;
private final String errorMessage;
public BsqSwapTradeInfo(BsqSwapTradeInfoBuilder builder) {
this.bsqSwapOffer = builder.bsqSwapOfferInfo;
public BsqSwapTradeInfo(Builder builder) {
this.bsqSwapOffer = builder.bsqSwapOffer;
this.tradeId = builder.tradeId;
this.tempTradingPeerNodeAddress = builder.tempTradingPeerNodeAddress;
this.peerNodeAddress = builder.peerNodeAddress;
this.txId = builder.txId;
this.bsqTradeAmount = builder.bsqTradeAmount;
this.bsqMaxTradeAmount = builder.bsqMaxTradeAmount;
this.bsqMinTradeAmount = builder.bsqMinTradeAmount;
this.btcTradeAmount = builder.btcTradeAmount;
this.btcMaxTradeAmount = builder.btcMaxTradeAmount;
this.btcMinTradeAmount = builder.btcMinTradeAmount;
this.tradePrice = builder.tradePrice;
this.bsqMakerTradeFee = builder.bsqMakerTradeFee;
this.bsqTakerTradeFee = builder.bsqTakerTradeFee;
@ -78,38 +72,38 @@ public class BsqSwapTradeInfo implements Payload {
this.takerBsqAddress = builder.takerBsqAddress;
this.takerBtcAddress = builder.takerBtcAddress;
this.takeOfferDate = builder.takeOfferDate;
this.role = builder.role;
this.state = builder.state;
this.errorMessage = builder.errorMessage;
}
public static BsqSwapTradeInfo toBsqSwapTradeInfo(BsqSwapTrade trade) {
return toBsqSwapTradeInfo(trade, null);
}
//TODO
public static BsqSwapTradeInfo toBsqSwapTradeInfo(BsqSwapTrade trade, String role) {
return new BsqSwapTradeInfoBuilder()
.withBsqSwapOffer(toBsqSwapOfferInfo(trade.getOffer()))
public static BsqSwapTradeInfo toBsqSwapTradeInfo(BsqSwapTrade trade, String role, boolean wasMyOffer) {
var protocolModel = trade.getBsqSwapProtocolModel();
var swapPeer = protocolModel.getTradePeer();
var makerBsqAddress = wasMyOffer ? protocolModel.getBsqAddress() : swapPeer.getBsqAddress();
var makerBtcAddress = wasMyOffer ? protocolModel.getBtcAddress() : swapPeer.getBtcAddress();
var takerBsqAddress = wasMyOffer ? swapPeer.getBsqAddress() : protocolModel.getBsqAddress();
var takerBtcAddress = wasMyOffer ? swapPeer.getBtcAddress() : protocolModel.getBtcAddress();
var offerInfo = wasMyOffer ? toMyOfferInfo(trade.getOffer()) : toOfferInfo(trade.getOffer());
return new Builder()
.withBsqSwapOffer(offerInfo)
.withTradeId(trade.getId())
.withTempTradingPeerNodeAddress(trade.getBsqSwapProtocolModel().getTempTradingPeerNodeAddress().getFullAddress())
.withPeerNodeAddress(trade.getTradingPeerNodeAddress().getFullAddress())
.withTxId(trade.getTxId())
/* .withBsqTradeAmount(trade.getBsqSwapProtocolModel().getBsqTradeAmount())
.withBsqMaxTradeAmount(trade.getBsqSwapProtocolModel().getBsqMaxTradeAmount())
.withBsqMinTradeAmount(trade.getBsqSwapProtocolModel().getBsqMinTradeAmount())
.withBtcTradeAmount(trade.getBsqSwapProtocolModel().getBtcTradeAmount())
.withBtcMaxTradeAmount(trade.getBsqSwapProtocolModel().getBtcMaxTradeAmount())
.withBtcMinTradeAmount(trade.getBsqSwapProtocolModel().getBtcMinTradeAmount())
.withTradePrice(trade.getBsqSwapProtocolModel().getTradePrice())
.withBsqMakerTradeFee(trade.getBsqSwapProtocolModel().getBsqMakerTradeFee())
.withBsqTakerTradeFee(trade.getBsqSwapProtocolModel().getBsqTakerTradeFee())
.withTxFeePerVbyte(trade.getBsqSwapProtocolModel().getTxFeePerVbyte())
.withTxFee(trade.getBsqSwapProtocolModel().getTxFee())
.withMakerBsqAddress(trade.getBsqSwapProtocolModel().getMakerBsqAddress())
.withMakerBtcAddress(trade.getBsqSwapProtocolModel().getMakerBtcAddress())
.withTakerBsqAddress(trade.getBsqSwapProtocolModel().getTakerBsqAddress())
.withTakerBtcAddress(trade.getBsqSwapProtocolModel().getTakerBtcAddress())*/
.withBsqTradeAmount(trade.getBsqTradeAmount())
.withBtcTradeAmount(trade.getAmountAsLong())
.withTradePrice(trade.getPrice().getValue())
.withBsqMakerTradeFee(trade.getMakerFeeAsLong())
.withBsqTakerTradeFee(trade.getTakerFeeAsLong())
.withTxFeePerVbyte(trade.getTxFeePerVbyte())
.withTxFee(trade.getTxFee().value)
.withMakerBsqAddress(makerBsqAddress)
.withMakerBtcAddress(makerBtcAddress)
.withTakerBsqAddress(takerBsqAddress)
.withTakerBtcAddress(takerBtcAddress)
.withTakeOfferDate(trade.getTakeOfferDate())
.withRole(role == null ? "" : role)
.withState(trade.getTradeState().name())
.withErrorMessage(trade.getErrorMessage())
.build();
@ -122,17 +116,13 @@ public class BsqSwapTradeInfo implements Payload {
@Override
public bisq.proto.grpc.BsqSwapTradeInfo toProtoMessage() {
return bisq.proto.grpc.BsqSwapTradeInfo.newBuilder()
.setBsqSwapOfferInfo(bsqSwapOffer.toProtoMessage())
.setOffer(bsqSwapOffer.toProtoMessage())
.setTradeId(tradeId)
.setTempTradingPeerNodeAddress(tempTradingPeerNodeAddress != null ? tempTradingPeerNodeAddress : "")
.setPeerNodeAddress(peerNodeAddress != null ? peerNodeAddress : "")
.setTxId(txId != null ? txId : "")
.setBsqTradeAmount(bsqTradeAmount)
.setBsqMaxTradeAmount(bsqMaxTradeAmount)
.setBsqMinTradeAmount(bsqMinTradeAmount)
.setBtcTradeAmount(btcTradeAmount)
.setBtcMaxTradeAmount(btcMaxTradeAmount)
.setBtcMinTradeAmount(btcMinTradeAmount)
.setTradePrice(tradePrice)
.setBsqMakerTradeFee(bsqMakerTradeFee)
.setBsqTakerTradeFee(bsqTakerTradeFee)
@ -143,24 +133,21 @@ public class BsqSwapTradeInfo implements Payload {
.setMakerBtcAddress(makerBtcAddress != null ? makerBtcAddress : "")
.setTakerBtcAddress(takerBtcAddress != null ? takerBtcAddress : "")
.setTakeOfferDate(takeOfferDate)
.setRole(role)
.setState(state)
.setErrorMessage(errorMessage != null ? errorMessage : "")
.build();
}
public static BsqSwapTradeInfo fromProto(bisq.proto.grpc.BsqSwapTradeInfo proto) {
return new BsqSwapTradeInfoBuilder()
.withBsqSwapOffer(BsqSwapOfferInfo.fromProto(proto.getBsqSwapOfferInfo()))
return new Builder()
.withBsqSwapOffer(OfferInfo.fromProto(proto.getOffer()))
.withTradeId(proto.getTradeId())
.withTempTradingPeerNodeAddress(proto.getTempTradingPeerNodeAddress())
.withPeerNodeAddress(proto.getPeerNodeAddress())
.withTxId(proto.getTxId())
.withBsqTradeAmount(proto.getBsqTradeAmount())
.withBsqMaxTradeAmount(proto.getBsqMaxTradeAmount())
.withBsqMinTradeAmount(proto.getBsqMinTradeAmount())
.withBtcTradeAmount(proto.getBtcTradeAmount())
.withBtcMaxTradeAmount(proto.getBtcMaxTradeAmount())
.withBtcMinTradeAmount(proto.getBtcMinTradeAmount())
.withTradePrice(proto.getTradePrice())
.withBsqMakerTradeFee(proto.getBsqMakerTradeFee())
.withBsqTakerTradeFee(proto.getBsqTakerTradeFee())
@ -171,23 +158,20 @@ public class BsqSwapTradeInfo implements Payload {
.withTakerBsqAddress(proto.getTakerBsqAddress())
.withTakerBtcAddress(proto.getTakerBtcAddress())
.withTakeOfferDate(proto.getTakeOfferDate())
.withRole(proto.getRole())
.withState(proto.getState())
.withErrorMessage(proto.getErrorMessage())
.build();
}
public static class BsqSwapTradeInfoBuilder {
private BsqSwapOfferInfo bsqSwapOfferInfo;
private static class Builder {
private OfferInfo bsqSwapOffer;
private String tradeId;
private String tempTradingPeerNodeAddress;
private String peerNodeAddress;
private String txId;
private long bsqTradeAmount;
private long bsqMaxTradeAmount;
private long bsqMinTradeAmount;
private long btcTradeAmount;
private long btcMaxTradeAmount;
private long btcMinTradeAmount;
private long tradePrice;
private long bsqMakerTradeFee;
private long bsqTakerTradeFee;
@ -198,120 +182,106 @@ public class BsqSwapTradeInfo implements Payload {
private String takerBsqAddress;
private String takerBtcAddress;
private long takeOfferDate;
private String role;
private String state;
private String errorMessage;
public BsqSwapTradeInfoBuilder withBsqSwapOffer(BsqSwapOfferInfo bsqSwapOfferInfo) {
this.bsqSwapOfferInfo = bsqSwapOfferInfo;
public Builder withBsqSwapOffer(OfferInfo bsqSwapOffer) {
this.bsqSwapOffer = bsqSwapOffer;
return this;
}
public BsqSwapTradeInfoBuilder withTradeId(String tradeId) {
public Builder withTradeId(String tradeId) {
this.tradeId = tradeId;
return this;
}
public BsqSwapTradeInfoBuilder withTempTradingPeerNodeAddress(String tempTradingPeerNodeAddress) {
public Builder withTempTradingPeerNodeAddress(String tempTradingPeerNodeAddress) {
this.tempTradingPeerNodeAddress = tempTradingPeerNodeAddress;
return this;
}
public BsqSwapTradeInfoBuilder withPeerNodeAddress(String peerNodeAddress) {
public Builder withPeerNodeAddress(String peerNodeAddress) {
this.peerNodeAddress = peerNodeAddress;
return this;
}
public BsqSwapTradeInfoBuilder withTxId(String txId) {
public Builder withTxId(String txId) {
this.txId = txId;
return this;
}
public BsqSwapTradeInfoBuilder withBsqTradeAmount(long bsqTradeAmount) {
public Builder withBsqTradeAmount(long bsqTradeAmount) {
this.bsqTradeAmount = bsqTradeAmount;
return this;
}
public BsqSwapTradeInfoBuilder withBsqMaxTradeAmount(long bsqMaxTradeAmount) {
this.bsqMaxTradeAmount = bsqMaxTradeAmount;
return this;
}
public BsqSwapTradeInfoBuilder withBsqMinTradeAmount(long bsqMinTradeAmount) {
this.bsqMinTradeAmount = bsqMinTradeAmount;
return this;
}
public BsqSwapTradeInfoBuilder withBtcTradeAmount(long btcTradeAmount) {
public Builder withBtcTradeAmount(long btcTradeAmount) {
this.btcTradeAmount = btcTradeAmount;
return this;
}
public BsqSwapTradeInfoBuilder withBtcMaxTradeAmount(long btcMaxTradeAmount) {
this.btcMaxTradeAmount = btcMaxTradeAmount;
return this;
}
public BsqSwapTradeInfoBuilder withBtcMinTradeAmount(long btcMinTradeAmount) {
this.btcMinTradeAmount = btcMinTradeAmount;
return this;
}
public BsqSwapTradeInfoBuilder withTradePrice(long tradePrice) {
public Builder withTradePrice(long tradePrice) {
this.tradePrice = tradePrice;
return this;
}
public BsqSwapTradeInfoBuilder withBsqMakerTradeFee(long bsqMakerTradeFee) {
public Builder withBsqMakerTradeFee(long bsqMakerTradeFee) {
this.bsqMakerTradeFee = bsqMakerTradeFee;
return this;
}
public BsqSwapTradeInfoBuilder withBsqTakerTradeFee(long bsqTakerTradeFee) {
public Builder withBsqTakerTradeFee(long bsqTakerTradeFee) {
this.bsqTakerTradeFee = bsqTakerTradeFee;
return this;
}
public BsqSwapTradeInfoBuilder withTxFeePerVbyte(long txFeePerVbyte) {
public Builder withTxFeePerVbyte(long txFeePerVbyte) {
this.txFeePerVbyte = txFeePerVbyte;
return this;
}
public BsqSwapTradeInfoBuilder withTxFee(long txFee) {
public Builder withTxFee(long txFee) {
this.txFee = txFee;
return this;
}
public BsqSwapTradeInfoBuilder withMakerBsqAddress(String makerBsqAddress) {
public Builder withMakerBsqAddress(String makerBsqAddress) {
this.makerBsqAddress = makerBsqAddress;
return this;
}
public BsqSwapTradeInfoBuilder withMakerBtcAddress(String makerBtcAddress) {
public Builder withMakerBtcAddress(String makerBtcAddress) {
this.makerBtcAddress = makerBtcAddress;
return this;
}
public BsqSwapTradeInfoBuilder withTakerBsqAddress(String takerBsqAddress) {
public Builder withTakerBsqAddress(String takerBsqAddress) {
this.takerBsqAddress = takerBsqAddress;
return this;
}
public BsqSwapTradeInfoBuilder withTakerBtcAddress(String takerBtcAddress) {
public Builder withTakerBtcAddress(String takerBtcAddress) {
this.takerBtcAddress = takerBtcAddress;
return this;
}
public BsqSwapTradeInfoBuilder withTakeOfferDate(long takeOfferDate) {
public Builder withTakeOfferDate(long takeOfferDate) {
this.takeOfferDate = takeOfferDate;
return this;
}
public BsqSwapTradeInfoBuilder withState(String state) {
public Builder withRole(String role) {
this.role = role;
return this;
}
public Builder withState(String state) {
this.state = state;
return this;
}
public BsqSwapTradeInfoBuilder withErrorMessage(String errorMessage) {
public Builder withErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
return this;
}

View file

@ -19,6 +19,7 @@ package bisq.core.api.model;
import bisq.core.offer.Offer;
import bisq.core.offer.OpenOffer;
import bisq.core.util.coin.CoinUtil;
import bisq.common.Payload;
@ -28,6 +29,8 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import static java.util.Objects.requireNonNull;
@EqualsAndHashCode
@ToString
@Getter
@ -56,17 +59,22 @@ public class OfferInfo implements Payload {
private final String paymentAccountId;
private final String paymentMethodId;
private final String paymentMethodShortName;
// For fiat offer the baseCurrencyCode is BTC and the counterCurrencyCode is the fiat currency
// For altcoin offers it is the opposite. baseCurrencyCode is the altcoin and the counterCurrencyCode is BTC.
// Fiat offer: baseCurrencyCode = BTC, counterCurrencyCode = fiat ccy code.
// Altcoin offer: baseCurrencyCode = altcoin ccy code, counterCurrencyCode = BTC.
private final String baseCurrencyCode;
private final String counterCurrencyCode;
private final long date;
private final String state;
private final boolean isActivated;
private boolean isMyOffer; // Not final -- may be re-set after instantiation.
private final boolean isMyOffer;
private final boolean isMyPendingOffer;
private final boolean isBsqSwapOffer;
private final String ownerNodeAddress;
private final String pubKeyRing;
private final String versionNumber;
private final int protocolVersion;
public OfferInfo(OfferInfoBuilder builder) {
public OfferInfo(Builder builder) {
this.id = builder.id;
this.direction = builder.direction;
this.price = builder.price;
@ -93,39 +101,43 @@ public class OfferInfo implements Payload {
this.isActivated = builder.isActivated;
this.isMyOffer = builder.isMyOffer;
this.isMyPendingOffer = builder.isMyPendingOffer;
this.isBsqSwapOffer = builder.isBsqSwapOffer;
this.ownerNodeAddress = builder.ownerNodeAddress;
this.pubKeyRing = builder.pubKeyRing;
this.versionNumber = builder.versionNumber;
this.protocolVersion = builder.protocolVersion;
}
// Allow isMyOffer to be set on a new offer's OfferInfo instance.
public void setIsMyOffer(boolean isMyOffer) {
this.isMyOffer = isMyOffer;
public static OfferInfo toMyOfferInfo(Offer offer) {
return getBuilder(offer, true).build();
}
public static OfferInfo toOfferInfo(Offer offer) {
// Assume the offer is not mine, but isMyOffer can be reset to true, i.e., when
// calling TradeInfo toTradeInfo(Trade trade, String role, boolean isMyOffer);
return getOfferInfoBuilder(offer, false).build();
return getBuilder(offer, false).build();
}
public static OfferInfo toPendingOfferInfo(Offer myNewOffer) {
public static OfferInfo toMyPendingOfferInfo(Offer myNewOffer) {
// Use this to build an OfferInfo instance when a new OpenOffer is being
// prepared, and no valid OpenOffer state (AVAILABLE, DEACTIVATED) exists.
// It is needed for the CLI's 'createoffer' output, which has a boolean 'ENABLED'
// column that will show a PENDING value when this.isMyPendingOffer = true.
return getOfferInfoBuilder(myNewOffer, true)
return getBuilder(myNewOffer, true)
.withIsMyPendingOffer(true)
.build();
}
public static OfferInfo toOfferInfo(OpenOffer openOffer) {
public static OfferInfo toMyOfferInfo(OpenOffer openOffer) {
// An OpenOffer is always my offer.
return getOfferInfoBuilder(openOffer.getOffer(), true)
return getBuilder(openOffer.getOffer(), true)
.withTriggerPrice(openOffer.getTriggerPrice())
.withIsActivated(!openOffer.isDeactivated())
.build();
}
private static OfferInfoBuilder getOfferInfoBuilder(Offer offer, boolean isMyOffer) {
return new OfferInfoBuilder()
private static Builder getBuilder(Offer offer, boolean isMyOffer) {
return new Builder()
.withId(offer.getId())
.withDirection(offer.getDirection().name())
.withPrice(Objects.requireNonNull(offer.getPrice()).getValue())
@ -135,7 +147,7 @@ public class OfferInfo implements Payload {
.withMinAmount(offer.getMinAmount().value)
.withVolume(Objects.requireNonNull(offer.getVolume()).getValue())
.withMinVolume(Objects.requireNonNull(offer.getMinVolume()).getValue())
.withMakerFee(offer.getMakerFee().value)
.withMakerFee(getMakerFee(offer, isMyOffer))
.withTxFee(offer.getTxFee().value)
.withOfferFeePaymentTxId(offer.getOfferFeePaymentTxId())
.withBuyerSecurityDeposit(offer.getBuyerSecurityDeposit().value)
@ -148,7 +160,18 @@ public class OfferInfo implements Payload {
.withCounterCurrencyCode(offer.getCounterCurrencyCode())
.withDate(offer.getDate().getTime())
.withState(offer.getState().name())
.withIsMyOffer(isMyOffer);
.withIsMyOffer(isMyOffer)
.withIsBsqSwapOffer(offer.isBsqSwapOffer())
.withOwnerNodeAddress(offer.getOfferPayloadBase().getOwnerNodeAddress().getFullAddress())
.withPubKeyRing(offer.getOfferPayloadBase().getPubKeyRing().toString())
.withVersionNumber(offer.getOfferPayloadBase().getVersionNr())
.withProtocolVersion(offer.getOfferPayloadBase().getProtocolVersion());
}
private static long getMakerFee(Offer offer, boolean isMyOffer) {
return isMyOffer
? requireNonNull(CoinUtil.getMakerFee(false, offer.getAmount())).value
: 0;
}
///////////////////////////////////////////////////////////////////////////////////////////
@ -169,7 +192,7 @@ public class OfferInfo implements Payload {
.setMinVolume(minVolume)
.setMakerFee(makerFee)
.setTxFee(txFee)
.setOfferFeePaymentTxId(offerFeePaymentTxId)
.setOfferFeePaymentTxId(isBsqSwapOffer ? "" : offerFeePaymentTxId)
.setBuyerSecurityDeposit(buyerSecurityDeposit)
.setSellerSecurityDeposit(sellerSecurityDeposit)
.setTriggerPrice(triggerPrice)
@ -184,12 +207,17 @@ public class OfferInfo implements Payload {
.setIsActivated(isActivated)
.setIsMyOffer(isMyOffer)
.setIsMyPendingOffer(isMyPendingOffer)
.setIsBsqSwapOffer(isBsqSwapOffer)
.setOwnerNodeAddress(ownerNodeAddress)
.setPubKeyRing(pubKeyRing)
.setVersionNr(versionNumber)
.setProtocolVersion(protocolVersion)
.build();
}
@SuppressWarnings("unused")
public static OfferInfo fromProto(bisq.proto.grpc.OfferInfo proto) {
return new OfferInfoBuilder()
return new Builder()
.withId(proto.getId())
.withDirection(proto.getDirection())
.withPrice(proto.getPrice())
@ -216,16 +244,21 @@ public class OfferInfo implements Payload {
.withIsActivated(proto.getIsActivated())
.withIsMyOffer(proto.getIsMyOffer())
.withIsMyPendingOffer(proto.getIsMyPendingOffer())
.withIsBsqSwapOffer(proto.getIsBsqSwapOffer())
.withOwnerNodeAddress(proto.getOwnerNodeAddress())
.withPubKeyRing(proto.getPubKeyRing())
.withVersionNumber(proto.getVersionNr())
.withProtocolVersion(proto.getProtocolVersion())
.build();
}
/*
* OfferInfoBuilder helps avoid bungling use of a large OfferInfo constructor
* Builder helps avoid bungling use of a large OfferInfo constructor
* argument list. If consecutive argument values of the same type are not
* ordered correctly, the compiler won't complain but the resulting bugs could
* be hard to find and fix.
*/
public static class OfferInfoBuilder {
private static class Builder {
private String id;
private String direction;
private long price;
@ -252,137 +285,167 @@ public class OfferInfo implements Payload {
private boolean isActivated;
private boolean isMyOffer;
private boolean isMyPendingOffer;
private boolean isBsqSwapOffer;
private String ownerNodeAddress;
private String pubKeyRing;
private String versionNumber;
private int protocolVersion;
public OfferInfoBuilder withId(String id) {
public Builder withId(String id) {
this.id = id;
return this;
}
public OfferInfoBuilder withDirection(String direction) {
public Builder withDirection(String direction) {
this.direction = direction;
return this;
}
public OfferInfoBuilder withPrice(long price) {
public Builder withPrice(long price) {
this.price = price;
return this;
}
public OfferInfoBuilder withUseMarketBasedPrice(boolean useMarketBasedPrice) {
public Builder withUseMarketBasedPrice(boolean useMarketBasedPrice) {
this.useMarketBasedPrice = useMarketBasedPrice;
return this;
}
public OfferInfoBuilder withMarketPriceMargin(double useMarketBasedPrice) {
public Builder withMarketPriceMargin(double useMarketBasedPrice) {
this.marketPriceMargin = useMarketBasedPrice;
return this;
}
public OfferInfoBuilder withAmount(long amount) {
public Builder withAmount(long amount) {
this.amount = amount;
return this;
}
public OfferInfoBuilder withMinAmount(long minAmount) {
public Builder withMinAmount(long minAmount) {
this.minAmount = minAmount;
return this;
}
public OfferInfoBuilder withVolume(long volume) {
public Builder withVolume(long volume) {
this.volume = volume;
return this;
}
public OfferInfoBuilder withMinVolume(long minVolume) {
public Builder withMinVolume(long minVolume) {
this.minVolume = minVolume;
return this;
}
public OfferInfoBuilder withTxFee(long txFee) {
public Builder withTxFee(long txFee) {
this.txFee = txFee;
return this;
}
public OfferInfoBuilder withMakerFee(long makerFee) {
public Builder withMakerFee(long makerFee) {
this.makerFee = makerFee;
return this;
}
public OfferInfoBuilder withOfferFeePaymentTxId(String offerFeePaymentTxId) {
public Builder withOfferFeePaymentTxId(String offerFeePaymentTxId) {
this.offerFeePaymentTxId = offerFeePaymentTxId;
return this;
}
public OfferInfoBuilder withBuyerSecurityDeposit(long buyerSecurityDeposit) {
public Builder withBuyerSecurityDeposit(long buyerSecurityDeposit) {
this.buyerSecurityDeposit = buyerSecurityDeposit;
return this;
}
public OfferInfoBuilder withSellerSecurityDeposit(long sellerSecurityDeposit) {
public Builder withSellerSecurityDeposit(long sellerSecurityDeposit) {
this.sellerSecurityDeposit = sellerSecurityDeposit;
return this;
}
public OfferInfoBuilder withTriggerPrice(long triggerPrice) {
public Builder withTriggerPrice(long triggerPrice) {
this.triggerPrice = triggerPrice;
return this;
}
public OfferInfoBuilder withIsCurrencyForMakerFeeBtc(boolean isCurrencyForMakerFeeBtc) {
public Builder withIsCurrencyForMakerFeeBtc(boolean isCurrencyForMakerFeeBtc) {
this.isCurrencyForMakerFeeBtc = isCurrencyForMakerFeeBtc;
return this;
}
public OfferInfoBuilder withPaymentAccountId(String paymentAccountId) {
public Builder withPaymentAccountId(String paymentAccountId) {
this.paymentAccountId = paymentAccountId;
return this;
}
public OfferInfoBuilder withPaymentMethodId(String paymentMethodId) {
public Builder withPaymentMethodId(String paymentMethodId) {
this.paymentMethodId = paymentMethodId;
return this;
}
public OfferInfoBuilder withPaymentMethodShortName(String paymentMethodShortName) {
public Builder withPaymentMethodShortName(String paymentMethodShortName) {
this.paymentMethodShortName = paymentMethodShortName;
return this;
}
public OfferInfoBuilder withBaseCurrencyCode(String baseCurrencyCode) {
public Builder withBaseCurrencyCode(String baseCurrencyCode) {
this.baseCurrencyCode = baseCurrencyCode;
return this;
}
public OfferInfoBuilder withCounterCurrencyCode(String counterCurrencyCode) {
public Builder withCounterCurrencyCode(String counterCurrencyCode) {
this.counterCurrencyCode = counterCurrencyCode;
return this;
}
public OfferInfoBuilder withDate(long date) {
public Builder withDate(long date) {
this.date = date;
return this;
}
public OfferInfoBuilder withState(String state) {
public Builder withState(String state) {
this.state = state;
return this;
}
public OfferInfoBuilder withIsActivated(boolean isActivated) {
public Builder withIsActivated(boolean isActivated) {
this.isActivated = isActivated;
return this;
}
public OfferInfoBuilder withIsMyOffer(boolean isMyOffer) {
public Builder withIsMyOffer(boolean isMyOffer) {
this.isMyOffer = isMyOffer;
return this;
}
public OfferInfoBuilder withIsMyPendingOffer(boolean isMyPendingOffer) {
public Builder withIsMyPendingOffer(boolean isMyPendingOffer) {
this.isMyPendingOffer = isMyPendingOffer;
return this;
}
public Builder withIsBsqSwapOffer(boolean isBsqSwapOffer) {
this.isBsqSwapOffer = isBsqSwapOffer;
return this;
}
public Builder withOwnerNodeAddress(String ownerNodeAddress) {
this.ownerNodeAddress = ownerNodeAddress;
return this;
}
public Builder withPubKeyRing(String pubKeyRing) {
this.pubKeyRing = pubKeyRing;
return this;
}
public Builder withVersionNumber(String versionNumber) {
this.versionNumber = versionNumber;
return this;
}
public Builder withProtocolVersion(int protocolVersion) {
this.protocolVersion = protocolVersion;
return this;
}
public OfferInfo build() {
return new OfferInfo(this);
}

View file

@ -27,6 +27,7 @@ import java.util.Objects;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import static bisq.core.api.model.OfferInfo.toMyOfferInfo;
import static bisq.core.api.model.OfferInfo.toOfferInfo;
import static bisq.core.api.model.PaymentAccountPayloadInfo.toPaymentAccountPayloadInfo;
@ -65,7 +66,7 @@ public class TradeInfo implements Payload {
private final String contractAsJson;
private final ContractInfo contract;
public TradeInfo(TradeInfoBuilder builder) {
public TradeInfo(Builder builder) {
this.offer = builder.offer;
this.tradeId = builder.tradeId;
this.shortId = builder.shortId;
@ -118,9 +119,8 @@ public class TradeInfo implements Payload {
contractInfo = ContractInfo.emptyContract.get();
}
OfferInfo offerInfo = toOfferInfo(trade.getOffer());
offerInfo.setIsMyOffer(isMyOffer);
return new TradeInfoBuilder()
OfferInfo offerInfo = isMyOffer ? toMyOfferInfo(trade.getOffer()) : toOfferInfo(trade.getOffer());
return new Builder()
.withOffer(offerInfo)
.withTradeId(trade.getId())
.withShortId(trade.getShortId())
@ -189,7 +189,7 @@ public class TradeInfo implements Payload {
}
public static TradeInfo fromProto(bisq.proto.grpc.TradeInfo proto) {
return new TradeInfoBuilder()
return new Builder()
.withOffer(OfferInfo.fromProto(proto.getOffer()))
.withTradeId(proto.getTradeId())
.withShortId(proto.getShortId())
@ -220,12 +220,12 @@ public class TradeInfo implements Payload {
}
/*
* TradeInfoBuilder helps avoid bungling use of a large TradeInfo constructor
* Builder helps avoid bungling use of a large TradeInfo constructor
* argument list. If consecutive argument values of the same type are not
* ordered correctly, the compiler won't complain but the resulting bugs could
* be hard to find and fix.
*/
public static class TradeInfoBuilder {
private static class Builder {
private OfferInfo offer;
private String tradeId;
private String shortId;
@ -253,132 +253,132 @@ public class TradeInfo implements Payload {
private String contractAsJson;
private ContractInfo contract;
public TradeInfoBuilder withOffer(OfferInfo offer) {
public Builder withOffer(OfferInfo offer) {
this.offer = offer;
return this;
}
public TradeInfoBuilder withTradeId(String tradeId) {
public Builder withTradeId(String tradeId) {
this.tradeId = tradeId;
return this;
}
public TradeInfoBuilder withShortId(String shortId) {
public Builder withShortId(String shortId) {
this.shortId = shortId;
return this;
}
public TradeInfoBuilder withDate(long date) {
public Builder withDate(long date) {
this.date = date;
return this;
}
public TradeInfoBuilder withRole(String role) {
public Builder withRole(String role) {
this.role = role;
return this;
}
public TradeInfoBuilder withIsCurrencyForTakerFeeBtc(boolean isCurrencyForTakerFeeBtc) {
public Builder withIsCurrencyForTakerFeeBtc(boolean isCurrencyForTakerFeeBtc) {
this.isCurrencyForTakerFeeBtc = isCurrencyForTakerFeeBtc;
return this;
}
public TradeInfoBuilder withTxFeeAsLong(long txFeeAsLong) {
public Builder withTxFeeAsLong(long txFeeAsLong) {
this.txFeeAsLong = txFeeAsLong;
return this;
}
public TradeInfoBuilder withTakerFeeAsLong(long takerFeeAsLong) {
public Builder withTakerFeeAsLong(long takerFeeAsLong) {
this.takerFeeAsLong = takerFeeAsLong;
return this;
}
public TradeInfoBuilder withTakerFeeTxId(String takerFeeTxId) {
public Builder withTakerFeeTxId(String takerFeeTxId) {
this.takerFeeTxId = takerFeeTxId;
return this;
}
public TradeInfoBuilder withDepositTxId(String depositTxId) {
public Builder withDepositTxId(String depositTxId) {
this.depositTxId = depositTxId;
return this;
}
public TradeInfoBuilder withPayoutTxId(String payoutTxId) {
public Builder withPayoutTxId(String payoutTxId) {
this.payoutTxId = payoutTxId;
return this;
}
public TradeInfoBuilder withTradeAmountAsLong(long tradeAmountAsLong) {
public Builder withTradeAmountAsLong(long tradeAmountAsLong) {
this.tradeAmountAsLong = tradeAmountAsLong;
return this;
}
public TradeInfoBuilder withTradePrice(long tradePrice) {
public Builder withTradePrice(long tradePrice) {
this.tradePrice = tradePrice;
return this;
}
public TradeInfoBuilder withTradeVolume(long tradeVolume) {
public Builder withTradeVolume(long tradeVolume) {
this.tradeVolume = tradeVolume;
return this;
}
public TradeInfoBuilder withTradePeriodState(String tradePeriodState) {
public Builder withTradePeriodState(String tradePeriodState) {
this.tradePeriodState = tradePeriodState;
return this;
}
public TradeInfoBuilder withState(String state) {
public Builder withState(String state) {
this.state = state;
return this;
}
public TradeInfoBuilder withPhase(String phase) {
public Builder withPhase(String phase) {
this.phase = phase;
return this;
}
public TradeInfoBuilder withTradingPeerNodeAddress(String tradingPeerNodeAddress) {
public Builder withTradingPeerNodeAddress(String tradingPeerNodeAddress) {
this.tradingPeerNodeAddress = tradingPeerNodeAddress;
return this;
}
public TradeInfoBuilder withIsDepositPublished(boolean isDepositPublished) {
public Builder withIsDepositPublished(boolean isDepositPublished) {
this.isDepositPublished = isDepositPublished;
return this;
}
public TradeInfoBuilder withIsDepositConfirmed(boolean isDepositConfirmed) {
public Builder withIsDepositConfirmed(boolean isDepositConfirmed) {
this.isDepositConfirmed = isDepositConfirmed;
return this;
}
public TradeInfoBuilder withIsFiatSent(boolean isFiatSent) {
public Builder withIsFiatSent(boolean isFiatSent) {
this.isFiatSent = isFiatSent;
return this;
}
public TradeInfoBuilder withIsFiatReceived(boolean isFiatReceived) {
public Builder withIsFiatReceived(boolean isFiatReceived) {
this.isFiatReceived = isFiatReceived;
return this;
}
public TradeInfoBuilder withIsPayoutPublished(boolean isPayoutPublished) {
public Builder withIsPayoutPublished(boolean isPayoutPublished) {
this.isPayoutPublished = isPayoutPublished;
return this;
}
public TradeInfoBuilder withIsWithdrawn(boolean isWithdrawn) {
public Builder withIsWithdrawn(boolean isWithdrawn) {
this.isWithdrawn = isWithdrawn;
return this;
}
public TradeInfoBuilder withContractAsJson(String contractAsJson) {
public Builder withContractAsJson(String contractAsJson) {
this.contractAsJson = contractAsJson;
return this;
}
public TradeInfoBuilder withContract(ContractInfo contract) {
public Builder withContract(ContractInfo contract) {
this.contract = contract;
return this;
}

View file

@ -46,7 +46,7 @@ public class TxInfo implements Payload {
private final boolean isPending;
private final String memo;
public TxInfo(TxInfoBuilder builder) {
public TxInfo(Builder builder) {
this.txId = builder.txId;
this.inputSum = builder.inputSum;
this.outputSum = builder.outputSum;
@ -61,7 +61,7 @@ public class TxInfo implements Payload {
throw new IllegalStateException("server created a null transaction");
if (transaction.getFee() != null)
return new TxInfoBuilder()
return new Builder()
.withTxId(transaction.getTxId().toString())
.withInputSum(transaction.getInputSum().value)
.withOutputSum(transaction.getOutputSum().value)
@ -71,7 +71,7 @@ public class TxInfo implements Payload {
.withMemo(transaction.getMemo())
.build();
else
return new TxInfoBuilder()
return new Builder()
.withTxId(transaction.getTxId().toString())
.withInputSum(transaction.getInputSum().value)
.withOutputSum(transaction.getOutputSum().value)
@ -101,7 +101,7 @@ public class TxInfo implements Payload {
@SuppressWarnings("unused")
public static TxInfo fromProto(bisq.proto.grpc.TxInfo proto) {
return new TxInfoBuilder()
return new Builder()
.withTxId(proto.getTxId())
.withInputSum(proto.getInputSum())
.withOutputSum(proto.getOutputSum())
@ -112,7 +112,7 @@ public class TxInfo implements Payload {
.build();
}
public static class TxInfoBuilder {
private static class Builder {
private String txId;
private long inputSum;
private long outputSum;
@ -121,37 +121,37 @@ public class TxInfo implements Payload {
private boolean isPending;
private String memo;
public TxInfoBuilder withTxId(String txId) {
public Builder withTxId(String txId) {
this.txId = txId;
return this;
}
public TxInfoBuilder withInputSum(long inputSum) {
public Builder withInputSum(long inputSum) {
this.inputSum = inputSum;
return this;
}
public TxInfoBuilder withOutputSum(long outputSum) {
public Builder withOutputSum(long outputSum) {
this.outputSum = outputSum;
return this;
}
public TxInfoBuilder withFee(long fee) {
public Builder withFee(long fee) {
this.fee = fee;
return this;
}
public TxInfoBuilder withSize(int size) {
public Builder withSize(int size) {
this.size = size;
return this;
}
public TxInfoBuilder withIsPending(boolean isPending) {
public Builder withIsPending(boolean isPending) {
this.isPending = isPending;
return this;
}
public TxInfoBuilder withMemo(String memo) {
public Builder withMemo(String memo) {
this.memo = memo;
return this;
}