mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 07:07:43 +01:00
Adjust createoffer opt parser for bsq swaps
This commit is contained in:
parent
b1c872c515
commit
35aeb61338
4 changed files with 40 additions and 13 deletions
|
@ -39,7 +39,7 @@ abstract class AbstractMethodOptionParser implements MethodOpts {
|
|||
|
||||
protected final OptionParser parser = new OptionParser();
|
||||
|
||||
// The help option for a specific api method, e.g., takeoffer -help.
|
||||
// The help option for a specific api method, e.g., takeoffer --help.
|
||||
protected final OptionSpec<Void> helpOpt = parser.accepts(OPT_HELP, "Print method help").forHelp();
|
||||
|
||||
@Getter
|
||||
|
|
|
@ -24,6 +24,7 @@ import static bisq.cli.opts.OptLabel.OPT_ACCOUNT_NAME;
|
|||
import static bisq.cli.opts.OptLabel.OPT_ADDRESS;
|
||||
import static bisq.cli.opts.OptLabel.OPT_CURRENCY_CODE;
|
||||
import static bisq.cli.opts.OptLabel.OPT_TRADE_INSTANT;
|
||||
import static java.lang.Boolean.FALSE;
|
||||
|
||||
public class CreateCryptoCurrencyPaymentAcctOptionParser extends AbstractMethodOptionParser implements MethodOpts {
|
||||
|
||||
|
@ -39,7 +40,7 @@ public class CreateCryptoCurrencyPaymentAcctOptionParser extends AbstractMethodO
|
|||
final OptionSpec<Boolean> tradeInstantOpt = parser.accepts(OPT_TRADE_INSTANT, "create trade instant account")
|
||||
.withOptionalArg()
|
||||
.ofType(boolean.class)
|
||||
.defaultsTo(Boolean.FALSE);
|
||||
.defaultsTo(FALSE);
|
||||
|
||||
public CreateCryptoCurrencyPaymentAcctOptionParser(String[] args) {
|
||||
super(args);
|
||||
|
|
|
@ -23,6 +23,7 @@ import joptsimple.OptionSpec;
|
|||
import java.math.BigDecimal;
|
||||
|
||||
import static bisq.cli.opts.OptLabel.*;
|
||||
import static java.lang.Boolean.FALSE;
|
||||
import static joptsimple.internal.Strings.EMPTY;
|
||||
|
||||
public class CreateOfferOptionParser extends AbstractMethodOptionParser implements MethodOpts {
|
||||
|
@ -59,6 +60,11 @@ public class CreateOfferOptionParser extends AbstractMethodOptionParser implemen
|
|||
.withOptionalArg()
|
||||
.defaultsTo("btc");
|
||||
|
||||
final OptionSpec<Boolean> isSwapOpt = parser.accepts(OPT_SWAP, "create bsq swap offer")
|
||||
.withOptionalArg()
|
||||
.ofType(boolean.class)
|
||||
.defaultsTo(FALSE);
|
||||
|
||||
public CreateOfferOptionParser(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
|
@ -70,9 +76,6 @@ public class CreateOfferOptionParser extends AbstractMethodOptionParser implemen
|
|||
if (options.has(helpOpt))
|
||||
return this;
|
||||
|
||||
if (!options.has(paymentAccountIdOpt) || options.valueOf(paymentAccountIdOpt).isEmpty())
|
||||
throw new IllegalArgumentException("no payment account id specified");
|
||||
|
||||
if (!options.has(directionOpt) || options.valueOf(directionOpt).isEmpty())
|
||||
throw new IllegalArgumentException("no direction (buy|sell) specified");
|
||||
|
||||
|
@ -82,17 +85,35 @@ public class CreateOfferOptionParser extends AbstractMethodOptionParser implemen
|
|||
if (!options.has(amountOpt) || options.valueOf(amountOpt).isEmpty())
|
||||
throw new IllegalArgumentException("no btc amount specified");
|
||||
|
||||
if (!options.has(mktPriceMarginOpt) && !options.has(fixedPriceOpt))
|
||||
throw new IllegalArgumentException("no market price margin or fixed price specified");
|
||||
if (getIsSwap()) {
|
||||
if (options.has(paymentAccountIdOpt))
|
||||
throw new IllegalArgumentException("cannot use a payment account id in bsq swap offer");
|
||||
|
||||
if (options.has(mktPriceMarginOpt) && options.valueOf(mktPriceMarginOpt).isEmpty())
|
||||
throw new IllegalArgumentException("no market price margin specified");
|
||||
if (options.has(mktPriceMarginOpt))
|
||||
throw new IllegalArgumentException("cannot use a market price margin in bsq swap offer");
|
||||
|
||||
if (options.has(fixedPriceOpt) && options.valueOf(fixedPriceOpt).isEmpty())
|
||||
throw new IllegalArgumentException("no fixed price specified");
|
||||
if (options.has(securityDepositOpt))
|
||||
throw new IllegalArgumentException("cannot use a security deposit in bsq swap offer");
|
||||
|
||||
if (!options.has(securityDepositOpt) || options.valueOf(securityDepositOpt).isEmpty())
|
||||
throw new IllegalArgumentException("no security deposit specified");
|
||||
if (!options.has(fixedPriceOpt) || options.valueOf(fixedPriceOpt).isEmpty())
|
||||
throw new IllegalArgumentException("no fixed price specified");
|
||||
|
||||
} else {
|
||||
if (!options.has(paymentAccountIdOpt) || options.valueOf(paymentAccountIdOpt).isEmpty())
|
||||
throw new IllegalArgumentException("no payment account id specified");
|
||||
|
||||
if (!options.has(mktPriceMarginOpt) && !options.has(fixedPriceOpt))
|
||||
throw new IllegalArgumentException("no market price margin or fixed price specified");
|
||||
|
||||
if (options.has(mktPriceMarginOpt) && options.valueOf(mktPriceMarginOpt).isEmpty())
|
||||
throw new IllegalArgumentException("no market price margin specified");
|
||||
|
||||
if (options.has(fixedPriceOpt) && options.valueOf(fixedPriceOpt).isEmpty())
|
||||
throw new IllegalArgumentException("no fixed price specified");
|
||||
|
||||
if (!options.has(securityDepositOpt) || options.valueOf(securityDepositOpt).isEmpty())
|
||||
throw new IllegalArgumentException("no security deposit specified");
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -141,4 +162,8 @@ public class CreateOfferOptionParser extends AbstractMethodOptionParser implemen
|
|||
public String getMakerFeeCurrencyCode() {
|
||||
return options.has(makerFeeCurrencyCodeOpt) ? options.valueOf(makerFeeCurrencyCodeOpt) : "btc";
|
||||
}
|
||||
|
||||
public boolean getIsSwap() {
|
||||
return options.valueOf(isSwapOpt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ public class OptLabel {
|
|||
public final static String OPT_REGISTRATION_KEY = "registration-key";
|
||||
public final static String OPT_SECURITY_DEPOSIT = "security-deposit";
|
||||
public final static String OPT_SHOW_CONTRACT = "show-contract";
|
||||
public final static String OPT_SWAP = "swap";
|
||||
public final static String OPT_TRADE_ID = "trade-id";
|
||||
public final static String OPT_TRADE_INSTANT = "trade-instant";
|
||||
public final static String OPT_TIMEOUT = "timeout";
|
||||
|
|
Loading…
Add table
Reference in a new issue