diff --git a/cli/src/main/java/bisq/cli/CliMain.java b/cli/src/main/java/bisq/cli/CliMain.java index c7c16a4376f..dee11cc7dd7 100644 --- a/cli/src/main/java/bisq/cli/CliMain.java +++ b/cli/src/main/java/bisq/cli/CliMain.java @@ -28,7 +28,7 @@ import bisq.proto.grpc.RemoveWalletPasswordRequest; import bisq.proto.grpc.SetWalletPasswordRequest; import bisq.proto.grpc.UnlockWalletRequest; -import bisq.proto.grpc.WalletGrpc; +import bisq.proto.grpc.WalletsGrpc; import io.grpc.ManagedChannelBuilder; import io.grpc.StatusRuntimeException; @@ -139,7 +139,7 @@ public static void run(String[] args) { var versionService = GetVersionGrpc.newBlockingStub(channel).withCallCredentials(credentials); var paymentAccountsService = PaymentAccountsGrpc.newBlockingStub(channel).withCallCredentials(credentials); - var walletService = WalletGrpc.newBlockingStub(channel).withCallCredentials(credentials); + var walletsService = WalletsGrpc.newBlockingStub(channel).withCallCredentials(credentials); try { switch (method) { @@ -151,7 +151,7 @@ public static void run(String[] args) { } case getbalance: { var request = GetBalanceRequest.newBuilder().build(); - var reply = walletService.getBalance(request); + var reply = walletsService.getBalance(request); var satoshiBalance = reply.getBalance(); var satoshiDivisor = new BigDecimal(100000000); var btcFormat = new DecimalFormat("###,##0.00000000"); @@ -166,13 +166,13 @@ public static void run(String[] args) { var request = GetAddressBalanceRequest.newBuilder() .setAddress(nonOptionArgs.get(1)).build(); - var reply = walletService.getAddressBalance(request); + var reply = walletsService.getAddressBalance(request); out.println(reply.getAddressBalanceInfo()); return; } case getfundingaddresses: { var request = GetFundingAddressesRequest.newBuilder().build(); - var reply = walletService.getFundingAddresses(request); + var reply = walletsService.getFundingAddresses(request); out.println(reply.getFundingAddressesInfo()); return; } @@ -202,7 +202,7 @@ public static void run(String[] args) { } case lockwallet: { var request = LockWalletRequest.newBuilder().build(); - walletService.lockWallet(request); + walletsService.lockWallet(request); out.println("wallet locked"); return; } @@ -222,7 +222,7 @@ public static void run(String[] args) { var request = UnlockWalletRequest.newBuilder() .setPassword(nonOptionArgs.get(1)) .setTimeout(timeout).build(); - walletService.unlockWallet(request); + walletsService.unlockWallet(request); out.println("wallet unlocked"); return; } @@ -231,7 +231,7 @@ public static void run(String[] args) { throw new IllegalArgumentException("no password specified"); var request = RemoveWalletPasswordRequest.newBuilder().setPassword(nonOptionArgs.get(1)).build(); - walletService.removeWalletPassword(request); + walletsService.removeWalletPassword(request); out.println("wallet decrypted"); return; } @@ -243,7 +243,7 @@ public static void run(String[] args) { var hasNewPassword = nonOptionArgs.size() == 3; if (hasNewPassword) requestBuilder.setNewPassword(nonOptionArgs.get(2)); - walletService.setWalletPassword(requestBuilder.build()); + walletsService.setWalletPassword(requestBuilder.build()); out.println("wallet encrypted" + (hasNewPassword ? " with new password" : "")); return; } diff --git a/core/src/main/java/bisq/core/grpc/CoreApi.java b/core/src/main/java/bisq/core/grpc/CoreApi.java index 8d45f31d5d3..610f0d7d8dd 100644 --- a/core/src/main/java/bisq/core/grpc/CoreApi.java +++ b/core/src/main/java/bisq/core/grpc/CoreApi.java @@ -48,6 +48,7 @@ @Slf4j public class CoreApi { private final CorePaymentAccountsService paymentAccountsService; + private final CoreWalletsService walletsService; private final OfferBookService offerBookService; private final TradeStatisticsManager tradeStatisticsManager; private final CreateOfferService createOfferService; @@ -56,12 +57,14 @@ public class CoreApi { @Inject public CoreApi(CorePaymentAccountsService paymentAccountsService, + CoreWalletsService walletsService, OfferBookService offerBookService, TradeStatisticsManager tradeStatisticsManager, CreateOfferService createOfferService, OpenOfferManager openOfferManager, User user) { this.paymentAccountsService = paymentAccountsService; + this.walletsService = walletsService; this.offerBookService = offerBookService; this.tradeStatisticsManager = tradeStatisticsManager; this.createOfferService = createOfferService; @@ -73,20 +76,52 @@ public String getVersion() { return Version.VERSION; } - public List getTradeStatistics() { - return new ArrayList<>(tradeStatisticsManager.getObservableTradeStatisticsSet()); + /////////////////////////////////////////////////////////////////////////////////////////// + // Wallets + /////////////////////////////////////////////////////////////////////////////////////////// + + public long getAvailableBalance() { + return walletsService.getAvailableBalance(); } - public List getOffers() { - return offerBookService.getOffers(); + public long getAddressBalance(String addressString) { + return walletsService.getAddressBalance(addressString); } - public void createPaymentAccount(String accountName, String accountNumber, String fiatCurrencyCode) { - paymentAccountsService.createPaymentAccount(accountName, accountNumber, fiatCurrencyCode); + public String getAddressBalanceInfo(String addressString) { + return walletsService.getAddressBalanceInfo(addressString); } - public Set getPaymentAccounts() { - return paymentAccountsService.getPaymentAccounts(); + public String getFundingAddresses() { + return walletsService.getFundingAddresses(); + } + + public void setWalletPassword(String password, String newPassword) { + walletsService.setWalletPassword(password, newPassword); + } + + public void lockWallet() { + walletsService.lockWallet(); + } + + public void unlockWallet(String password, long timeout) { + walletsService.unlockWallet(password, timeout); + } + + public void removeWalletPassword(String password) { + walletsService.removeWalletPassword(password); + } + + public List getTradeStatistics() { + return new ArrayList<>(tradeStatisticsManager.getObservableTradeStatisticsSet()); + } + + public int getNumConfirmationsForMostRecentTransaction(String addressString) { + return walletsService.getNumConfirmationsForMostRecentTransaction(addressString); + } + + public List getOffers() { + return offerBookService.getOffers(); } public void placeOffer(String currencyCode, @@ -152,4 +187,15 @@ public void placeOffer(String offerId, log::error); } + /////////////////////////////////////////////////////////////////////////////////////////// + // PaymentAccounts + /////////////////////////////////////////////////////////////////////////////////////////// + + public void createPaymentAccount(String accountName, String accountNumber, String fiatCurrencyCode) { + paymentAccountsService.createPaymentAccount(accountName, accountNumber, fiatCurrencyCode); + } + + public Set getPaymentAccounts() { + return paymentAccountsService.getPaymentAccounts(); + } } diff --git a/core/src/main/java/bisq/core/grpc/GrpcServer.java b/core/src/main/java/bisq/core/grpc/GrpcServer.java index 2c4f766b3c6..6fa6dad9faf 100644 --- a/core/src/main/java/bisq/core/grpc/GrpcServer.java +++ b/core/src/main/java/bisq/core/grpc/GrpcServer.java @@ -59,7 +59,7 @@ public class GrpcServer { public GrpcServer(Config config, CoreApi coreApi, GrpcPaymentAccountsService paymentAccountsService, - GrpcWalletService walletService) { + GrpcWalletsService walletService) { this.coreApi = coreApi; this.server = ServerBuilder.forPort(config.apiPort) .addService(new GetVersionService()) diff --git a/core/src/main/java/bisq/core/grpc/GrpcWalletService.java b/core/src/main/java/bisq/core/grpc/GrpcWalletsService.java similarity index 86% rename from core/src/main/java/bisq/core/grpc/GrpcWalletService.java rename to core/src/main/java/bisq/core/grpc/GrpcWalletsService.java index 0343960f394..e7ec5629100 100644 --- a/core/src/main/java/bisq/core/grpc/GrpcWalletService.java +++ b/core/src/main/java/bisq/core/grpc/GrpcWalletsService.java @@ -14,7 +14,7 @@ import bisq.proto.grpc.SetWalletPasswordRequest; import bisq.proto.grpc.UnlockWalletReply; import bisq.proto.grpc.UnlockWalletRequest; -import bisq.proto.grpc.WalletGrpc; +import bisq.proto.grpc.WalletsGrpc; import io.grpc.Status; import io.grpc.StatusRuntimeException; @@ -22,19 +22,19 @@ import javax.inject.Inject; -class GrpcWalletService extends WalletGrpc.WalletImplBase { +class GrpcWalletsService extends WalletsGrpc.WalletsImplBase { - private final CoreWalletsService walletsService; + private final CoreApi coreApi; @Inject - public GrpcWalletService(CoreWalletsService walletsService) { - this.walletsService = walletsService; + public GrpcWalletsService(CoreApi coreApi) { + this.coreApi = coreApi; } @Override public void getBalance(GetBalanceRequest req, StreamObserver responseObserver) { try { - long result = walletsService.getAvailableBalance(); + long result = coreApi.getAvailableBalance(); var reply = GetBalanceReply.newBuilder().setBalance(result).build(); responseObserver.onNext(reply); responseObserver.onCompleted(); @@ -49,7 +49,7 @@ public void getBalance(GetBalanceRequest req, StreamObserver re public void getAddressBalance(GetAddressBalanceRequest req, StreamObserver responseObserver) { try { - String result = walletsService.getAddressBalanceInfo(req.getAddress()); + String result = coreApi.getAddressBalanceInfo(req.getAddress()); var reply = GetAddressBalanceReply.newBuilder().setAddressBalanceInfo(result).build(); responseObserver.onNext(reply); responseObserver.onCompleted(); @@ -64,7 +64,7 @@ public void getAddressBalance(GetAddressBalanceRequest req, public void getFundingAddresses(GetFundingAddressesRequest req, StreamObserver responseObserver) { try { - String result = walletsService.getFundingAddresses(); + String result = coreApi.getFundingAddresses(); var reply = GetFundingAddressesReply.newBuilder().setFundingAddressesInfo(result).build(); responseObserver.onNext(reply); responseObserver.onCompleted(); @@ -79,7 +79,7 @@ public void getFundingAddresses(GetFundingAddressesRequest req, public void setWalletPassword(SetWalletPasswordRequest req, StreamObserver responseObserver) { try { - walletsService.setWalletPassword(req.getPassword(), req.getNewPassword()); + coreApi.setWalletPassword(req.getPassword(), req.getNewPassword()); var reply = SetWalletPasswordReply.newBuilder().build(); responseObserver.onNext(reply); responseObserver.onCompleted(); @@ -94,7 +94,7 @@ public void setWalletPassword(SetWalletPasswordRequest req, public void removeWalletPassword(RemoveWalletPasswordRequest req, StreamObserver responseObserver) { try { - walletsService.removeWalletPassword(req.getPassword()); + coreApi.removeWalletPassword(req.getPassword()); var reply = RemoveWalletPasswordReply.newBuilder().build(); responseObserver.onNext(reply); responseObserver.onCompleted(); @@ -109,7 +109,7 @@ public void removeWalletPassword(RemoveWalletPasswordRequest req, public void lockWallet(LockWalletRequest req, StreamObserver responseObserver) { try { - walletsService.lockWallet(); + coreApi.lockWallet(); var reply = LockWalletReply.newBuilder().build(); responseObserver.onNext(reply); responseObserver.onCompleted(); @@ -124,7 +124,7 @@ public void lockWallet(LockWalletRequest req, public void unlockWallet(UnlockWalletRequest req, StreamObserver responseObserver) { try { - walletsService.unlockWallet(req.getPassword(), req.getTimeout()); + coreApi.unlockWallet(req.getPassword(), req.getTimeout()); var reply = UnlockWalletReply.newBuilder().build(); responseObserver.onNext(reply); responseObserver.onCompleted(); diff --git a/proto/src/main/proto/grpc.proto b/proto/src/main/proto/grpc.proto index 66c4eb2ada8..1c7ca532b0a 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -124,10 +124,10 @@ message PlaceOfferReply { } /////////////////////////////////////////////////////////////////////////////////////////// -// Wallet +// Wallets /////////////////////////////////////////////////////////////////////////////////////////// -service Wallet { +service Wallets { rpc GetBalance (GetBalanceRequest) returns (GetBalanceReply) { } rpc GetAddressBalance (GetAddressBalanceRequest) returns (GetAddressBalanceReply) {