Fix opt validation bugs in CLI

Unset empty string default values on some the createoffer method's
required option declarations in CreateOfferOptionParser, and adds a
check for presence of required currency-code option.

- Removes default "" value from required opt direction.
- Removes default "" value from required opt currency-code.
- Removes default "" value from required opt amount.
- Removes default "" value from required opt min-amount.
- Removes default "" value from required opt fixed-price.
- Removes default "" value from required opt security-deposit.
- Check for required currency-code option.

Unset empty string default values on some of the createoffer method's
required option declarations in TakeOfferOptionParser.

- Removes default "" value from required opt offer-id.
- Removes default "" value from required opt payment-account.

Other opt parser default values removed from:

- CancelOfferOptionParser#offer-id
- CreatePaymentAcctOptionParser#payment-account-form
- GetAddressBalanceOptionParser#address
- GetBTCMarketPriceOptionParser#currency-code
- GetOfferOptionParser#offer-id
- GetOffersOptionParser#direction
- GetOffersOptionParser#currency-code
- GetPaymentAcctFormOptionParser#payment-method-id
- GetTradeOptionParser#trade-id
- GetTransactionOptionParser#transaction-id
- RegisterDisputeAgentOptionParser#registration-key
- RegisterDisputeAgentOptionParser#dispute-agent-type
- RemoveWalletPasswordOptionParser#wallet-password
- SendBsqOptionParser#address
- SendBsqOptionParser#amount
- SendBtcOptionParser#address
- SendBtcOptionParser#amount
- SetTxFeeRateOptionParser#tx-fee-rate
- SetWalletPasswordOptionParser#wallet-password
- UnlockWalletOptionParser#wallet-password
- UnlockWalletOptionParser#timeout
- WithdrawFundsOptionParser#trade-id
- WithdrawFundsOptionParser#address
This commit is contained in:
ghubstan 2021-03-04 13:03:04 -03:00
parent a2000bdc33
commit cfaa539a5e
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
19 changed files with 36 additions and 73 deletions

View File

@ -21,13 +21,11 @@ package bisq.cli.opts;
import joptsimple.OptionSpec;
import static bisq.cli.opts.OptLabel.OPT_OFFER_ID;
import static joptsimple.internal.Strings.EMPTY;
public class CancelOfferOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> offerIdOpt = parser.accepts(OPT_OFFER_ID, "id of offer to cancel")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
public CancelOfferOptionParser(String[] args) {
super(args);

View File

@ -33,20 +33,16 @@ public class CreateOfferOptionParser extends AbstractMethodOptionParser implemen
.defaultsTo(EMPTY);
final OptionSpec<String> directionOpt = parser.accepts(OPT_DIRECTION, "offer direction (buy|sell)")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<String> currencyCodeOpt = parser.accepts(OPT_CURRENCY_CODE, "currency code (eur|usd|...)")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<String> amountOpt = parser.accepts(OPT_AMOUNT, "amount of btc to buy or sell")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<String> minAmountOpt = parser.accepts(OPT_MIN_AMOUNT, "minimum amount of btc to buy or sell")
.withOptionalArg()
.defaultsTo(EMPTY);
.withOptionalArg();
final OptionSpec<String> mktPriceMarginOpt = parser.accepts(OPT_MKT_PRICE_MARGIN, "market btc price margin (%)")
.withOptionalArg()
@ -54,11 +50,10 @@ public class CreateOfferOptionParser extends AbstractMethodOptionParser implemen
final OptionSpec<String> fixedPriceOpt = parser.accepts(OPT_FIXED_PRICE, "fixed btc price")
.withOptionalArg()
.defaultsTo(EMPTY);
.defaultsTo("0");
final OptionSpec<String> securityDepositOpt = parser.accepts(OPT_SECURITY_DEPOSIT, "maker security deposit (%)")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<String> makerFeeCurrencyCodeOpt = parser.accepts(OPT_FEE_CURRENCY, "maker fee currency code (bsq|btc)")
.withOptionalArg()
@ -81,6 +76,9 @@ public class CreateOfferOptionParser extends AbstractMethodOptionParser implemen
if (!options.has(directionOpt))
throw new IllegalArgumentException("no direction (buy|sell) specified");
if (!options.has(currencyCodeOpt))
throw new IllegalArgumentException("no currency code specified");
if (!options.has(amountOpt))
throw new IllegalArgumentException("no btc amount specified");

View File

@ -25,14 +25,12 @@ import java.nio.file.Paths;
import static bisq.cli.opts.OptLabel.OPT_PAYMENT_ACCOUNT_FORM;
import static java.lang.String.format;
import static joptsimple.internal.Strings.EMPTY;
public class CreatePaymentAcctOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> paymentAcctFormPathOpt = parser.accepts(OPT_PAYMENT_ACCOUNT_FORM,
"path to json payment account form")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
public CreatePaymentAcctOptionParser(String[] args) {
super(args);

View File

@ -21,13 +21,11 @@ package bisq.cli.opts;
import joptsimple.OptionSpec;
import static bisq.cli.opts.OptLabel.OPT_ADDRESS;
import static joptsimple.internal.Strings.EMPTY;
public class GetAddressBalanceOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> addressOpt = parser.accepts(OPT_ADDRESS, "wallet btc address")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
public GetAddressBalanceOptionParser(String[] args) {
super(args);

View File

@ -21,13 +21,11 @@ package bisq.cli.opts;
import joptsimple.OptionSpec;
import static bisq.cli.opts.OptLabel.OPT_CURRENCY_CODE;
import static joptsimple.internal.Strings.EMPTY;
public class GetBTCMarketPriceOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> currencyCodeOpt = parser.accepts(OPT_CURRENCY_CODE, "currency-code")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
public GetBTCMarketPriceOptionParser(String[] args) {
super(args);

View File

@ -21,13 +21,11 @@ package bisq.cli.opts;
import joptsimple.OptionSpec;
import static bisq.cli.opts.OptLabel.OPT_OFFER_ID;
import static joptsimple.internal.Strings.EMPTY;
public class GetOfferOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> offerIdOpt = parser.accepts(OPT_OFFER_ID, "id of offer to get")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
public GetOfferOptionParser(String[] args) {
super(args);

View File

@ -22,17 +22,14 @@ import joptsimple.OptionSpec;
import static bisq.cli.opts.OptLabel.OPT_CURRENCY_CODE;
import static bisq.cli.opts.OptLabel.OPT_DIRECTION;
import static joptsimple.internal.Strings.EMPTY;
public class GetOffersOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> directionOpt = parser.accepts(OPT_DIRECTION, "offer direction (buy|sell)")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<String> currencyCodeOpt = parser.accepts(OPT_CURRENCY_CODE, "currency code (eur|usd|...)")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
public GetOffersOptionParser(String[] args) {
super(args);

View File

@ -21,14 +21,12 @@ package bisq.cli.opts;
import joptsimple.OptionSpec;
import static bisq.cli.opts.OptLabel.OPT_PAYMENT_METHOD_ID;
import static joptsimple.internal.Strings.EMPTY;
public class GetPaymentAcctFormOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> paymentMethodIdOpt = parser.accepts(OPT_PAYMENT_METHOD_ID,
"id of payment method type used by a payment account")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
public GetPaymentAcctFormOptionParser(String[] args) {
super(args);

View File

@ -22,13 +22,11 @@ import joptsimple.OptionSpec;
import static bisq.cli.opts.OptLabel.OPT_SHOW_CONTRACT;
import static bisq.cli.opts.OptLabel.OPT_TRADE_ID;
import static joptsimple.internal.Strings.EMPTY;
public class GetTradeOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> tradeIdOpt = parser.accepts(OPT_TRADE_ID, "id of trade")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<Boolean> showContractOpt = parser.accepts(OPT_SHOW_CONTRACT, "show trade's json contract")
.withOptionalArg()

View File

@ -21,13 +21,11 @@ package bisq.cli.opts;
import joptsimple.OptionSpec;
import static bisq.cli.opts.OptLabel.OPT_TRANSACTION_ID;
import static joptsimple.internal.Strings.EMPTY;
public class GetTransactionOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> txIdOpt = parser.accepts(OPT_TRANSACTION_ID, "id of transaction")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
public GetTransactionOptionParser(String[] args) {
super(args);

View File

@ -22,17 +22,14 @@ import joptsimple.OptionSpec;
import static bisq.cli.opts.OptLabel.OPT_DISPUTE_AGENT_TYPE;
import static bisq.cli.opts.OptLabel.OPT_REGISTRATION_KEY;
import static joptsimple.internal.Strings.EMPTY;
public class RegisterDisputeAgentOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> disputeAgentTypeOpt = parser.accepts(OPT_DISPUTE_AGENT_TYPE, "dispute agent type")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<String> registrationKeyOpt = parser.accepts(OPT_REGISTRATION_KEY, "registration key")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
public RegisterDisputeAgentOptionParser(String[] args) {
super(args);

View File

@ -21,13 +21,11 @@ package bisq.cli.opts;
import joptsimple.OptionSpec;
import static bisq.cli.opts.OptLabel.OPT_WALLET_PASSWORD;
import static joptsimple.internal.Strings.EMPTY;
public class RemoveWalletPasswordOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> passwordOpt = parser.accepts(OPT_WALLET_PASSWORD, "bisq wallet password")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
public RemoveWalletPasswordOptionParser(String[] args) {
super(args);

View File

@ -28,12 +28,10 @@ import static joptsimple.internal.Strings.EMPTY;
public class SendBsqOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> addressOpt = parser.accepts(OPT_ADDRESS, "destination bsq address")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<String> amountOpt = parser.accepts(OPT_AMOUNT, "amount of bsq to send")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<String> feeRateOpt = parser.accepts(OPT_TX_FEE_RATE, "optional tx fee rate (sats/byte)")
.withOptionalArg()

View File

@ -29,12 +29,10 @@ import static joptsimple.internal.Strings.EMPTY;
public class SendBtcOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> addressOpt = parser.accepts(OPT_ADDRESS, "destination btc address")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<String> amountOpt = parser.accepts(OPT_AMOUNT, "amount of btc to send")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<String> feeRateOpt = parser.accepts(OPT_TX_FEE_RATE, "optional tx fee rate (sats/byte)")
.withOptionalArg()

View File

@ -21,14 +21,12 @@ package bisq.cli.opts;
import joptsimple.OptionSpec;
import static bisq.cli.opts.OptLabel.OPT_TX_FEE_RATE;
import static joptsimple.internal.Strings.EMPTY;
public class SetTxFeeRateOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> feeRateOpt = parser.accepts(OPT_TX_FEE_RATE,
"tx fee rate preference (sats/byte)")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
public SetTxFeeRateOptionParser(String[] args) {
super(args);

View File

@ -27,8 +27,7 @@ import static joptsimple.internal.Strings.EMPTY;
public class SetWalletPasswordOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> passwordOpt = parser.accepts(OPT_WALLET_PASSWORD, "bisq wallet password")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<String> newPasswordOpt = parser.accepts(OPT_NEW_WALLET_PASSWORD, "new bisq wallet password")
.withOptionalArg()

View File

@ -23,17 +23,14 @@ import joptsimple.OptionSpec;
import static bisq.cli.opts.OptLabel.OPT_FEE_CURRENCY;
import static bisq.cli.opts.OptLabel.OPT_OFFER_ID;
import static bisq.cli.opts.OptLabel.OPT_PAYMENT_ACCOUNT;
import static joptsimple.internal.Strings.EMPTY;
public class TakeOfferOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> offerIdOpt = parser.accepts(OPT_OFFER_ID, "id of offer to take")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<String> paymentAccountIdOpt = parser.accepts(OPT_PAYMENT_ACCOUNT, "id of payment account used for trade")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<String> takerFeeCurrencyCodeOpt = parser.accepts(OPT_FEE_CURRENCY, "taker fee currency code (bsq|btc)")
.withOptionalArg()

View File

@ -22,13 +22,11 @@ import joptsimple.OptionSpec;
import static bisq.cli.opts.OptLabel.OPT_TIMEOUT;
import static bisq.cli.opts.OptLabel.OPT_WALLET_PASSWORD;
import static joptsimple.internal.Strings.EMPTY;
public class UnlockWalletOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> passwordOpt = parser.accepts(OPT_WALLET_PASSWORD, "bisq wallet password")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<Long> unlockTimeoutOpt = parser.accepts(OPT_TIMEOUT, "wallet unlock timeout (s)")
.withRequiredArg()

View File

@ -28,12 +28,10 @@ import static joptsimple.internal.Strings.EMPTY;
public class WithdrawFundsOptionParser extends AbstractMethodOptionParser implements MethodOpts {
final OptionSpec<String> tradeIdOpt = parser.accepts(OPT_TRADE_ID, "id of trade")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<String> addressOpt = parser.accepts(OPT_ADDRESS, "destination btc address")
.withRequiredArg()
.defaultsTo(EMPTY);
.withRequiredArg();
final OptionSpec<String> memoOpt = parser.accepts(OPT_MEMO, "optional tx memo")
.withOptionalArg()
@ -53,6 +51,9 @@ public class WithdrawFundsOptionParser extends AbstractMethodOptionParser implem
if (!options.has(tradeIdOpt))
throw new IllegalArgumentException("no trade id specified");
if (!options.has(addressOpt))
throw new IllegalArgumentException("no destination address specified");
return this;
}