mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 07:07:43 +01:00
Merge pull request #4096 from ghubstan/move-protobuf-defs
Move command & core proto defs to new subproject
This commit is contained in:
commit
e2a01b6c66
13 changed files with 225 additions and 262 deletions
4
.idea/codeStyles/Project.xml
generated
4
.idea/codeStyles/Project.xml
generated
|
@ -33,6 +33,10 @@
|
|||
<emptyLine />
|
||||
<package name="bisq.asset" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="bisq.proto.grpc" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="protobuf" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="io.grpc" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="com.google.protobuf" withSubpackages="true" static="false" />
|
||||
|
|
126
build.gradle
126
build.gradle
|
@ -47,6 +47,7 @@ configure(subprojects) {
|
|||
ioVersion = '2.6'
|
||||
jacksonVersion = '2.8.10'
|
||||
javafxVersion = '11.0.2'
|
||||
javaxAnnotationVersion = '1.2'
|
||||
jcsvVersion = '1.4.0'
|
||||
jetbrainsAnnotationsVersion = '13.0'
|
||||
jfoenixVersion = '9.0.6'
|
||||
|
@ -154,6 +155,47 @@ configure([project(':cli'),
|
|||
}
|
||||
}
|
||||
|
||||
configure(project(':proto')) {
|
||||
apply plugin: 'com.google.protobuf'
|
||||
|
||||
dependencies {
|
||||
implementation "com.google.protobuf:protobuf-java:$protobufVersion"
|
||||
implementation("io.grpc:grpc-protobuf:$grpcVersion") {
|
||||
exclude(module: 'guava')
|
||||
exclude(module: 'animal-sniffer-annotations')
|
||||
}
|
||||
implementation("io.grpc:grpc-stub:$grpcVersion") {
|
||||
exclude(module: 'guava')
|
||||
exclude(module: 'animal-sniffer-annotations')
|
||||
}
|
||||
implementation "com.google.guava:guava:$guavaVersion"
|
||||
implementation "org.slf4j:slf4j-api:$slf4jVersion"
|
||||
implementation "ch.qos.logback:logback-core:$logbackVersion"
|
||||
implementation "ch.qos.logback:logback-classic:$logbackVersion"
|
||||
compileOnly "org.projectlombok:lombok:$lombokVersion"
|
||||
compileOnly "javax.annotation:javax.annotation-api:$javaxAnnotationVersion"
|
||||
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
||||
}
|
||||
|
||||
sourceSets.main.java.srcDirs += [
|
||||
'build/generated/source/proto/main/grpc',
|
||||
'build/generated/source/proto/main/java'
|
||||
]
|
||||
|
||||
protobuf {
|
||||
protoc {
|
||||
artifact = "com.google.protobuf:protoc:${protocVersion}"
|
||||
}
|
||||
plugins {
|
||||
grpc {
|
||||
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
|
||||
}
|
||||
}
|
||||
generateProtoTasks {
|
||||
all()*.plugins { grpc {} }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configure(project(':assets')) {
|
||||
dependencies {
|
||||
|
@ -171,17 +213,8 @@ configure(project(':assets')) {
|
|||
|
||||
|
||||
configure(project(':common')) {
|
||||
apply plugin: 'com.google.protobuf'
|
||||
|
||||
sourceSets.main.java.srcDir "$buildDir/generated/source/proto/main/java"
|
||||
|
||||
protobuf {
|
||||
protoc {
|
||||
artifact = "com.google.protobuf:protoc:$protocVersion"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':proto')
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
|
||||
compile "org.openjfx:javafx-base:$javafxVersion:$os"
|
||||
compile "org.openjfx:javafx-graphics:$javafxVersion:$os"
|
||||
|
@ -202,6 +235,10 @@ configure(project(':common')) {
|
|||
exclude(module: 'guava')
|
||||
exclude(module: 'protobuf-java')
|
||||
}
|
||||
runtimeOnly("io.grpc:grpc-netty-shaded:$grpcVersion") {
|
||||
exclude(module: 'guava')
|
||||
exclude(module: 'animal-sniffer-annotations')
|
||||
}
|
||||
compile "org.jetbrains:annotations:$jetbrainsAnnotationsVersion"
|
||||
compile "org.bouncycastle:bcpg-jdk15on:$bcVersion"
|
||||
compile "commons-io:commons-io:$ioVersion"
|
||||
|
@ -236,14 +273,13 @@ configure(project(':p2p')) {
|
|||
|
||||
|
||||
configure(project(':core')) {
|
||||
apply plugin: 'com.google.protobuf'
|
||||
|
||||
dependencies {
|
||||
compile project(':proto')
|
||||
compile project(':assets')
|
||||
compile project(':p2p')
|
||||
implementation "commons-codec:commons-codec:$codecVersion"
|
||||
implementation "org.apache.httpcomponents:httpcore:$httpcoreVersion"
|
||||
implementation("org.apache.httpcomponents:httpclient:$httpclientVersion") {
|
||||
implementation "commons-codec:commons-codec:$codecVersion"
|
||||
implementation "org.apache.httpcomponents:httpcore:$httpcoreVersion"
|
||||
implementation("org.apache.httpcomponents:httpclient:$httpclientVersion") {
|
||||
exclude(module: 'commons-codec')
|
||||
}
|
||||
compile("network.bisq.btcd-cli4j:btcd-cli4j-core:$btcdCli4jVersion") {
|
||||
|
@ -276,8 +312,8 @@ configure(project(':core')) {
|
|||
exclude(module: 'guava')
|
||||
exclude(module: 'animal-sniffer-annotations')
|
||||
}
|
||||
compileOnly "javax.annotation:javax.annotation-api:1.2"
|
||||
runtimeOnly ("io.grpc:grpc-netty-shaded:$grpcVersion") {
|
||||
compileOnly "javax.annotation:javax.annotation-api:$javaxAnnotationVersion"
|
||||
runtimeOnly("io.grpc:grpc-netty-shaded:$grpcVersion") {
|
||||
exclude(module: 'guava')
|
||||
exclude(module: 'animal-sniffer-annotations')
|
||||
}
|
||||
|
@ -291,25 +327,6 @@ configure(project(':core')) {
|
|||
testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
||||
}
|
||||
|
||||
protobuf {
|
||||
protoc {
|
||||
artifact = "com.google.protobuf:protoc:${protocVersion}"
|
||||
}
|
||||
plugins {
|
||||
grpc {
|
||||
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
|
||||
}
|
||||
}
|
||||
generateProtoTasks {
|
||||
all()*.plugins { grpc {} }
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets.main.java.srcDirs += [
|
||||
'build/generated/source/proto/main/grpc',
|
||||
'build/generated/source/proto/main/java'
|
||||
]
|
||||
|
||||
test {
|
||||
systemProperty 'jdk.attach.allowAttachSelf', true
|
||||
}
|
||||
|
@ -319,7 +336,9 @@ configure(project(':cli')) {
|
|||
mainClassName = 'bisq.cli.app.BisqCliMain'
|
||||
|
||||
dependencies {
|
||||
compile project(':core')
|
||||
compile project(':proto')
|
||||
implementation "com.google.guava:guava:$guavaVersion"
|
||||
implementation "com.google.protobuf:protobuf-java:$protobufVersion"
|
||||
implementation("io.grpc:grpc-core:$grpcVersion") {
|
||||
exclude(module: 'guava')
|
||||
exclude(module: 'animal-sniffer-annotations')
|
||||
|
@ -328,6 +347,13 @@ configure(project(':cli')) {
|
|||
exclude(module: 'guava')
|
||||
exclude(module: 'animal-sniffer-annotations')
|
||||
}
|
||||
runtimeOnly("io.grpc:grpc-netty-shaded:$grpcVersion") {
|
||||
exclude(module: 'guava')
|
||||
exclude(module: 'animal-sniffer-annotations')
|
||||
}
|
||||
implementation "org.slf4j:slf4j-api:$slf4jVersion"
|
||||
implementation "ch.qos.logback:logback-core:$logbackVersion"
|
||||
implementation "ch.qos.logback:logback-classic:$logbackVersion"
|
||||
compileOnly "org.projectlombok:lombok:$lombokVersion"
|
||||
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
||||
}
|
||||
|
@ -355,6 +381,7 @@ configure(project(':desktop')) {
|
|||
compile "de.jensd:fontawesomefx:$fontawesomefxVersion"
|
||||
compile "de.jensd:fontawesomefx-commons:$fontawesomefxCommonsVersion"
|
||||
compile "de.jensd:fontawesomefx-materialdesignfont:$fontawesomefxMaterialdesignfontVersion"
|
||||
compile "com.google.guava:guava:$guavaVersion"
|
||||
compile "com.googlecode.jcsv:jcsv:$jcsvVersion"
|
||||
compile "com.github.sarxos:webcam-capture:$sarxosVersion"
|
||||
compile "org.openjfx:javafx-controls:$javafxVersion:$os"
|
||||
|
@ -418,8 +445,8 @@ configure(project(':pricenode')) {
|
|||
dependencies {
|
||||
compile project(":core")
|
||||
implementation "commons-codec:commons-codec:$codecVersion"
|
||||
implementation "org.apache.httpcomponents:httpcore:$httpcoreVersion"
|
||||
implementation("org.apache.httpcomponents:httpclient:$httpclientVersion") {
|
||||
implementation "org.apache.httpcomponents:httpcore:$httpcoreVersion"
|
||||
implementation("org.apache.httpcomponents:httpclient:$httpclientVersion") {
|
||||
exclude(module: 'commons-codec')
|
||||
}
|
||||
compile("org.knowm.xchange:xchange-bitcoinaverage:$knowmXchangeVersion")
|
||||
|
@ -441,12 +468,12 @@ configure(project(':relay')) {
|
|||
dependencies {
|
||||
compile project(':common')
|
||||
compile "com.sparkjava:spark-core:$sparkVersion"
|
||||
compile "com.turo:pushy:$pushyVersion"
|
||||
compile "com.turo:pushy:$pushyVersion"
|
||||
implementation("com.google.firebase:firebase-admin:$firebaseVersion") {
|
||||
exclude(module: 'commons-logging')
|
||||
exclude(module: 'httpclient')
|
||||
exclude(module: 'httpcore')
|
||||
}
|
||||
exclude(module: 'httpcore')
|
||||
}
|
||||
compile "commons-codec:commons-codec:$codecVersion"
|
||||
}
|
||||
}
|
||||
|
@ -481,8 +508,21 @@ configure(project(':daemon')) {
|
|||
|
||||
dependencies {
|
||||
compile project(':core')
|
||||
implementation "com.google.guava:guava:$guavaVersion"
|
||||
implementation "com.google.protobuf:protobuf-java:$protobufVersion"
|
||||
implementation("io.grpc:grpc-protobuf:$grpcVersion") {
|
||||
exclude(module: 'guava')
|
||||
exclude(module: 'animal-sniffer-annotations')
|
||||
}
|
||||
implementation("io.grpc:grpc-stub:$grpcVersion") {
|
||||
exclude(module: 'guava')
|
||||
exclude(module: 'animal-sniffer-annotations')
|
||||
}
|
||||
implementation "org.slf4j:slf4j-api:$slf4jVersion"
|
||||
implementation "ch.qos.logback:logback-core:$logbackVersion"
|
||||
implementation "ch.qos.logback:logback-classic:$logbackVersion"
|
||||
compileOnly "org.projectlombok:lombok:$lombokVersion"
|
||||
compileOnly "javax.annotation:javax.annotation-api:1.2"
|
||||
compileOnly "javax.annotation:javax.annotation-api:$javaxAnnotationVersion"
|
||||
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,150 +17,65 @@
|
|||
|
||||
package bisq.cli.app;
|
||||
|
||||
import bisq.core.grpc.GetBalanceGrpc;
|
||||
import bisq.core.grpc.GetBalanceRequest;
|
||||
import bisq.core.grpc.GetOffersGrpc;
|
||||
import bisq.core.grpc.GetOffersRequest;
|
||||
import bisq.core.grpc.GetPaymentAccountsGrpc;
|
||||
import bisq.core.grpc.GetPaymentAccountsRequest;
|
||||
import bisq.core.grpc.GetTradeStatisticsGrpc;
|
||||
import bisq.core.grpc.GetTradeStatisticsRequest;
|
||||
import bisq.core.grpc.GetVersionGrpc;
|
||||
import bisq.core.grpc.GetVersionRequest;
|
||||
import bisq.core.grpc.PlaceOfferGrpc;
|
||||
import bisq.core.grpc.PlaceOfferRequest;
|
||||
import bisq.core.grpc.StopServerGrpc;
|
||||
import bisq.core.grpc.StopServerRequest;
|
||||
import bisq.core.payment.PaymentAccount;
|
||||
import bisq.core.proto.network.CoreNetworkProtoResolver;
|
||||
import bisq.core.proto.persistable.CorePersistenceProtoResolver;
|
||||
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
import io.grpc.StatusRuntimeException;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import java.time.Clock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static java.lang.String.format;
|
||||
import static java.lang.System.currentTimeMillis;
|
||||
import static java.lang.System.exit;
|
||||
import static java.lang.System.in;
|
||||
|
||||
/**
|
||||
* gRPC client.
|
||||
*
|
||||
* FIXME We get warning 'DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0 - direct buffer constructor: unavailable
|
||||
* java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled' which is
|
||||
* related to Java 10 changes. Requests are working but we should find out why we get that warning
|
||||
*/
|
||||
@Slf4j
|
||||
public class BisqCliMain {
|
||||
|
||||
private final ManagedChannel channel;
|
||||
private final GetVersionGrpc.GetVersionBlockingStub getVersionStub;
|
||||
private final GetBalanceGrpc.GetBalanceBlockingStub getBalanceStub;
|
||||
private final StopServerGrpc.StopServerBlockingStub stopServerStub;
|
||||
private final GetTradeStatisticsGrpc.GetTradeStatisticsBlockingStub getTradeStatisticsStub;
|
||||
private final GetOffersGrpc.GetOffersBlockingStub getOffersStub;
|
||||
private final GetPaymentAccountsGrpc.GetPaymentAccountsBlockingStub getPaymentAccountsStub;
|
||||
private final PlaceOfferGrpc.PlaceOfferBlockingStub placeOfferBlockingStub;
|
||||
private final CorePersistenceProtoResolver corePersistenceProtoResolver;
|
||||
private final CliCommand cmd;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
public static void main(String[] args) {
|
||||
new BisqCliMain("localhost", 8888);
|
||||
}
|
||||
|
||||
private BisqCliMain(String host, int port) {
|
||||
this(ManagedChannelBuilder.forAddress(host, port)
|
||||
// Channels are secure by default (via SSL/TLS). For the example we disable TLS to avoid
|
||||
// needing certificates.
|
||||
.usePlaintext(true).build());
|
||||
// Channels are secure by default (via SSL/TLS); for the example disable TLS to avoid needing certificates.
|
||||
this(ManagedChannelBuilder.forAddress(host, port).usePlaintext().build());
|
||||
|
||||
// Simple input scanner
|
||||
// TODO use some more sophisticated input processing with validation....
|
||||
try (Scanner scanner = new Scanner(System.in);) {
|
||||
try (Scanner scanner = new Scanner(in)) {
|
||||
while (true) {
|
||||
long startTs = System.currentTimeMillis();
|
||||
long startTs = currentTimeMillis();
|
||||
|
||||
String[] tokens = scanner.nextLine().split(" ");
|
||||
if (tokens.length == 0) {
|
||||
return;
|
||||
}
|
||||
String command = tokens[0];
|
||||
List<String> params = new ArrayList<>();
|
||||
if (tokens.length > 1) {
|
||||
params.addAll(Arrays.asList(tokens));
|
||||
List<String> params = new ArrayList<>(Arrays.asList(tokens));
|
||||
params.remove(0);
|
||||
}
|
||||
String result = "";
|
||||
String result;
|
||||
|
||||
switch (command) {
|
||||
case "getVersion":
|
||||
result = getVersion();
|
||||
break;
|
||||
case "getBalance":
|
||||
result = Coin.valueOf(getBalance()).toFriendlyString();
|
||||
long satoshis = cmd.getBalance();
|
||||
// TODO mimic bitcoin-cli? Depends on an error code: Loading block index... Verifying blocks...
|
||||
result = satoshis == -1 ? "Server initializing..." : cmd.prettyBalance.apply(satoshis);
|
||||
break;
|
||||
case "getTradeStatistics":
|
||||
List<bisq.core.trade.statistics.TradeStatistics2> tradeStatistics = getTradeStatistics().stream()
|
||||
.map(bisq.core.trade.statistics.TradeStatistics2::fromProto)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
result = tradeStatistics.toString();
|
||||
case "getVersion":
|
||||
result = cmd.getVersion();
|
||||
break;
|
||||
case "getOffers":
|
||||
List<bisq.core.offer.Offer> offers = getOffers().stream()
|
||||
.map(bisq.core.offer.Offer::fromProto)
|
||||
.collect(Collectors.toList());
|
||||
result = offers.toString();
|
||||
break;
|
||||
case "getPaymentAccounts":
|
||||
List<PaymentAccount> paymentAccounts = getPaymentAccounts().stream()
|
||||
.map(proto -> PaymentAccount.fromProto(proto, corePersistenceProtoResolver))
|
||||
.collect(Collectors.toList());
|
||||
result = paymentAccounts.toString();
|
||||
break;
|
||||
case "placeOffer":
|
||||
// test input: placeOffer CNY BUY 750000000 true -0.2251 1000000 500000 0.15 5a972121-c30a-4b0e-b519-b17b63795d16
|
||||
// payment accountId and currency need to be adopted
|
||||
|
||||
// We expect 9 params
|
||||
// TODO add basic input validation
|
||||
try {
|
||||
checkArgument(params.size() == 9);
|
||||
String currencyCode = params.get(0);
|
||||
String directionAsString = params.get(1);
|
||||
long priceAsLong = Long.parseLong(params.get(2));
|
||||
boolean useMarketBasedPrice = Boolean.parseBoolean(params.get(3));
|
||||
double marketPriceMargin = Double.parseDouble(params.get(4));
|
||||
long amountAsLong = Long.parseLong(params.get(5));
|
||||
long minAmountAsLong = Long.parseLong(params.get(6));
|
||||
double buyerSecurityDeposit = Double.parseDouble(params.get(7));
|
||||
String paymentAccountId = params.get(8);
|
||||
boolean success = placeOffer(currencyCode,
|
||||
directionAsString,
|
||||
priceAsLong,
|
||||
useMarketBasedPrice,
|
||||
marketPriceMargin,
|
||||
amountAsLong,
|
||||
minAmountAsLong,
|
||||
buyerSecurityDeposit,
|
||||
paymentAccountId);
|
||||
result = String.valueOf(success);
|
||||
break;
|
||||
} catch (Throwable t) {
|
||||
log.error(t.toString(), t);
|
||||
break;
|
||||
}
|
||||
case "stop":
|
||||
result = "Shut down client";
|
||||
try {
|
||||
|
@ -170,7 +85,7 @@ public class BisqCliMain {
|
|||
}
|
||||
break;
|
||||
case "stopServer":
|
||||
stopServer();
|
||||
cmd.stopServer();
|
||||
result = "Server stopped";
|
||||
break;
|
||||
default:
|
||||
|
@ -178,8 +93,7 @@ public class BisqCliMain {
|
|||
}
|
||||
|
||||
// First response is rather slow (300 ms) but following responses are fast (3-5 ms).
|
||||
log.info("Request took: {} ms", System.currentTimeMillis() - startTs);
|
||||
log.info(result);
|
||||
log.info("{}\t{}", result, cmd.responseTime.apply(startTs));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -189,108 +103,11 @@ public class BisqCliMain {
|
|||
*/
|
||||
private BisqCliMain(ManagedChannel channel) {
|
||||
this.channel = channel;
|
||||
|
||||
getVersionStub = GetVersionGrpc.newBlockingStub(channel);
|
||||
getBalanceStub = GetBalanceGrpc.newBlockingStub(channel);
|
||||
getTradeStatisticsStub = GetTradeStatisticsGrpc.newBlockingStub(channel);
|
||||
getOffersStub = GetOffersGrpc.newBlockingStub(channel);
|
||||
getPaymentAccountsStub = GetPaymentAccountsGrpc.newBlockingStub(channel);
|
||||
placeOfferBlockingStub = PlaceOfferGrpc.newBlockingStub(channel);
|
||||
stopServerStub = StopServerGrpc.newBlockingStub(channel);
|
||||
|
||||
CoreNetworkProtoResolver coreNetworkProtoResolver = new CoreNetworkProtoResolver(Clock.systemDefaultZone());
|
||||
//TODO
|
||||
corePersistenceProtoResolver = new CorePersistenceProtoResolver(null, coreNetworkProtoResolver, null, null);
|
||||
}
|
||||
|
||||
private String getVersion() {
|
||||
GetVersionRequest request = GetVersionRequest.newBuilder().build();
|
||||
try {
|
||||
return getVersionStub.getVersion(request).getVersion();
|
||||
} catch (StatusRuntimeException e) {
|
||||
return "RPC failed: " + e.getStatus();
|
||||
}
|
||||
}
|
||||
|
||||
private long getBalance() {
|
||||
GetBalanceRequest request = GetBalanceRequest.newBuilder().build();
|
||||
try {
|
||||
return getBalanceStub.getBalance(request).getBalance();
|
||||
} catch (StatusRuntimeException e) {
|
||||
log.warn("RPC failed: {}", e.getStatus());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private List<protobuf.TradeStatistics2> getTradeStatistics() {
|
||||
GetTradeStatisticsRequest request = GetTradeStatisticsRequest.newBuilder().build();
|
||||
try {
|
||||
return getTradeStatisticsStub.getTradeStatistics(request).getTradeStatisticsList();
|
||||
} catch (StatusRuntimeException e) {
|
||||
log.warn("RPC failed: {}", e.getStatus());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private List<protobuf.Offer> getOffers() {
|
||||
GetOffersRequest request = GetOffersRequest.newBuilder().build();
|
||||
try {
|
||||
return getOffersStub.getOffers(request).getOffersList();
|
||||
} catch (StatusRuntimeException e) {
|
||||
log.warn("RPC failed: {}", e.getStatus());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private List<protobuf.PaymentAccount> getPaymentAccounts() {
|
||||
GetPaymentAccountsRequest request = GetPaymentAccountsRequest.newBuilder().build();
|
||||
try {
|
||||
return getPaymentAccountsStub.getPaymentAccounts(request).getPaymentAccountsList();
|
||||
} catch (StatusRuntimeException e) {
|
||||
log.warn("RPC failed: {}", e.getStatus());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean placeOffer(String currencyCode,
|
||||
String directionAsString,
|
||||
long priceAsLong,
|
||||
boolean useMarketBasedPrice,
|
||||
double marketPriceMargin,
|
||||
long amountAsLong,
|
||||
long minAmountAsLong,
|
||||
double buyerSecurityDeposit,
|
||||
String paymentAccountId) {
|
||||
PlaceOfferRequest request = PlaceOfferRequest.newBuilder()
|
||||
.setCurrencyCode(currencyCode)
|
||||
.setDirection(directionAsString)
|
||||
.setPrice(priceAsLong)
|
||||
.setUseMarketBasedPrice(useMarketBasedPrice)
|
||||
.setMarketPriceMargin(marketPriceMargin)
|
||||
.setAmount(amountAsLong)
|
||||
.setMinAmount(minAmountAsLong)
|
||||
.setBuyerSecurityDeposit(buyerSecurityDeposit)
|
||||
.setPaymentAccountId(paymentAccountId)
|
||||
.build();
|
||||
try {
|
||||
return placeOfferBlockingStub.placeOffer(request).getResult();
|
||||
} catch (StatusRuntimeException e) {
|
||||
log.warn("RPC failed: {}", e.getStatus());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void stopServer() {
|
||||
StopServerRequest request = StopServerRequest.newBuilder().build();
|
||||
try {
|
||||
stopServerStub.stopServer(request);
|
||||
} catch (StatusRuntimeException e) {
|
||||
log.warn("RPC failed: {}", e.getStatus());
|
||||
}
|
||||
this.cmd = new CliCommand(channel);
|
||||
}
|
||||
|
||||
private void shutdown() throws InterruptedException {
|
||||
channel.shutdown().awaitTermination(1, TimeUnit.SECONDS);
|
||||
System.exit(0);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
|
70
cli/src/main/java/bisq/cli/app/CliCommand.java
Normal file
70
cli/src/main/java/bisq/cli/app/CliCommand.java
Normal file
|
@ -0,0 +1,70 @@
|
|||
package bisq.cli.app;
|
||||
|
||||
import bisq.proto.grpc.GetBalanceGrpc;
|
||||
import bisq.proto.grpc.GetBalanceRequest;
|
||||
import bisq.proto.grpc.GetVersionGrpc;
|
||||
import bisq.proto.grpc.GetVersionRequest;
|
||||
import bisq.proto.grpc.StopServerGrpc;
|
||||
import bisq.proto.grpc.StopServerRequest;
|
||||
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.StatusRuntimeException;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static java.lang.System.currentTimeMillis;
|
||||
|
||||
@Slf4j
|
||||
final class CliCommand {
|
||||
|
||||
private final GetBalanceGrpc.GetBalanceBlockingStub getBalanceStub;
|
||||
private final GetVersionGrpc.GetVersionBlockingStub getVersionStub;
|
||||
private final StopServerGrpc.StopServerBlockingStub stopServerStub;
|
||||
|
||||
private final DecimalFormat btcFormat = new DecimalFormat("###,##0.00000000");
|
||||
private final BigDecimal satoshiDivisor = new BigDecimal(100000000);
|
||||
@SuppressWarnings("BigDecimalMethodWithoutRoundingCalled")
|
||||
final Function<Long, String> prettyBalance = (sats) -> btcFormat.format(BigDecimal.valueOf(sats).divide(satoshiDivisor));
|
||||
|
||||
final Function<Long, String> responseTime = (t0) -> "(response time: " + (currentTimeMillis() - t0) + " ms)";
|
||||
|
||||
CliCommand(ManagedChannel channel) {
|
||||
getBalanceStub = GetBalanceGrpc.newBlockingStub(channel);
|
||||
getVersionStub = GetVersionGrpc.newBlockingStub(channel);
|
||||
stopServerStub = StopServerGrpc.newBlockingStub(channel);
|
||||
}
|
||||
|
||||
String getVersion() {
|
||||
GetVersionRequest request = GetVersionRequest.newBuilder().build();
|
||||
try {
|
||||
return getVersionStub.getVersion(request).getVersion();
|
||||
} catch (StatusRuntimeException e) {
|
||||
return "RPC failed: " + e.getStatus();
|
||||
}
|
||||
}
|
||||
|
||||
long getBalance() {
|
||||
GetBalanceRequest request = GetBalanceRequest.newBuilder().build();
|
||||
try {
|
||||
return getBalanceStub.getBalance(request).getBalance();
|
||||
} catch (StatusRuntimeException e) {
|
||||
log.warn("RPC failed: {}", e.getStatus());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void stopServer() {
|
||||
StopServerRequest request = StopServerRequest.newBuilder().build();
|
||||
try {
|
||||
stopServerStub.stopServer(request);
|
||||
} catch (StatusRuntimeException e) {
|
||||
log.warn("RPC failed: {}", e.getStatus());
|
||||
}
|
||||
}
|
||||
}
|
17
cli/src/main/resources/logback.xml
Normal file
17
cli/src/main/resources/logback.xml
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="CONSOLE_APPENDER" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%highlight(%d{MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{30}: %msg %xEx%n)</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="TRACE">
|
||||
<appender-ref ref="CONSOLE_APPENDER"/>
|
||||
</root>
|
||||
|
||||
<logger name="io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0" level="WARN"/>
|
||||
<logger name="io.grpc.netty.shaded.io.netty.util.internal.NativeLibraryLoader" level="WARN"/>
|
||||
<logger name="io.grpc.netty" level="TRACE"/>
|
||||
|
||||
</configuration>
|
|
@ -22,6 +22,28 @@ import bisq.core.payment.PaymentAccount;
|
|||
import bisq.core.trade.handlers.TransactionResultHandler;
|
||||
import bisq.core.trade.statistics.TradeStatistics2;
|
||||
|
||||
import bisq.proto.grpc.GetBalanceGrpc;
|
||||
import bisq.proto.grpc.GetBalanceReply;
|
||||
import bisq.proto.grpc.GetBalanceRequest;
|
||||
import bisq.proto.grpc.GetOffersGrpc;
|
||||
import bisq.proto.grpc.GetOffersReply;
|
||||
import bisq.proto.grpc.GetOffersRequest;
|
||||
import bisq.proto.grpc.GetPaymentAccountsGrpc;
|
||||
import bisq.proto.grpc.GetPaymentAccountsReply;
|
||||
import bisq.proto.grpc.GetPaymentAccountsRequest;
|
||||
import bisq.proto.grpc.GetTradeStatisticsGrpc;
|
||||
import bisq.proto.grpc.GetTradeStatisticsReply;
|
||||
import bisq.proto.grpc.GetTradeStatisticsRequest;
|
||||
import bisq.proto.grpc.GetVersionGrpc;
|
||||
import bisq.proto.grpc.GetVersionReply;
|
||||
import bisq.proto.grpc.GetVersionRequest;
|
||||
import bisq.proto.grpc.PlaceOfferGrpc;
|
||||
import bisq.proto.grpc.PlaceOfferReply;
|
||||
import bisq.proto.grpc.PlaceOfferRequest;
|
||||
import bisq.proto.grpc.StopServerGrpc;
|
||||
import bisq.proto.grpc.StopServerReply;
|
||||
import bisq.proto.grpc.StopServerRequest;
|
||||
|
||||
import io.grpc.Server;
|
||||
import io.grpc.ServerBuilder;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
|
|
|
@ -21,15 +21,13 @@ import bisq.core.offer.OpenOffer;
|
|||
|
||||
import bisq.common.proto.ProtoUtil;
|
||||
|
||||
import protobuf.OfferPayload;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
||||
|
||||
import protobuf.OfferPayload;
|
||||
|
||||
@SuppressWarnings("UnusedAssignment")
|
||||
public class ProtoUtilTest {
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
@Slf4j
|
||||
public class BisqDaemonMain extends BisqHeadlessAppMain implements BisqSetup.BisqSetupListener {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
public static void main(String[] args) {
|
||||
new BisqDaemonMain().execute(args);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ import bisq.network.p2p.SendersNodeAddressMessage;
|
|||
import bisq.common.app.Version;
|
||||
import bisq.common.proto.ProtoUtil;
|
||||
|
||||
import protobuf.NetworkEnvelope;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import java.util.Set;
|
||||
|
@ -34,10 +36,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
|
||||
|
||||
import protobuf.NetworkEnvelope;
|
||||
|
||||
@Slf4j
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Value
|
||||
|
|
|
@ -24,6 +24,8 @@ import bisq.common.app.Capabilities;
|
|||
import bisq.common.app.Version;
|
||||
import bisq.common.proto.ProtoUtil;
|
||||
|
||||
import protobuf.NetworkEnvelope;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import java.util.Set;
|
||||
|
@ -35,8 +37,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import protobuf.NetworkEnvelope;
|
||||
|
||||
@Slf4j
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Value
|
||||
|
|
|
@ -18,10 +18,9 @@
|
|||
syntax = "proto3";
|
||||
package io.bisq.protobuffer;
|
||||
|
||||
// FIXME: IntelliJ does not recognize the import but the compiler does
|
||||
import "pb.proto";
|
||||
|
||||
option java_package = "bisq.core.grpc";
|
||||
option java_package = "bisq.proto.grpc";
|
||||
option java_multiple_files = true;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -68,7 +67,6 @@ service GetTradeStatistics {
|
|||
message GetTradeStatisticsRequest {
|
||||
}
|
||||
|
||||
// FIXME: IntelliJ does not recognize the imported TradeStatistics2 but the compiler does
|
||||
message GetTradeStatisticsReply {
|
||||
repeated TradeStatistics2 TradeStatistics = 1;
|
||||
}
|
||||
|
@ -85,7 +83,6 @@ service GetOffers {
|
|||
message GetOffersRequest {
|
||||
}
|
||||
|
||||
// FIXME: IntelliJ does not recognize the imported Offer but the compiler does
|
||||
message GetOffersReply {
|
||||
repeated Offer offers = 1;
|
||||
}
|
||||
|
@ -102,7 +99,6 @@ service GetPaymentAccounts {
|
|||
message GetPaymentAccountsRequest {
|
||||
}
|
||||
|
||||
// FIXME: IntelliJ does not recognize the imported PaymentAccount but the compiler does
|
||||
message GetPaymentAccountsReply {
|
||||
repeated PaymentAccount paymentAccounts = 1;
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
include 'proto'
|
||||
include 'assets'
|
||||
include 'common'
|
||||
include 'p2p'
|
||||
|
|
Loading…
Add table
Reference in a new issue