mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Adjust CLI classes to new console output api
This commit is contained in:
parent
08d16e6040
commit
0341104823
@ -34,6 +34,8 @@ import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ -41,13 +43,13 @@ import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static bisq.cli.CurrencyFormat.*;
|
||||
import static bisq.cli.Method.*;
|
||||
import static bisq.cli.TableFormat.*;
|
||||
import static bisq.cli.opts.OptLabel.*;
|
||||
import static bisq.cli.table.builder.TableType.*;
|
||||
import static java.lang.String.format;
|
||||
import static java.lang.System.err;
|
||||
import static java.lang.System.exit;
|
||||
import static java.lang.System.out;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.math.BigDecimal.ZERO;
|
||||
|
||||
|
||||
|
||||
@ -76,6 +78,7 @@ import bisq.cli.opts.TakeOfferOptionParser;
|
||||
import bisq.cli.opts.UnlockWalletOptionParser;
|
||||
import bisq.cli.opts.VerifyBsqSentToAddressOptionParser;
|
||||
import bisq.cli.opts.WithdrawFundsOptionParser;
|
||||
import bisq.cli.table.builder.TableBuilder;
|
||||
|
||||
/**
|
||||
* A command-line client for the Bisq gRPC API.
|
||||
@ -167,15 +170,19 @@ public class CliMain {
|
||||
var balances = client.getBalances(currencyCode);
|
||||
switch (currencyCode.toUpperCase()) {
|
||||
case "BSQ":
|
||||
out.println(formatBsqBalanceInfoTbl(balances.getBsq()));
|
||||
new TableBuilder(BSQ_BALANCE_TBL, balances.getBsq()).build().print(out);
|
||||
break;
|
||||
case "BTC":
|
||||
out.println(formatBtcBalanceInfoTbl(balances.getBtc()));
|
||||
new TableBuilder(BTC_BALANCE_TBL, balances.getBtc()).build().print(out);
|
||||
break;
|
||||
case "":
|
||||
default:
|
||||
out.println(formatBalancesTbls(balances));
|
||||
default: {
|
||||
out.println("BTC");
|
||||
new TableBuilder(BTC_BALANCE_TBL, balances.getBtc()).build().print(out);
|
||||
out.println("BSQ");
|
||||
new TableBuilder(BSQ_BALANCE_TBL, balances.getBsq()).build().print(out);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -187,7 +194,7 @@ public class CliMain {
|
||||
}
|
||||
var address = opts.getAddress();
|
||||
var addressBalance = client.getAddressBalance(address);
|
||||
out.println(formatAddressBalanceTbl(singletonList(addressBalance)));
|
||||
new TableBuilder(ADDRESS_BALANCE_TBL, addressBalance).build().print(out);
|
||||
return;
|
||||
}
|
||||
case getbtcprice: {
|
||||
@ -207,7 +214,7 @@ public class CliMain {
|
||||
return;
|
||||
}
|
||||
var fundingAddresses = client.getFundingAddresses();
|
||||
out.println(formatAddressBalanceTbl(fundingAddresses));
|
||||
new TableBuilder(ADDRESS_BALANCE_TBL, fundingAddresses).build().print(out);
|
||||
return;
|
||||
}
|
||||
case getunusedbsqaddress: {
|
||||
@ -316,7 +323,7 @@ public class CliMain {
|
||||
}
|
||||
var txId = opts.getTxId();
|
||||
var tx = client.getTransaction(txId);
|
||||
out.println(TransactionFormat.format(tx));
|
||||
new TableBuilder(TRANSACTION_TBL, tx).build().print(out);
|
||||
return;
|
||||
}
|
||||
case createoffer: {
|
||||
@ -347,7 +354,7 @@ public class CliMain {
|
||||
paymentAcctId,
|
||||
makerFeeCurrencyCode,
|
||||
triggerPrice);
|
||||
out.println(formatOfferTable(singletonList(offer), currencyCode));
|
||||
new TableBuilder(OFFER_TBL, offer).build().print(out);
|
||||
return;
|
||||
}
|
||||
case editoffer: {
|
||||
@ -360,7 +367,7 @@ public class CliMain {
|
||||
var fixedPrice = opts.getFixedPrice();
|
||||
var isUsingMktPriceMargin = opts.isUsingMktPriceMargin();
|
||||
var marketPriceMargin = opts.getMktPriceMarginAsBigDecimal();
|
||||
var triggerPrice = toInternalFiatPrice(opts.getTriggerPriceAsBigDecimal());
|
||||
var triggerPrice = toInternalTriggerPrice(client, offerId, opts.getTriggerPriceAsBigDecimal());
|
||||
var enable = opts.getEnableAsSignedInt();
|
||||
var editOfferType = opts.getOfferEditType();
|
||||
client.editOffer(offerId,
|
||||
@ -392,7 +399,7 @@ public class CliMain {
|
||||
}
|
||||
var offerId = opts.getOfferId();
|
||||
var offer = client.getOffer(offerId);
|
||||
out.println(formatOfferTable(singletonList(offer), offer.getCounterCurrencyCode()));
|
||||
new TableBuilder(OFFER_TBL, offer).build().print(out);
|
||||
return;
|
||||
}
|
||||
case getmyoffer: {
|
||||
@ -403,7 +410,7 @@ public class CliMain {
|
||||
}
|
||||
var offerId = opts.getOfferId();
|
||||
var offer = client.getMyOffer(offerId);
|
||||
out.println(formatOfferTable(singletonList(offer), offer.getCounterCurrencyCode()));
|
||||
new TableBuilder(OFFER_TBL, offer).build().print(out);
|
||||
return;
|
||||
}
|
||||
case getoffers: {
|
||||
@ -418,7 +425,7 @@ public class CliMain {
|
||||
if (offers.isEmpty())
|
||||
out.printf("no %s %s offers found%n", direction, currencyCode);
|
||||
else
|
||||
out.println(formatOfferTable(offers, currencyCode));
|
||||
new TableBuilder(OFFER_TBL, offers).build().print(out);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -434,7 +441,7 @@ public class CliMain {
|
||||
if (offers.isEmpty())
|
||||
out.printf("no %s %s offers found%n", direction, currencyCode);
|
||||
else
|
||||
out.println(formatOfferTable(offers, currencyCode));
|
||||
new TableBuilder(OFFER_TBL, offers).build().print(out);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -464,7 +471,7 @@ public class CliMain {
|
||||
if (showContract)
|
||||
out.println(trade.getContractAsJson());
|
||||
else
|
||||
out.println(TradeFormat.format(trade));
|
||||
new TableBuilder(TRADE_DETAIL_TBL, trade).build().print(out);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -556,11 +563,12 @@ public class CliMain {
|
||||
}
|
||||
var paymentAccount = client.createPaymentAccount(jsonString);
|
||||
out.println("payment account saved");
|
||||
out.println(formatPaymentAcctTbl(singletonList(paymentAccount)));
|
||||
new TableBuilder(PAYMENT_ACCOUNT_TBL, paymentAccount).build().print(out);
|
||||
return;
|
||||
}
|
||||
case createcryptopaymentacct: {
|
||||
var opts = new CreateCryptoCurrencyPaymentAcctOptionParser(args).parse();
|
||||
var opts =
|
||||
new CreateCryptoCurrencyPaymentAcctOptionParser(args).parse();
|
||||
if (opts.isForHelp()) {
|
||||
out.println(client.getMethodHelp(method));
|
||||
return;
|
||||
@ -574,7 +582,7 @@ public class CliMain {
|
||||
address,
|
||||
isTradeInstant);
|
||||
out.println("payment account saved");
|
||||
out.println(formatPaymentAcctTbl(singletonList(paymentAccount)));
|
||||
new TableBuilder(PAYMENT_ACCOUNT_TBL, paymentAccount).build().print(out);
|
||||
return;
|
||||
}
|
||||
case getpaymentaccts: {
|
||||
@ -584,7 +592,7 @@ public class CliMain {
|
||||
}
|
||||
var paymentAccounts = client.getPaymentAccounts();
|
||||
if (paymentAccounts.size() > 0)
|
||||
out.println(formatPaymentAcctTbl(paymentAccounts));
|
||||
new TableBuilder(PAYMENT_ACCOUNT_TBL, paymentAccounts).build().print(out);
|
||||
else
|
||||
out.println("no payment accounts are saved");
|
||||
|
||||
@ -708,6 +716,25 @@ public class CliMain {
|
||||
}
|
||||
}
|
||||
|
||||
private static long toInternalTriggerPrice(GrpcClient client,
|
||||
String offerId,
|
||||
BigDecimal unscaledTriggerPrice) {
|
||||
if (unscaledTriggerPrice.compareTo(ZERO) >= 0) {
|
||||
// Unfortunately, the EditOffer proto triggerPrice field was declared as
|
||||
// a long instead of a string, so the CLI has to look at the offer to know
|
||||
// how to scale the trigger-price (for a fiat or altcoin offer) param sent
|
||||
// to the server in its 'editoffer' request. That means a preliminary round
|
||||
// trip to the server: a 'getmyoffer' request.
|
||||
var offer = client.getMyOffer(offerId);
|
||||
if (offer.getCounterCurrencyCode().equals("BTC"))
|
||||
return toInternalCryptoCurrencyPrice(unscaledTriggerPrice);
|
||||
else
|
||||
return toInternalFiatPrice(unscaledTriggerPrice);
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
private static File saveFileToDisk(String prefix,
|
||||
@SuppressWarnings("SameParameterValue") String suffix,
|
||||
String text) {
|
||||
|
@ -327,6 +327,10 @@ public final class GrpcClient {
|
||||
return offersServiceRequest.getMyOffersSortedByDate(currencyCode);
|
||||
}
|
||||
|
||||
public List<OfferInfo> getMyCryptoCurrencyOffersSortedByDate(String currencyCode) {
|
||||
return offersServiceRequest.getMyCryptoCurrencyOffersSortedByDate(currencyCode);
|
||||
}
|
||||
|
||||
public List<OfferInfo> getMyBsqOffersSortedByDate() {
|
||||
return offersServiceRequest.getMyBsqOffersSortedByDate();
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ public class OffersServiceRequest {
|
||||
this.grpcStubs = grpcStubs;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public OfferInfo createFixedPricedOffer(String direction,
|
||||
String currencyCode,
|
||||
long amount,
|
||||
@ -81,6 +82,7 @@ public class OffersServiceRequest {
|
||||
0 /* no trigger price */);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public OfferInfo createMarketBasedPricedOffer(String direction,
|
||||
String currencyCode,
|
||||
long amount,
|
||||
@ -328,6 +330,13 @@ public class OffersServiceRequest {
|
||||
return sortOffersByDate(offers);
|
||||
}
|
||||
|
||||
public List<OfferInfo> getMyCryptoCurrencyOffersSortedByDate(String currencyCode) {
|
||||
ArrayList<OfferInfo> offers = new ArrayList<>();
|
||||
offers.addAll(getMyCryptoCurrencyOffers(BUY.name(), currencyCode));
|
||||
offers.addAll(getMyCryptoCurrencyOffers(SELL.name(), currencyCode));
|
||||
return sortOffersByDate(offers);
|
||||
}
|
||||
|
||||
public List<OfferInfo> getMyBsqOffersSortedByDate() {
|
||||
ArrayList<OfferInfo> offers = new ArrayList<>();
|
||||
offers.addAll(getMyCryptoCurrencyOffers(BUY.name(), "BSQ"));
|
||||
|
@ -74,6 +74,7 @@ public class TradesServiceRequest {
|
||||
var request = ConfirmPaymentStartedRequest.newBuilder()
|
||||
.setTradeId(tradeId)
|
||||
.build();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
grpcStubs.tradesService.confirmPaymentStarted(request);
|
||||
}
|
||||
|
||||
@ -81,6 +82,7 @@ public class TradesServiceRequest {
|
||||
var request = ConfirmPaymentReceivedRequest.newBuilder()
|
||||
.setTradeId(tradeId)
|
||||
.build();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
grpcStubs.tradesService.confirmPaymentReceived(request);
|
||||
}
|
||||
|
||||
@ -88,6 +90,7 @@ public class TradesServiceRequest {
|
||||
var request = KeepFundsRequest.newBuilder()
|
||||
.setTradeId(tradeId)
|
||||
.build();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
grpcStubs.tradesService.keepFunds(request);
|
||||
}
|
||||
|
||||
@ -97,6 +100,7 @@ public class TradesServiceRequest {
|
||||
.setAddress(address)
|
||||
.setMemo(memo)
|
||||
.build();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
grpcStubs.tradesService.withdrawFunds(request);
|
||||
}
|
||||
}
|
||||
|
@ -161,6 +161,7 @@ public class WalletsServiceRequest {
|
||||
|
||||
public void lockWallet() {
|
||||
var request = LockWalletRequest.newBuilder().build();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
grpcStubs.walletsService.lockWallet(request);
|
||||
}
|
||||
|
||||
@ -168,18 +169,21 @@ public class WalletsServiceRequest {
|
||||
var request = UnlockWalletRequest.newBuilder()
|
||||
.setPassword(walletPassword)
|
||||
.setTimeout(timeout).build();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
grpcStubs.walletsService.unlockWallet(request);
|
||||
}
|
||||
|
||||
public void removeWalletPassword(String walletPassword) {
|
||||
var request = RemoveWalletPasswordRequest.newBuilder()
|
||||
.setPassword(walletPassword).build();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
grpcStubs.walletsService.removeWalletPassword(request);
|
||||
}
|
||||
|
||||
public void setWalletPassword(String walletPassword) {
|
||||
var request = SetWalletPasswordRequest.newBuilder()
|
||||
.setPassword(walletPassword).build();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
grpcStubs.walletsService.setWalletPassword(request);
|
||||
}
|
||||
|
||||
@ -187,6 +191,7 @@ public class WalletsServiceRequest {
|
||||
var request = SetWalletPasswordRequest.newBuilder()
|
||||
.setPassword(oldWalletPassword)
|
||||
.setNewPassword(newWalletPassword).build();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
grpcStubs.walletsService.setWalletPassword(request);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user