Skip to content

Commit

Permalink
Merge branch '01-use-default-bsq-swap-acct' into 02-cli-console-forma…
Browse files Browse the repository at this point in the history
…tting-api
  • Loading branch information
ghubstan committed Nov 7, 2021
2 parents 1d403e7 + edd0141 commit eb57b7e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@

import joptsimple.OptionSpec;

import static bisq.cli.opts.OptLabel.*;
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;

public class CreateCryptoCurrencyPaymentAcctOptionParser extends AbstractMethodOptionParser implements MethodOpts {

Expand All @@ -38,11 +41,6 @@ public class CreateCryptoCurrencyPaymentAcctOptionParser extends AbstractMethodO
.ofType(boolean.class)
.defaultsTo(Boolean.FALSE);

final OptionSpec<Boolean> tradeBsqSwapOpt = parser.accepts(OPT_TRADE_BSQ_SWAP, "create trade bsq swap account")
.withOptionalArg()
.ofType(boolean.class)
.defaultsTo(Boolean.FALSE);

public CreateCryptoCurrencyPaymentAcctOptionParser(String[] args) {
super(args);
}
Expand Down Expand Up @@ -84,8 +82,4 @@ public String getAddress() {
public boolean getIsTradeInstant() {
return options.valueOf(tradeInstantOpt);
}

public boolean getIsTradeBsqSwap() {
return options.valueOf(tradeBsqSwapOpt);
}
}
1 change: 0 additions & 1 deletion cli/src/main/java/bisq/cli/opts/OptLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ 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_TRADE_BSQ_SWAP = "trade-bsq-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";
Expand Down
6 changes: 2 additions & 4 deletions core/src/main/java/bisq/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,11 @@ public String getPaymentAccountForm(String paymentMethodId) {
public PaymentAccount createCryptoCurrencyPaymentAccount(String accountName,
String currencyCode,
String address,
boolean tradeInstant,
boolean isBsqSwap) {
boolean tradeInstant) {
return paymentAccountsService.createCryptoCurrencyPaymentAccount(accountName,
currencyCode,
address,
tradeInstant,
isBsqSwap);
tradeInstant);
}

public List<PaymentMethod> getCryptoCurrencyPaymentMethods() {
Expand Down
21 changes: 5 additions & 16 deletions core/src/main/java/bisq/core/api/CorePaymentAccountsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,34 +103,23 @@ File getPaymentAccountForm(String paymentMethodId) {
PaymentAccount createCryptoCurrencyPaymentAccount(String accountName,
String currencyCode,
String address,
boolean tradeInstant,
boolean isBsqSwap) {
boolean tradeInstant) {
String bsqCode = currencyCode.toUpperCase();
if (!bsqCode.equals("BSQ"))
throw new IllegalArgumentException("api does not currently support " + currencyCode + " accounts");

// Validate the BSQ address string but ignore the return value.
coreWalletsService.getValidBsqAddress(address);

// TODO Split into 2 methods: createAtomicPaymentAccount(), createCryptoCurrencyPaymentAccount().
PaymentAccount cryptoCurrencyAccount;
if (isBsqSwap) {
cryptoCurrencyAccount = PaymentAccountFactory.getPaymentAccount(PaymentMethod.BSQ_SWAP);
} else {
cryptoCurrencyAccount = tradeInstant
? (InstantCryptoCurrencyAccount) PaymentAccountFactory.getPaymentAccount(PaymentMethod.BLOCK_CHAINS_INSTANT)
: (CryptoCurrencyAccount) PaymentAccountFactory.getPaymentAccount(PaymentMethod.BLOCK_CHAINS);
}
AssetAccount cryptoCurrencyAccount = tradeInstant
? (InstantCryptoCurrencyAccount) PaymentAccountFactory.getPaymentAccount(PaymentMethod.BLOCK_CHAINS_INSTANT)
: (CryptoCurrencyAccount) PaymentAccountFactory.getPaymentAccount(PaymentMethod.BLOCK_CHAINS);
cryptoCurrencyAccount.init();
cryptoCurrencyAccount.setAccountName(accountName);
if (!isBsqSwap) {
((AssetAccount) cryptoCurrencyAccount).setAddress(address);
}

cryptoCurrencyAccount.setAddress(address);
Optional<CryptoCurrency> cryptoCurrency = getCryptoCurrency(bsqCode);
cryptoCurrency.ifPresent(cryptoCurrencyAccount::setSingleTradeCurrency);
user.addPaymentAccount(cryptoCurrencyAccount);
accountAgeWitnessService.publishMyAccountAgeWitness(cryptoCurrencyAccount.getPaymentAccountPayload());
log.info("Saved crypto payment account with id {} and payment method {}.",
cryptoCurrencyAccount.getId(),
cryptoCurrencyAccount.getPaymentAccountPayload().getPaymentMethodId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ public void createCryptoCurrencyPaymentAccount(CreateCryptoCurrencyPaymentAccoun
PaymentAccount paymentAccount = coreApi.createCryptoCurrencyPaymentAccount(req.getAccountName(),
req.getCurrencyCode(),
req.getAddress(),
req.getTradeInstant(),
req.getIsBsqSwap());
req.getTradeInstant());
var reply = CreateCryptoCurrencyPaymentAccountReply.newBuilder()
.setPaymentAccount(paymentAccount.toProtoMessage())
.build();
Expand Down
1 change: 0 additions & 1 deletion proto/src/main/proto/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ message CreateCryptoCurrencyPaymentAccountRequest {
string currencyCode = 2;
string address = 3;
bool tradeInstant = 4;
bool isBsqSwap = 5;
}

message CreateCryptoCurrencyPaymentAccountReply {
Expand Down

0 comments on commit eb57b7e

Please sign in to comment.