mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Adjust CLI opts parsers & opt parsing test for XMR support
This commit is contained in:
parent
03b57916a5
commit
a45c5fa61f
@ -20,27 +20,28 @@ package bisq.cli.opts;
|
||||
|
||||
import joptsimple.OptionSpec;
|
||||
|
||||
import static bisq.cli.CryptoCurrencyUtil.apiDoesSupportCryptoCurrency;
|
||||
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;
|
||||
import static java.lang.String.format;
|
||||
|
||||
public class CreateCryptoCurrencyPaymentAcctOptionParser extends AbstractMethodOptionParser implements MethodOpts {
|
||||
|
||||
final OptionSpec<String> accountNameOpt = parser.accepts(OPT_ACCOUNT_NAME, "crypto currency account name")
|
||||
.withRequiredArg();
|
||||
|
||||
final OptionSpec<String> currencyCodeOpt = parser.accepts(OPT_CURRENCY_CODE, "crypto currency code (bsq only)")
|
||||
final OptionSpec<String> currencyCodeOpt = parser.accepts(OPT_CURRENCY_CODE, "crypto currency code (bsq|xmr)")
|
||||
.withRequiredArg();
|
||||
|
||||
final OptionSpec<String> addressOpt = parser.accepts(OPT_ADDRESS, "bsq address")
|
||||
final OptionSpec<String> addressOpt = parser.accepts(OPT_ADDRESS, "altcoin address")
|
||||
.withRequiredArg();
|
||||
|
||||
final OptionSpec<Boolean> tradeInstantOpt = parser.accepts(OPT_TRADE_INSTANT, "create trade instant account")
|
||||
.withOptionalArg()
|
||||
.ofType(boolean.class)
|
||||
.defaultsTo(FALSE);
|
||||
.defaultsTo(Boolean.FALSE);
|
||||
|
||||
public CreateCryptoCurrencyPaymentAcctOptionParser(String[] args) {
|
||||
super(args);
|
||||
@ -59,11 +60,14 @@ public class CreateCryptoCurrencyPaymentAcctOptionParser extends AbstractMethodO
|
||||
if (!options.has(currencyCodeOpt) || options.valueOf(currencyCodeOpt).isEmpty())
|
||||
throw new IllegalArgumentException("no currency code specified");
|
||||
|
||||
if (!options.valueOf(currencyCodeOpt).equalsIgnoreCase("bsq"))
|
||||
throw new IllegalArgumentException("api only supports bsq crypto currency payment accounts");
|
||||
String cryptoCurrencyCode = options.valueOf(currencyCodeOpt);
|
||||
if (!apiDoesSupportCryptoCurrency(cryptoCurrencyCode))
|
||||
throw new IllegalArgumentException(format("api does not support %s payment accounts",
|
||||
cryptoCurrencyCode.toLowerCase()));
|
||||
|
||||
if (!options.has(addressOpt) || options.valueOf(addressOpt).isEmpty())
|
||||
throw new IllegalArgumentException("no bsq address specified");
|
||||
throw new IllegalArgumentException(format("no %s address specified",
|
||||
cryptoCurrencyCode.toLowerCase()));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class CreateOfferOptionParser extends AbstractMethodOptionParser implemen
|
||||
final OptionSpec<String> directionOpt = parser.accepts(OPT_DIRECTION, "offer direction (buy|sell)")
|
||||
.withRequiredArg();
|
||||
|
||||
final OptionSpec<String> currencyCodeOpt = parser.accepts(OPT_CURRENCY_CODE, "currency code (eur|usd|...)")
|
||||
final OptionSpec<String> currencyCodeOpt = parser.accepts(OPT_CURRENCY_CODE, "currency code (bsq|xmr|eur|usd|...)")
|
||||
.withRequiredArg();
|
||||
|
||||
final OptionSpec<String> amountOpt = parser.accepts(OPT_AMOUNT, "amount of btc to buy or sell")
|
||||
|
@ -235,6 +235,9 @@ public class EditOfferOptionParser extends OfferIdOptionParser implements Method
|
||||
}
|
||||
|
||||
public boolean isUsingMktPriceMargin() {
|
||||
// We do not have the offer, so we do not really know if isUsingMktPriceMargin
|
||||
// should be true or false if editType = ACTIVATION_STATE_ONLY. Take care to
|
||||
// override this value in the daemon in the ACTIVATION_STATE_ONLY case.
|
||||
return !offerEditType.equals(FIXED_PRICE_ONLY)
|
||||
&& !offerEditType.equals(FIXED_PRICE_AND_ACTIVATION_STATE);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public class GetOffersOptionParser extends AbstractMethodOptionParser implements
|
||||
final OptionSpec<String> directionOpt = parser.accepts(OPT_DIRECTION, "offer direction (buy|sell)")
|
||||
.withRequiredArg();
|
||||
|
||||
final OptionSpec<String> currencyCodeOpt = parser.accepts(OPT_CURRENCY_CODE, "currency code (eur|usd|...)")
|
||||
final OptionSpec<String> currencyCodeOpt = parser.accepts(OPT_CURRENCY_CODE, "currency code (bsq|xmr|eur|usd|...)")
|
||||
.withRequiredArg();
|
||||
|
||||
public GetOffersOptionParser(String[] args) {
|
||||
|
@ -327,12 +327,12 @@ public class OptionParsersTest {
|
||||
String[] args = new String[]{
|
||||
PASSWORD_OPT,
|
||||
createcryptopaymentacct.name(),
|
||||
"--" + OPT_ACCOUNT_NAME + "=" + "bsq payment account",
|
||||
"--" + OPT_CURRENCY_CODE + "=" + "xmr"
|
||||
"--" + OPT_ACCOUNT_NAME + "=" + "bch payment account",
|
||||
"--" + OPT_CURRENCY_CODE + "=" + "bch"
|
||||
};
|
||||
Throwable exception = assertThrows(RuntimeException.class, () ->
|
||||
new CreateCryptoCurrencyPaymentAcctOptionParser(args).parse());
|
||||
assertEquals("api only supports bsq crypto currency payment accounts", exception.getMessage());
|
||||
assertEquals("api does not support bch payment accounts", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -349,7 +349,7 @@ public class OptionParsersTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateCryptoCurrencyPaymentAcct() {
|
||||
public void testCreateV1BsqPaymentAcct() {
|
||||
var acctName = "bsq payment account";
|
||||
var currencyCode = "bsq";
|
||||
var address = "B1nXyZ"; // address is validated on server
|
||||
@ -365,4 +365,22 @@ public class OptionParsersTest {
|
||||
assertEquals(currencyCode, parser.getCurrencyCode());
|
||||
assertEquals(address, parser.getAddress());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateV1XmrPaymentAcct() {
|
||||
var acctName = "xmr payment account";
|
||||
var currencyCode = "xmr";
|
||||
var address = "B1nXyZ46XXX"; // address is validated on server
|
||||
String[] args = new String[]{
|
||||
PASSWORD_OPT,
|
||||
createcryptopaymentacct.name(),
|
||||
"--" + OPT_ACCOUNT_NAME + "=" + acctName,
|
||||
"--" + OPT_CURRENCY_CODE + "=" + currencyCode,
|
||||
"--" + OPT_ADDRESS + "=" + address
|
||||
};
|
||||
var parser = new CreateCryptoCurrencyPaymentAcctOptionParser(args).parse();
|
||||
assertEquals(acctName, parser.getAccountName());
|
||||
assertEquals(currencyCode, parser.getCurrencyCode());
|
||||
assertEquals(address, parser.getAddress());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user