Print createoffer's reply in the CLI's console

This commit is contained in:
ghubstan 2020-09-23 19:57:22 -03:00
parent d5b8800ba4
commit c8a7fe4b97
No known key found for this signature in database
GPG Key ID: E35592D6800A861E

View File

@ -17,6 +17,7 @@
package bisq.cli;
import bisq.proto.grpc.CreateOfferRequest;
import bisq.proto.grpc.CreatePaymentAccountRequest;
import bisq.proto.grpc.GetAddressBalanceRequest;
import bisq.proto.grpc.GetBalanceRequest;
@ -38,11 +39,15 @@ import joptsimple.OptionSet;
import java.io.IOException;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import static bisq.cli.CurrencyFormat.formatSatoshis;
import static bisq.cli.CurrencyFormat.toSatoshis;
import static bisq.cli.NegativeNumberOptions.hasNegativeNumberOptions;
import static bisq.cli.TableFormat.formatAddressBalanceTbl;
import static bisq.cli.TableFormat.formatOfferTable;
import static bisq.cli.TableFormat.formatPaymentAcctTbl;
@ -50,6 +55,7 @@ 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.math.BigDecimal.ZERO;
import static java.util.Collections.singletonList;
/**
@ -102,6 +108,16 @@ public class CliMain {
var passwordOpt = parser.accepts("password", "rpc server password")
.withRequiredArg();
var negativeNumberOpts = hasNegativeNumberOptions(args)
? new NegativeNumberOptions()
: null;
// Cache any negative number params that will not be accepted by the parser.
if (negativeNumberOpts != null)
args = negativeNumberOpts.removeNegativeNumberOptions(args);
// Parse the options after temporarily removing any negative number params we
// do not want the parser recognizing as invalid option arguments, e.g., -0.05.
OptionSet options = parser.parse(args);
if (options.has(helpOpt)) {
@ -116,6 +132,10 @@ public class CliMain {
throw new IllegalArgumentException("no method specified");
}
// Restore any cached negative number params to the nonOptionArgs list.
if (negativeNumberOpts != null)
nonOptionArgs = negativeNumberOpts.restoreNegativeNumberOptions(nonOptionArgs);
var methodName = nonOptionArgs.get(0);
Method method;
try {
@ -169,8 +189,39 @@ public class CliMain {
return;
}
case createoffer: {
// TODO
out.println("offer created");
if (nonOptionArgs.size() < 9)
throw new IllegalArgumentException("incorrect parameter count,"
+ " expecting buy | sell, payment acct id, currency code, amount, min amount,"
+ " use-market-based-price, fixed-price | mkt-price-margin, security-deposit");
var direction = nonOptionArgs.get(1);
var paymentAcctId = nonOptionArgs.get(2);
var currencyCode = nonOptionArgs.get(3);
var amount = toSatoshis(nonOptionArgs.get(4));
var minAmount = toSatoshis(nonOptionArgs.get(5));
var useMarketBasedPrice = Boolean.parseBoolean(nonOptionArgs.get(6));
var fixedPrice = ZERO;
var marketPriceMargin = ZERO;
if (useMarketBasedPrice)
marketPriceMargin = new BigDecimal(nonOptionArgs.get(7));
else
fixedPrice = new BigDecimal(nonOptionArgs.get(7));
var securityDeposit = new BigDecimal(nonOptionArgs.get(8));
var request = CreateOfferRequest.newBuilder()
.setDirection(direction.toUpperCase())
.setCurrencyCode(currencyCode.toUpperCase())
.setAmount(amount)
.setMinAmount(minAmount)
.setUseMarketBasedPrice(useMarketBasedPrice)
.setPrice(fixedPrice.longValue())
.setMarketPriceMargin(marketPriceMargin.doubleValue())
.setBuyerSecurityDeposit(securityDeposit.doubleValue())
.setPaymentAccountId(paymentAcctId)
.build();
var reply = offersService.createOffer(request);
out.println(formatOfferTable(singletonList(reply.getOffer()), currencyCode));
return;
}
case getoffers: {
@ -179,14 +230,14 @@ public class CliMain {
+ " expecting direction (buy|sell), currency code");
var direction = nonOptionArgs.get(1);
var fiatCurrency = nonOptionArgs.get(2);
var currencyCode = nonOptionArgs.get(2);
var request = GetOffersRequest.newBuilder()
.setDirection(direction)
.setCurrencyCode(fiatCurrency)
.setCurrencyCode(currencyCode)
.build();
var reply = offersService.getOffers(request);
out.println(formatOfferTable(reply.getOffersList(), fiatCurrency));
out.println(formatOfferTable(reply.getOffersList(), currencyCode));
return;
}
case createpaymentacct: {