mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Print createoffer's reply in the CLI's console
This commit is contained in:
parent
d5b8800ba4
commit
c8a7fe4b97
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package bisq.cli;
|
package bisq.cli;
|
||||||
|
|
||||||
|
import bisq.proto.grpc.CreateOfferRequest;
|
||||||
import bisq.proto.grpc.CreatePaymentAccountRequest;
|
import bisq.proto.grpc.CreatePaymentAccountRequest;
|
||||||
import bisq.proto.grpc.GetAddressBalanceRequest;
|
import bisq.proto.grpc.GetAddressBalanceRequest;
|
||||||
import bisq.proto.grpc.GetBalanceRequest;
|
import bisq.proto.grpc.GetBalanceRequest;
|
||||||
@ -38,11 +39,15 @@ import joptsimple.OptionSet;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import static bisq.cli.CurrencyFormat.formatSatoshis;
|
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.formatAddressBalanceTbl;
|
||||||
import static bisq.cli.TableFormat.formatOfferTable;
|
import static bisq.cli.TableFormat.formatOfferTable;
|
||||||
import static bisq.cli.TableFormat.formatPaymentAcctTbl;
|
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.err;
|
||||||
import static java.lang.System.exit;
|
import static java.lang.System.exit;
|
||||||
import static java.lang.System.out;
|
import static java.lang.System.out;
|
||||||
|
import static java.math.BigDecimal.ZERO;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,6 +108,16 @@ public class CliMain {
|
|||||||
var passwordOpt = parser.accepts("password", "rpc server password")
|
var passwordOpt = parser.accepts("password", "rpc server password")
|
||||||
.withRequiredArg();
|
.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);
|
OptionSet options = parser.parse(args);
|
||||||
|
|
||||||
if (options.has(helpOpt)) {
|
if (options.has(helpOpt)) {
|
||||||
@ -116,6 +132,10 @@ public class CliMain {
|
|||||||
throw new IllegalArgumentException("no method specified");
|
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);
|
var methodName = nonOptionArgs.get(0);
|
||||||
Method method;
|
Method method;
|
||||||
try {
|
try {
|
||||||
@ -169,8 +189,39 @@ public class CliMain {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case createoffer: {
|
case createoffer: {
|
||||||
// TODO
|
if (nonOptionArgs.size() < 9)
|
||||||
out.println("offer created");
|
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;
|
return;
|
||||||
}
|
}
|
||||||
case getoffers: {
|
case getoffers: {
|
||||||
@ -179,14 +230,14 @@ public class CliMain {
|
|||||||
+ " expecting direction (buy|sell), currency code");
|
+ " expecting direction (buy|sell), currency code");
|
||||||
|
|
||||||
var direction = nonOptionArgs.get(1);
|
var direction = nonOptionArgs.get(1);
|
||||||
var fiatCurrency = nonOptionArgs.get(2);
|
var currencyCode = nonOptionArgs.get(2);
|
||||||
|
|
||||||
var request = GetOffersRequest.newBuilder()
|
var request = GetOffersRequest.newBuilder()
|
||||||
.setDirection(direction)
|
.setDirection(direction)
|
||||||
.setCurrencyCode(fiatCurrency)
|
.setCurrencyCode(currencyCode)
|
||||||
.build();
|
.build();
|
||||||
var reply = offersService.getOffers(request);
|
var reply = offersService.getOffers(request);
|
||||||
out.println(formatOfferTable(reply.getOffersList(), fiatCurrency));
|
out.println(formatOfferTable(reply.getOffersList(), currencyCode));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case createpaymentacct: {
|
case createpaymentacct: {
|
||||||
|
Loading…
Reference in New Issue
Block a user