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

View file

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

View file

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

View file

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