From 435672a5ee71b4988b22d41f7762303b59bc3a22 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Fri, 19 Jun 2020 12:45:04 -0300 Subject: [PATCH] Add rpc method 'getpaymentaccts' This addresses task 5 in issue 4257 https://github.com/bisq-network/bisq/issues/4257 This new gRPC PaymentAccounts service method displays the user's saved payment accounts. A unit test to check a successful return status code was added to cli/test.sh. This PR should be reviewed/merged after PR 4322. https://github.com/bisq-network/bisq/pull/4322 --- cli/src/main/java/bisq/cli/CliMain.java | 18 ++++++++++++++++++ cli/test.sh | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/cli/src/main/java/bisq/cli/CliMain.java b/cli/src/main/java/bisq/cli/CliMain.java index dee11cc7dd7..4f8b6f2d1be 100644 --- a/cli/src/main/java/bisq/cli/CliMain.java +++ b/cli/src/main/java/bisq/cli/CliMain.java @@ -21,6 +21,7 @@ import bisq.proto.grpc.GetAddressBalanceRequest; import bisq.proto.grpc.GetBalanceRequest; import bisq.proto.grpc.GetFundingAddressesRequest; +import bisq.proto.grpc.GetPaymentAccountsRequest; import bisq.proto.grpc.GetVersionGrpc; import bisq.proto.grpc.GetVersionRequest; import bisq.proto.grpc.LockWalletRequest; @@ -45,6 +46,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; @@ -61,6 +63,7 @@ public class CliMain { private enum Method { createpaymentacct, + getpaymentaccts, getversion, getbalance, getaddressbalance, @@ -200,6 +203,20 @@ public static void run(String[] args) { out.println(format("payment account %s saved", accountName)); return; } + case getpaymentaccts: { + var request = GetPaymentAccountsRequest.newBuilder().build(); + var reply = paymentAccountsService.getPaymentAccounts(request); + var columnFormatSpec = "%-41s %-25s %-14s %s"; + out.println(format(columnFormatSpec, "ID", "Name", "Currency", "Payment Method")); + out.println(reply.getPaymentAccountsList().stream() + .map(a -> format(columnFormatSpec, + a.getId(), + a.getAccountName(), + a.getSelectedTradeCurrency().getCode(), + a.getPaymentMethod().getId())) + .collect(Collectors.joining("\n"))); + return; + } case lockwallet: { var request = LockWalletRequest.newBuilder().build(); walletsService.lockWallet(request); @@ -273,6 +290,7 @@ private static void printHelp(OptionParser parser, PrintStream stream) { stream.format("%-22s%-50s%s%n", "getaddressbalance", "address", "Get server wallet address balance"); stream.format("%-22s%-50s%s%n", "getfundingaddresses", "", "Get BTC funding addresses"); stream.format("%-22s%-50s%s%n", "createpaymentacct", "account name, account number, currency code", "Create PerfectMoney dummy account"); + stream.format("%-22s%-50s%s%n", "getpaymentaccts", "", "Get user payment accounts"); stream.format("%-22s%-50s%s%n", "lockwallet", "", "Remove wallet password from memory, locking the wallet"); stream.format("%-22s%-50s%s%n", "unlockwallet", "password timeout", "Store wallet password in memory for timeout seconds"); diff --git a/cli/test.sh b/cli/test.sh index 79754d188bb..eaa64c9ebc8 100755 --- a/cli/test.sh +++ b/cli/test.sh @@ -171,6 +171,11 @@ [ "$status" -eq 0 ] } +@test "test getpaymentaccts" { + run ./bisq-cli --password=xyz getpaymentaccts + [ "$status" -eq 0 ] +} + @test "test help displayed on stderr if no options or arguments" { run ./bisq-cli [ "$status" -eq 1 ]