Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return protos from funding address methods #4324

Merged
merged 15 commits into from
Jun 25, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add rpc method 'getaddressbalance'
This addresses task 2 in issue 4257
	#4257

This new gRPC Wallet service method displays the balance and number
of confimirmations of the most recent transaction for the given BTC
wallet address.

The new method required the usual boilerplate changes to grpc.proto,
CliMain, and GrpcWalletService.

Two unit tests to check error msgs was added to cli/test.sh.
ghubstan committed Jun 14, 2020
commit b1228e5ea72211c9010943db1aa8bf46675417a6
13 changes: 13 additions & 0 deletions cli/src/main/java/bisq/cli/CliMain.java
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@

package bisq.cli;

import bisq.proto.grpc.GetAddressBalanceRequest;
import bisq.proto.grpc.GetBalanceRequest;
import bisq.proto.grpc.GetFundingAddressesRequest;
import bisq.proto.grpc.GetVersionGrpc;
@@ -59,6 +60,7 @@ public class CliMain {
private enum Method {
getversion,
getbalance,
getaddressbalance,
getfundingaddresses,
lockwallet,
unlockwallet,
@@ -154,6 +156,16 @@ public static void run(String[] args) {
out.println(btcBalance);
return;
}
case getaddressbalance: {
if (nonOptionArgs.size() < 2)
throw new IllegalArgumentException("no address specified");

var request = GetAddressBalanceRequest.newBuilder()
.setAddress(nonOptionArgs.get(1)).build();
var reply = walletService.getAddressBalance(request);
out.println(reply.getAddressBalanceInfo());
return;
}
case getfundingaddresses: {
var request = GetFundingAddressesRequest.newBuilder().build();
var reply = walletService.getFundingAddresses(request);
@@ -230,6 +242,7 @@ private static void printHelp(OptionParser parser, PrintStream stream) {
stream.format("%-19s%-30s%s%n", "------", "------", "------------");
stream.format("%-19s%-30s%s%n", "getversion", "", "Get server version");
stream.format("%-19s%-30s%s%n", "getbalance", "", "Get server wallet balance");
stream.format("%-19s%-30s%s%n", "getaddressbalance", "", "Get server wallet address balance");
stream.format("%-19s%-30s%s%n", "getfundingaddresses", "", "Get BTC funding addresses");
stream.format("%-19s%-30s%s%n", "lockwallet", "", "Remove wallet password from memory, locking the wallet");
stream.format("%-19s%-30s%s%n", "unlockwallet", "password timeout",
14 changes: 14 additions & 0 deletions cli/test.sh
Original file line number Diff line number Diff line change
@@ -152,6 +152,20 @@
[ "$status" -eq 0 ]
}

@test "test getaddressbalance missing address argument" {
run ./bisq-cli --password=xyz getaddressbalance
[ "$status" -eq 1 ]
echo "actual output: $output" >&2
[ "$output" = "Error: no address specified" ]
}

@test "test getaddressbalance bogus address argument" {
run ./bisq-cli --password=xyz getaddressbalance bogus
[ "$status" -eq 1 ]
echo "actual output: $output" >&2
[ "$output" = "Error: address bogus not found in wallet" ]
}

@test "test help displayed on stderr if no options or arguments" {
run ./bisq-cli
[ "$status" -eq 1 ]
9 changes: 9 additions & 0 deletions core/src/main/java/bisq/core/grpc/CoreWalletsService.java
Original file line number Diff line number Diff line change
@@ -80,6 +80,15 @@ public long getAddressBalance(String addressString) {
return btcWalletService.getBalanceForAddress(address).value;
}

public String getAddressBalanceInfo(String addressString) {
var satoshiBalance = getAddressBalance(addressString);
var btcBalance = formatSatoshis.apply(satoshiBalance);
var numConfirmations = getNumConfirmationsForMostRecentTransaction(addressString);
return addressString
+ " balance: " + format("%13s", btcBalance)
+ ((numConfirmations > 0) ? (" confirmations: " + format("%6d", numConfirmations)) : "");
}

public String getFundingAddresses() {
if (!walletsManager.areWalletsAvailable())
throw new IllegalStateException("wallet is not yet available");
19 changes: 18 additions & 1 deletion core/src/main/java/bisq/core/grpc/GrpcWalletService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bisq.core.grpc;

import bisq.proto.grpc.GetAddressBalanceReply;
import bisq.proto.grpc.GetAddressBalanceRequest;
import bisq.proto.grpc.GetBalanceReply;
import bisq.proto.grpc.GetBalanceRequest;
import bisq.proto.grpc.GetFundingAddressesReply;
@@ -42,7 +44,22 @@ public void getBalance(GetBalanceRequest req, StreamObserver<GetBalanceReply> re
throw ex;
}
}


@Override
public void getAddressBalance(GetAddressBalanceRequest req,
StreamObserver<GetAddressBalanceReply> responseObserver) {
try {
String result = walletsService.getAddressBalanceInfo(req.getAddress());
var reply = GetAddressBalanceReply.newBuilder().setAddressBalanceInfo(result).build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
} catch (IllegalStateException cause) {
var ex = new StatusRuntimeException(Status.UNKNOWN.withDescription(cause.getMessage()));
responseObserver.onError(ex);
throw ex;
}
}

@Override
public void getFundingAddresses(GetFundingAddressesRequest req,
StreamObserver<GetFundingAddressesReply> responseObserver) {
10 changes: 10 additions & 0 deletions proto/src/main/proto/grpc.proto
Original file line number Diff line number Diff line change
@@ -119,6 +119,8 @@ message PlaceOfferReply {
service Wallet {
rpc GetBalance (GetBalanceRequest) returns (GetBalanceReply) {
}
rpc GetAddressBalance (GetAddressBalanceRequest) returns (GetAddressBalanceReply) {
}
rpc GetFundingAddresses (GetFundingAddressesRequest) returns (GetFundingAddressesReply) {
}
rpc SetWalletPassword (SetWalletPasswordRequest) returns (SetWalletPasswordReply) {
@@ -138,6 +140,14 @@ message GetBalanceReply {
uint64 balance = 1;
}

message GetAddressBalanceRequest {
string address = 1;
}

message GetAddressBalanceReply {
string addressBalanceInfo = 1;
}

message GetFundingAddressesRequest {
}