From 6e21508a942c68eae574dce250ee2350d2dc6396 Mon Sep 17 00:00:00 2001 From: woodser Date: Sat, 18 Sep 2021 15:27:18 -0400 Subject: [PATCH] add grpc call to get new deposit subaddress --- core/src/main/java/bisq/core/api/CoreApi.java | 4 ++++ .../java/bisq/core/api/CoreWalletsService.java | 8 ++++++++ .../bisq/daemon/grpc/GrpcWalletsService.java | 17 +++++++++++++++++ proto/src/main/proto/grpc.proto | 9 +++++++++ 4 files changed, 38 insertions(+) diff --git a/core/src/main/java/bisq/core/api/CoreApi.java b/core/src/main/java/bisq/core/api/CoreApi.java index fe5bbceba5..20261a5b2e 100644 --- a/core/src/main/java/bisq/core/api/CoreApi.java +++ b/core/src/main/java/bisq/core/api/CoreApi.java @@ -280,6 +280,10 @@ public class CoreApi { public BalancesInfo getBalances(String currencyCode) { return walletsService.getBalances(currencyCode); } + + public String getNewDepositSubaddress() { + return walletsService.getNewDepositSubaddress(); + } public long getAddressBalance(String addressString) { return walletsService.getAddressBalance(addressString); diff --git a/core/src/main/java/bisq/core/api/CoreWalletsService.java b/core/src/main/java/bisq/core/api/CoreWalletsService.java index f05d8b6f35..8a096ee1df 100644 --- a/core/src/main/java/bisq/core/api/CoreWalletsService.java +++ b/core/src/main/java/bisq/core/api/CoreWalletsService.java @@ -38,6 +38,7 @@ import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.TxBroadcaster; import bisq.core.btc.wallet.WalletsManager; +import bisq.core.btc.wallet.XmrWalletService; import bisq.core.provider.fee.FeeService; import bisq.core.user.Preferences; import bisq.core.util.FormattingUtils; @@ -103,6 +104,7 @@ class CoreWalletsService { private final BsqTransferService bsqTransferService; private final BsqFormatter bsqFormatter; private final BtcWalletService btcWalletService; + private final XmrWalletService xmrWalletService; private final CoinFormatter btcFormatter; private final FeeService feeService; private final Preferences preferences; @@ -125,6 +127,7 @@ class CoreWalletsService { BsqTransferService bsqTransferService, BsqFormatter bsqFormatter, BtcWalletService btcWalletService, + XmrWalletService xmrWalletService, @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter btcFormatter, FeeService feeService, Preferences preferences) { @@ -137,6 +140,7 @@ class CoreWalletsService { this.bsqTransferService = bsqTransferService; this.bsqFormatter = bsqFormatter; this.btcWalletService = btcWalletService; + this.xmrWalletService = xmrWalletService; this.btcFormatter = btcFormatter; this.feeService = feeService; this.preferences = preferences; @@ -170,6 +174,10 @@ class CoreWalletsService { return new BalancesInfo(getBsqBalances(), getBtcBalances(), getXmrBalances()); } } + + String getNewDepositSubaddress() { + return xmrWalletService.getWallet().createSubaddress(0).getAddress(); + } long getAddressBalance(String addressString) { Address address = getAddressEntry(addressString).getAddress(); diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcWalletsService.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcWalletsService.java index 3f1b07e9e8..7619e7dc01 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcWalletsService.java +++ b/daemon/src/main/java/bisq/daemon/grpc/GrpcWalletsService.java @@ -29,6 +29,8 @@ import bisq.proto.grpc.GetBalancesReply; import bisq.proto.grpc.GetBalancesRequest; import bisq.proto.grpc.GetFundingAddressesReply; import bisq.proto.grpc.GetFundingAddressesRequest; +import bisq.proto.grpc.GetNewDepositSubaddressRequest; +import bisq.proto.grpc.GetNewDepositSubaddressReply; import bisq.proto.grpc.GetTransactionReply; import bisq.proto.grpc.GetTransactionRequest; import bisq.proto.grpc.GetTxFeeRateReply; @@ -108,6 +110,21 @@ class GrpcWalletsService extends WalletsImplBase { exceptionHandler.handleException(log, cause, responseObserver); } } + + @Override + public void getNewDepositSubaddress(GetNewDepositSubaddressRequest req, + StreamObserver responseObserver) { + try { + String subaddress = coreApi.getNewDepositSubaddress(); + var reply = GetNewDepositSubaddressReply.newBuilder() + .setSubaddress(subaddress) + .build(); + responseObserver.onNext(reply); + responseObserver.onCompleted(); + } catch (Throwable cause) { + exceptionHandler.handleException(log, cause, responseObserver); + } + } @Override public void getAddressBalance(GetAddressBalanceRequest req, diff --git a/proto/src/main/proto/grpc.proto b/proto/src/main/proto/grpc.proto index 57fcc7217d..13a82856f5 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -431,6 +431,8 @@ message TxInfo { service Wallets { rpc GetBalances (GetBalancesRequest) returns (GetBalancesReply) { } + rpc GetNewDepositSubaddress (GetNewDepositSubaddressRequest) returns (GetNewDepositSubaddressReply) { + } rpc GetAddressBalance (GetAddressBalanceRequest) returns (GetAddressBalanceReply) { } rpc GetUnusedBsqAddress (GetUnusedBsqAddressRequest) returns (GetUnusedBsqAddressReply) { @@ -469,6 +471,13 @@ message GetBalancesReply { BalancesInfo balances = 1; } +message GetNewDepositSubaddressRequest { +} + +message GetNewDepositSubaddressReply { + string subaddress = 1; +} + message GetAddressBalanceRequest { string address = 1; }