mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 15:10:44 +01:00
Adjust .proto wrappers to price & volume type change
Some minor refactoring included.
This commit is contained in:
parent
3b22aeeb98
commit
a0b68bc756
3 changed files with 42 additions and 22 deletions
|
@ -39,7 +39,7 @@ public class CanceledTradeInfo {
|
|||
Offer offer = myCanceledOpenOffer.getOffer();
|
||||
OfferInfo offerInfo = toMyOfferInfo(offer);
|
||||
|
||||
return new TradeInfoV1Builder() // TODO May need to use BsqSwapTradeInfoBuilder?
|
||||
return new TradeInfoV1Builder()
|
||||
.withOffer(offerInfo)
|
||||
.withTradeId(myCanceledOpenOffer.getId())
|
||||
.withShortId(myCanceledOpenOffer.getShortId())
|
||||
|
@ -52,8 +52,8 @@ public class CanceledTradeInfo {
|
|||
.withDepositTxId("") // Ignored
|
||||
.withPayoutTxId("") // Ignored
|
||||
.withTradeAmountAsLong(0) // Ignored
|
||||
.withTradePrice(offer.getPrice().getValue())
|
||||
.withTradeVolume(0) // Ignored
|
||||
.withTradePrice(offerInfo.getPrice())
|
||||
.withTradeVolume("") // Ignored
|
||||
.withTradingPeerNodeAddress("") // Ignored
|
||||
.withState("") // Ignored
|
||||
.withPhase("") // Ignored
|
||||
|
|
|
@ -25,6 +25,9 @@ import bisq.core.trade.model.bsq_swap.BsqSwapTrade;
|
|||
|
||||
import bisq.common.Payload;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
|
||||
|
@ -34,6 +37,8 @@ import static bisq.core.api.model.OfferInfo.toOfferInfo;
|
|||
import static bisq.core.api.model.PaymentAccountPayloadInfo.toPaymentAccountPayloadInfo;
|
||||
import static bisq.core.offer.OfferDirection.BUY;
|
||||
import static bisq.core.offer.OfferDirection.SELL;
|
||||
import static bisq.core.util.PriceUtil.reformatMarketPrice;
|
||||
import static bisq.core.util.VolumeUtil.formatVolume;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
@EqualsAndHashCode
|
||||
|
@ -44,6 +49,23 @@ public class TradeInfo implements Payload {
|
|||
// lighter weight TradeInfo proto wrapper instead, containing just enough fields to
|
||||
// view and interact with trades.
|
||||
|
||||
private static final BiFunction<TradeModel, Boolean, OfferInfo> toOfferInfo = (tradeModel, isMyOffer) ->
|
||||
isMyOffer ? toMyOfferInfo(tradeModel.getOffer()) : toOfferInfo(tradeModel.getOffer());
|
||||
|
||||
private static final Function<TradeModel, String> toPeerNodeAddress = (tradeModel) ->
|
||||
tradeModel.getTradingPeerNodeAddress() == null
|
||||
? ""
|
||||
: tradeModel.getTradingPeerNodeAddress().getFullAddress();
|
||||
|
||||
private static final Function<TradeModel, String> toRoundedVolume = (tradeModel) ->
|
||||
tradeModel.getVolume() == null
|
||||
? ""
|
||||
: formatVolume(requireNonNull(tradeModel.getVolume()));
|
||||
|
||||
private static final Function<TradeModel, String> toPreciseTradePrice = (tradeModel) ->
|
||||
reformatMarketPrice(requireNonNull(tradeModel.getPrice()).toPlainString(),
|
||||
tradeModel.getOffer().getCurrencyCode());
|
||||
|
||||
// Bisq v1 trade protocol fields (some are in common with the BSQ Swap protocol).
|
||||
private final OfferInfo offer;
|
||||
private final String tradeId;
|
||||
|
@ -57,8 +79,8 @@ public class TradeInfo implements Payload {
|
|||
private final String depositTxId;
|
||||
private final String payoutTxId;
|
||||
private final long tradeAmountAsLong;
|
||||
private final long tradePrice;
|
||||
private final long tradeVolume;
|
||||
private final String tradePrice;
|
||||
private final String tradeVolume;
|
||||
private final String tradingPeerNodeAddress;
|
||||
private final String state;
|
||||
private final String phase;
|
||||
|
@ -133,14 +155,12 @@ public class TradeInfo implements Payload {
|
|||
boolean isMyOffer,
|
||||
int numConfirmations,
|
||||
String closingStatus) {
|
||||
OfferInfo offerInfo = isMyOffer ? toMyOfferInfo(bsqSwapTrade.getOffer()) : toOfferInfo(bsqSwapTrade.getOffer());
|
||||
var offerInfo = toOfferInfo.apply(bsqSwapTrade, isMyOffer);
|
||||
// A BSQ Swap miner tx fee is paid in full by the BTC seller (buying BSQ).
|
||||
// The BTC buyer's payout = tradeamount minus his share of miner fee.
|
||||
var isBtcSeller = (isMyOffer && bsqSwapTrade.getOffer().getDirection().equals(SELL))
|
||||
|| (!isMyOffer && bsqSwapTrade.getOffer().getDirection().equals(BUY));
|
||||
var txFeeInBtc = isBtcSeller
|
||||
? bsqSwapTrade.getTxFee().value
|
||||
: 0L;
|
||||
var txFeeInBtc = isBtcSeller ? bsqSwapTrade.getTxFee().value : 0L;
|
||||
// A BSQ Swap trade fee is paid in full by the BTC buyer (selling BSQ).
|
||||
// The transferred BSQ (payout) is reduced by the peer's trade fee.
|
||||
var takerFeeInBsq = !isMyOffer && bsqSwapTrade.getOffer().getDirection().equals(SELL)
|
||||
|
@ -157,9 +177,9 @@ public class TradeInfo implements Payload {
|
|||
.withTakerFeeAsLong(takerFeeInBsq)
|
||||
// N/A for bsq-swaps: .withTakerFeeTxId(""), .withDepositTxId(""), .withPayoutTxId("")
|
||||
.withTradeAmountAsLong(bsqSwapTrade.getAmountAsLong())
|
||||
.withTradePrice(bsqSwapTrade.getPrice().getValue())
|
||||
.withTradeVolume(bsqSwapTrade.getVolume() == null ? 0 : bsqSwapTrade.getVolume().getValue())
|
||||
.withTradingPeerNodeAddress(requireNonNull(bsqSwapTrade.getTradingPeerNodeAddress().getFullAddress()))
|
||||
.withTradePrice(toPreciseTradePrice.apply(bsqSwapTrade))
|
||||
.withTradeVolume(toRoundedVolume.apply(bsqSwapTrade))
|
||||
.withTradingPeerNodeAddress(toPeerNodeAddress.apply(bsqSwapTrade))
|
||||
.withState(bsqSwapTrade.getTradeState().name())
|
||||
.withPhase(bsqSwapTrade.getTradePhase().name())
|
||||
// N/A for bsq-swaps: .withTradePeriodState(""), .withIsDepositPublished(false), .withIsDepositConfirmed(false)
|
||||
|
@ -194,7 +214,7 @@ public class TradeInfo implements Payload {
|
|||
contractInfo = ContractInfo.emptyContract.get();
|
||||
}
|
||||
|
||||
OfferInfo offerInfo = isMyOffer ? toMyOfferInfo(trade.getOffer()) : toOfferInfo(trade.getOffer());
|
||||
var offerInfo = toOfferInfo.apply(trade, isMyOffer);
|
||||
return new TradeInfoV1Builder()
|
||||
.withOffer(offerInfo)
|
||||
.withTradeId(trade.getId())
|
||||
|
@ -208,9 +228,9 @@ public class TradeInfo implements Payload {
|
|||
.withDepositTxId(trade.getDepositTxId())
|
||||
.withPayoutTxId(trade.getPayoutTxId())
|
||||
.withTradeAmountAsLong(trade.getAmountAsLong())
|
||||
.withTradePrice(trade.getPrice().getValue())
|
||||
.withTradeVolume(trade.getVolume() == null ? 0 : trade.getVolume().getValue())
|
||||
.withTradingPeerNodeAddress(requireNonNull(trade.getTradingPeerNodeAddress().getFullAddress()))
|
||||
.withTradePrice(toPreciseTradePrice.apply(trade))
|
||||
.withTradeVolume(toRoundedVolume.apply(trade))
|
||||
.withTradingPeerNodeAddress(toPeerNodeAddress.apply(trade))
|
||||
.withState(trade.getTradeState().name())
|
||||
.withPhase(trade.getTradePhase().name())
|
||||
.withTradePeriodState(trade.getTradePeriodState().name())
|
||||
|
@ -246,8 +266,8 @@ public class TradeInfo implements Payload {
|
|||
.setDepositTxId(depositTxId == null ? "" : depositTxId)
|
||||
.setPayoutTxId(payoutTxId == null ? "" : payoutTxId)
|
||||
.setTradeAmountAsLong(tradeAmountAsLong)
|
||||
.setTradePrice(tradePrice)
|
||||
.setTradeVolume(tradeVolume)
|
||||
.setTradePrice(tradePrice == null ? "" : tradePrice)
|
||||
.setTradeVolume(tradeVolume == null ? "" : tradeVolume)
|
||||
.setTradingPeerNodeAddress(tradingPeerNodeAddress)
|
||||
.setState(state == null ? "" : state)
|
||||
.setPhase(phase == null ? "" : phase)
|
||||
|
|
|
@ -44,8 +44,8 @@ public final class TradeInfoV1Builder {
|
|||
private String depositTxId;
|
||||
private String payoutTxId;
|
||||
private long tradeAmountAsLong;
|
||||
private long tradePrice;
|
||||
private long tradeVolume;
|
||||
private String tradePrice;
|
||||
private String tradeVolume;
|
||||
private String tradingPeerNodeAddress;
|
||||
private String state;
|
||||
private String phase;
|
||||
|
@ -120,12 +120,12 @@ public final class TradeInfoV1Builder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public TradeInfoV1Builder withTradePrice(long tradePrice) {
|
||||
public TradeInfoV1Builder withTradePrice(String tradePrice) {
|
||||
this.tradePrice = tradePrice;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TradeInfoV1Builder withTradeVolume(long tradeVolume) {
|
||||
public TradeInfoV1Builder withTradeVolume(String tradeVolume) {
|
||||
this.tradeVolume = tradeVolume;
|
||||
return this;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue