mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 01:41:11 +01:00
Merge pull request #6357 from ghubstan/fix-bsq-buyer-trade-fee-reporting
API: Fix BSQ buyer's displayed trade fee for gettrade(s) methods
This commit is contained in:
commit
06de8a455a
@ -31,6 +31,14 @@ public class TakeBsqSwapOfferOptionParser extends OfferIdOptionParser implements
|
|||||||
.withRequiredArg()
|
.withRequiredArg()
|
||||||
.defaultsTo("0");
|
.defaultsTo("0");
|
||||||
|
|
||||||
|
final OptionSpec<String> paymentAccountIdOpt = parser.accepts(OPT_PAYMENT_ACCOUNT_ID, "not used when taking bsq swaps")
|
||||||
|
.withRequiredArg()
|
||||||
|
.defaultsTo("invalid param");
|
||||||
|
|
||||||
|
final OptionSpec<String> takerFeeCurrencyCodeOpt = parser.accepts(OPT_FEE_CURRENCY, "not used when taking bsq swaps")
|
||||||
|
.withOptionalArg()
|
||||||
|
.defaultsTo("invalid param");
|
||||||
|
|
||||||
public TakeBsqSwapOfferOptionParser(String[] args) {
|
public TakeBsqSwapOfferOptionParser(String[] args) {
|
||||||
super(args, true);
|
super(args, true);
|
||||||
}
|
}
|
||||||
@ -40,6 +48,16 @@ public class TakeBsqSwapOfferOptionParser extends OfferIdOptionParser implements
|
|||||||
|
|
||||||
// Super class will short-circuit parsing if help option is present.
|
// Super class will short-circuit parsing if help option is present.
|
||||||
|
|
||||||
|
if (options.has(paymentAccountIdOpt)) {
|
||||||
|
throw new IllegalArgumentException("the " + OPT_PAYMENT_ACCOUNT_ID
|
||||||
|
+ " param is not used for swaps; the internal default swap account is always used");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.has(takerFeeCurrencyCodeOpt)) {
|
||||||
|
throw new IllegalArgumentException("the " + OPT_FEE_CURRENCY
|
||||||
|
+ " param is not used for swaps; fees are always paid in bsq");
|
||||||
|
}
|
||||||
|
|
||||||
if (options.has(amountOpt)) {
|
if (options.has(amountOpt)) {
|
||||||
if (options.valueOf(amountOpt).isEmpty())
|
if (options.valueOf(amountOpt).isEmpty())
|
||||||
throw new IllegalArgumentException("no intended btc trade amount specified");
|
throw new IllegalArgumentException("no intended btc trade amount specified");
|
||||||
|
@ -3,7 +3,6 @@ package bisq.cli.opts;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static bisq.cli.Method.*;
|
import static bisq.cli.Method.*;
|
||||||
import static bisq.cli.Method.takeoffer;
|
|
||||||
import static bisq.cli.opts.OptLabel.*;
|
import static bisq.cli.opts.OptLabel.*;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
@ -444,4 +443,54 @@ public class OptionParsersTest {
|
|||||||
assertEquals(takerFeeCurrencyCode, parser.getTakerFeeCurrencyCode());
|
assertEquals(takerFeeCurrencyCode, parser.getTakerFeeCurrencyCode());
|
||||||
assertEquals(amount, parser.getAmount());
|
assertEquals(amount, parser.getAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTakeBsqSwapOfferWithInvalidFeeCurrencyParam() {
|
||||||
|
var offerId = "ABC-OFFER-ID";
|
||||||
|
var takerFeeCurrencyCode = "BSQ";
|
||||||
|
var amount = "0.05";
|
||||||
|
String[] args = new String[]{
|
||||||
|
PASSWORD_OPT,
|
||||||
|
takeoffer.name(),
|
||||||
|
"--" + OPT_OFFER_ID + "=" + offerId,
|
||||||
|
"--" + OPT_FEE_CURRENCY + "=" + takerFeeCurrencyCode,
|
||||||
|
"--" + OPT_AMOUNT + "=" + amount
|
||||||
|
};
|
||||||
|
Throwable exception = assertThrows(RuntimeException.class, () ->
|
||||||
|
new TakeBsqSwapOfferOptionParser(args).parse());
|
||||||
|
assertEquals("the fee-currency param is not used for swaps; fees are always paid in bsq", exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTakeBsqSwapOfferWithInvalidPaymentAccountIdParam() {
|
||||||
|
var offerId = "ABC-OFFER-ID";
|
||||||
|
var paymentAccountId = "ABC-ACCT-ID";
|
||||||
|
var amount = "0.05";
|
||||||
|
String[] args = new String[]{
|
||||||
|
PASSWORD_OPT,
|
||||||
|
takeoffer.name(),
|
||||||
|
"--" + OPT_OFFER_ID + "=" + offerId,
|
||||||
|
"--" + OPT_PAYMENT_ACCOUNT_ID + "=" + paymentAccountId,
|
||||||
|
"--" + OPT_AMOUNT + "=" + amount
|
||||||
|
};
|
||||||
|
Throwable exception = assertThrows(RuntimeException.class, () ->
|
||||||
|
new TakeBsqSwapOfferOptionParser(args).parse());
|
||||||
|
assertEquals("the payment-account-id param is not used for swaps; the internal default swap account is always used",
|
||||||
|
exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTakeBsqSwapOffer() {
|
||||||
|
var offerId = "ABC-OFFER-ID";
|
||||||
|
var amount = "0.05";
|
||||||
|
String[] args = new String[]{
|
||||||
|
PASSWORD_OPT,
|
||||||
|
takeoffer.name(),
|
||||||
|
"--" + OPT_OFFER_ID + "=" + offerId,
|
||||||
|
"--" + OPT_AMOUNT + "=" + amount
|
||||||
|
};
|
||||||
|
var parser = new TakeBsqSwapOfferOptionParser(args).parse();
|
||||||
|
assertEquals(offerId, parser.getOfferId());
|
||||||
|
assertEquals(amount, parser.getAmount());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,6 @@ import bisq.common.Payload;
|
|||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import static bisq.core.offer.OfferDirection.BUY;
|
|
||||||
import static bisq.core.offer.OfferDirection.SELL;
|
|
||||||
|
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
@Getter
|
@Getter
|
||||||
public class BsqSwapTradeInfo implements Payload {
|
public class BsqSwapTradeInfo implements Payload {
|
||||||
@ -73,20 +70,12 @@ public class BsqSwapTradeInfo implements Payload {
|
|||||||
var makerBtcAddress = wasMyOffer ? protocolModel.getBtcAddress() : swapPeer.getBtcAddress();
|
var makerBtcAddress = wasMyOffer ? protocolModel.getBtcAddress() : swapPeer.getBtcAddress();
|
||||||
var takerBsqAddress = wasMyOffer ? swapPeer.getBsqAddress() : protocolModel.getBsqAddress();
|
var takerBsqAddress = wasMyOffer ? swapPeer.getBsqAddress() : protocolModel.getBsqAddress();
|
||||||
var takerBtcAddress = wasMyOffer ? swapPeer.getBtcAddress() : protocolModel.getBtcAddress();
|
var takerBtcAddress = wasMyOffer ? swapPeer.getBtcAddress() : protocolModel.getBtcAddress();
|
||||||
// A BSQ Swap trade fee is paid in full by the BTC buyer (selling BSQ).
|
|
||||||
// The transferred BSQ (payout) is reduced by the fee of the peer.
|
|
||||||
var makerTradeFee = wasMyOffer && trade.getOffer().getDirection().equals(BUY)
|
|
||||||
? trade.getMakerFeeAsLong()
|
|
||||||
: 0L;
|
|
||||||
var takerTradeFee = !wasMyOffer && trade.getOffer().getDirection().equals(SELL)
|
|
||||||
? trade.getTakerFeeAsLong()
|
|
||||||
: 0L;
|
|
||||||
return new BsqSwapTradeInfoBuilder()
|
return new BsqSwapTradeInfoBuilder()
|
||||||
.withTxId(trade.getTxId())
|
.withTxId(trade.getTxId())
|
||||||
.withBsqTradeAmount(trade.getBsqTradeAmount())
|
.withBsqTradeAmount(trade.getBsqTradeAmount())
|
||||||
.withBtcTradeAmount(trade.getAmountAsLong())
|
.withBtcTradeAmount(trade.getAmountAsLong())
|
||||||
.withBsqMakerTradeFee(makerTradeFee)
|
.withBsqMakerTradeFee(trade.getMakerFeeAsLong())
|
||||||
.withBsqTakerTradeFee(takerTradeFee)
|
.withBsqTakerTradeFee(trade.getTakerFeeAsLong())
|
||||||
.withTxFeePerVbyte(trade.getTxFeePerVbyte())
|
.withTxFeePerVbyte(trade.getTxFeePerVbyte())
|
||||||
.withMakerBsqAddress(makerBsqAddress)
|
.withMakerBsqAddress(makerBsqAddress)
|
||||||
.withMakerBtcAddress(makerBtcAddress)
|
.withMakerBtcAddress(makerBtcAddress)
|
||||||
|
@ -6,21 +6,28 @@ takeoffer - take an offer to buy or sell BTC
|
|||||||
|
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
takeoffer
|
takeoffer (Bisq v1 Protocol)
|
||||||
--offer-id=<offer-id>
|
--offer-id=<offer-id>
|
||||||
--payment-account=<payment-acct-id>
|
--payment-account=<payment-acct-id>
|
||||||
[--fee-currency=<btc|bsq>]
|
[--fee-currency=<btc|bsq>]
|
||||||
[--amount=<offer.min-btc-amount >= amount <= offer.btc-amount>]
|
[--amount=<offer.min-btc-amount >= amount <= offer.btc-amount>]
|
||||||
|
|
||||||
|
takeoffer (BSQ Swap)
|
||||||
|
--offer-id=<offer-id>
|
||||||
|
[--amount=<offer.min-btc-amount >= amount <= offer.btc-amount>]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
Take an existing offer. There are currently two types offers and trade protocols.
|
Take an existing offer. There are currently two types offers and trade protocols.
|
||||||
|
|
||||||
BSQ swap offers
|
BSQ swap offers
|
||||||
|
|
||||||
The takeoffer command only requires an offer-id parameter, and sufficient BSQ and BTC
|
The takeoffer command only requires an offer-id parameter, and sufficient BSQ and/or BTC
|
||||||
to cover the trade amount and the taker fee. The amount parameter is optional.
|
to cover the trade amount and the taker fee.
|
||||||
The trade (swap) will be executed immediately after being successfully taken.
|
The amount parameter is optional.
|
||||||
|
The payment-account parameter is invalid; BSQ Swap transactions use the default BsqSwapAccount.
|
||||||
|
The fee-currency parameter is invalid; BSQ is always used to pay BSQ swap trade fees.
|
||||||
|
The swap will be executed immediately after being successfully taken.
|
||||||
|
|
||||||
Version 1 protocol fiat and BSQ offers
|
Version 1 protocol fiat and BSQ offers
|
||||||
|
|
||||||
@ -33,11 +40,15 @@ OPTIONS
|
|||||||
The ID of the buy or sell offer to take.
|
The ID of the buy or sell offer to take.
|
||||||
|
|
||||||
--payment-account
|
--payment-account
|
||||||
The ID of the fiat payment account used to send or receive funds during the trade.
|
The ID of the fiat payment account used to send or receive funds during the Bisq v1 protocol trade.
|
||||||
The payment account's payment method must match that of the offer.
|
The payment account's payment method must match that of the offer.
|
||||||
|
This parameter is not valid for taking BSQ Swaps, due to swaps' different transaction structure,
|
||||||
|
where the default BsqSwapAccount is used.
|
||||||
|
|
||||||
--fee-currency
|
--fee-currency
|
||||||
The wallet currency used to pay the Bisq trade taker fee (BSQ|BTC). Default is BTC
|
The wallet currency used to pay a Bisq v1 protocol trade's taker fee (BSQ|BTC). Default is BTC.
|
||||||
|
This parameter is not valid for taking BSQ Swaps, due to swaps' different transaction structure,
|
||||||
|
where BSQ is always used to BSQ swap trade fees.
|
||||||
|
|
||||||
--amount
|
--amount
|
||||||
The trade's intended btc amount. The amount must be within the offer's min-amount and (max) amount range.
|
The trade's intended btc amount. The amount must be within the offer's min-amount and (max) amount range.
|
||||||
@ -56,5 +67,5 @@ To take an offer with ID 83e8b2e2-51b6-4f39-a748-3ebd29c22aea
|
|||||||
and setting the trade amount = the offer's min-amount (0.025 BTC):
|
and setting the trade amount = the offer's min-amount (0.025 BTC):
|
||||||
$ ./bisq-cli --password=xyz --port=9998 takeoffer --offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea \
|
$ ./bisq-cli --password=xyz --port=9998 takeoffer --offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea \
|
||||||
--payment-account=fe20cdbd-22be-4b8a-a4b6-d2608ff09d6e \
|
--payment-account=fe20cdbd-22be-4b8a-a4b6-d2608ff09d6e \
|
||||||
-fee-currency=bsq \
|
--fee-currency=bsq \
|
||||||
--amount=0.025
|
--amount=0.025
|
||||||
|
@ -514,8 +514,14 @@ service Trades {
|
|||||||
|
|
||||||
message TakeOfferRequest {
|
message TakeOfferRequest {
|
||||||
string offer_id = 1; // The unique identifier of the offer being taken.
|
string offer_id = 1; // The unique identifier of the offer being taken.
|
||||||
string payment_account_id = 2; // The unique identifier of the payment account used to take offer.
|
// The unique identifier of the payment account used to take a Bisq v1 protocol offer.
|
||||||
string taker_fee_currency_code = 3; // The code of the currency (BSQ or BTC) used to pay the taker's Bisq trade fee.
|
// This payment_account_id request param is not used when taking a BSQ Swap offer;
|
||||||
|
// all BSQ Swap transactions use the daemon's default BsqSwapAccount.
|
||||||
|
string payment_account_id = 2;
|
||||||
|
// The code of the currency (BSQ or BTC) used to pay the taker's Bisq v1 protocol trade fee.
|
||||||
|
// This taker_fee_currency_code request param is not used when taking a BSQ Swap offer;
|
||||||
|
// all BSQ Swap trade fees are paid in BSQ.
|
||||||
|
string taker_fee_currency_code = 3;
|
||||||
// The trade's intended BTC amount in satoshis. Ten million satoshis is represented as 10000000.
|
// The trade's intended BTC amount in satoshis. Ten million satoshis is represented as 10000000.
|
||||||
// If set, the takeoffer amount value must be >= offer.min_amount and <= offer.amount.
|
// If set, the takeoffer amount value must be >= offer.min_amount and <= offer.amount.
|
||||||
// If not set (0 default), the taken offer's (max) amount becomes the intended trade amount.
|
// If not set (0 default), the taken offer's (max) amount becomes the intended trade amount.
|
||||||
|
Loading…
Reference in New Issue
Block a user