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