diff --git a/apitest/src/test/java/bisq/apitest/method/MethodTest.java b/apitest/src/test/java/bisq/apitest/method/MethodTest.java index 72634b1678..34fbeffbc5 100644 --- a/apitest/src/test/java/bisq/apitest/method/MethodTest.java +++ b/apitest/src/test/java/bisq/apitest/method/MethodTest.java @@ -30,6 +30,7 @@ import bisq.proto.grpc.GetBalancesRequest; import bisq.proto.grpc.GetFundingAddressesRequest; import bisq.proto.grpc.GetOfferRequest; import bisq.proto.grpc.GetPaymentAccountsRequest; +import bisq.proto.grpc.GetPaymentMethodsRequest; import bisq.proto.grpc.GetTradeRequest; import bisq.proto.grpc.GetUnusedBsqAddressRequest; import bisq.proto.grpc.KeepFundsRequest; @@ -46,7 +47,9 @@ import bisq.proto.grpc.UnlockWalletRequest; import bisq.proto.grpc.WithdrawFundsRequest; import protobuf.PaymentAccount; +import protobuf.PaymentMethod; +import java.util.List; import java.util.stream.Collectors; import static bisq.apitest.config.BisqAppConfig.alicedaemon; @@ -244,6 +247,11 @@ public class MethodTest extends ApiTestCase { .getAddress(); } + protected final List getPaymentMethods(BisqAppConfig bisqAppConfig) { + var req = GetPaymentMethodsRequest.newBuilder().build(); + return grpcStubs(bisqAppConfig).paymentAccountsService.getPaymentMethods(req).getPaymentMethodsList(); + } + protected final CreatePaymentAccountRequest createCreatePerfectMoneyPaymentAccountRequest( String accountName, String accountNumber, diff --git a/apitest/src/test/java/bisq/apitest/method/CreatePaymentAccountTest.java b/apitest/src/test/java/bisq/apitest/method/payment/CreatePaymentAccountTest.java similarity index 97% rename from apitest/src/test/java/bisq/apitest/method/CreatePaymentAccountTest.java rename to apitest/src/test/java/bisq/apitest/method/payment/CreatePaymentAccountTest.java index 9e8b0af878..83e827834e 100644 --- a/apitest/src/test/java/bisq/apitest/method/CreatePaymentAccountTest.java +++ b/apitest/src/test/java/bisq/apitest/method/payment/CreatePaymentAccountTest.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.apitest.method; +package bisq.apitest.method.payment; import bisq.proto.grpc.GetPaymentAccountsRequest; @@ -41,6 +41,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.MethodOrderer.OrderAnnotation; + + +import bisq.apitest.method.MethodTest; + @Disabled @Slf4j @TestMethodOrder(OrderAnnotation.class) diff --git a/apitest/src/test/java/bisq/apitest/method/payment/GetPaymentMethodsTest.java b/apitest/src/test/java/bisq/apitest/method/payment/GetPaymentMethodsTest.java new file mode 100644 index 0000000000..acd791f596 --- /dev/null +++ b/apitest/src/test/java/bisq/apitest/method/payment/GetPaymentMethodsTest.java @@ -0,0 +1,53 @@ +package bisq.apitest.method.payment; + +import java.util.List; +import java.util.stream.Collectors; + +import lombok.extern.slf4j.Slf4j; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import static bisq.apitest.Scaffold.BitcoinCoreApp.bitcoind; +import static bisq.apitest.config.BisqAppConfig.alicedaemon; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + + + +import bisq.apitest.method.MethodTest; + +@Disabled +@Slf4j +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class GetPaymentMethodsTest extends MethodTest { + + @BeforeAll + public static void setUp() { + try { + setUpScaffold(bitcoind, alicedaemon); + } catch (Exception ex) { + fail(ex); + } + } + + @Test + @Order(1) + public void testGetPaymentMethods() { + List paymentMethodIds = getPaymentMethods(alicedaemon) + .stream() + .map(p -> p.getId()) + .collect(Collectors.toList()); + assertTrue(paymentMethodIds.size() > 25); + } + + @AfterAll + public static void tearDown() { + tearDownScaffold(); + } +} diff --git a/apitest/src/test/java/bisq/apitest/scenario/PaymentAccountTest.java b/apitest/src/test/java/bisq/apitest/scenario/PaymentAccountTest.java new file mode 100644 index 0000000000..af36eba27c --- /dev/null +++ b/apitest/src/test/java/bisq/apitest/scenario/PaymentAccountTest.java @@ -0,0 +1,56 @@ +package bisq.apitest.scenario; + +import lombok.extern.slf4j.Slf4j; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import static bisq.apitest.Scaffold.BitcoinCoreApp.bitcoind; +import static bisq.apitest.config.BisqAppConfig.alicedaemon; +import static bisq.apitest.config.BisqAppConfig.arbdaemon; +import static bisq.apitest.config.BisqAppConfig.seednode; +import static org.junit.jupiter.api.Assertions.fail; + + + +import bisq.apitest.method.MethodTest; +import bisq.apitest.method.payment.CreatePaymentAccountTest; +import bisq.apitest.method.payment.GetPaymentMethodsTest; + +@Slf4j +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class PaymentAccountTest extends MethodTest { + + @BeforeAll + public static void setUp() { + try { + setUpScaffold(bitcoind, seednode, arbdaemon, alicedaemon); + } catch (Exception ex) { + fail(ex); + } + } + + @Test + @Order(1) + public void testGetPaymentMethods() { + GetPaymentMethodsTest test = new GetPaymentMethodsTest(); + test.testGetPaymentMethods(); + } + + @Test + @Order(2) + public void testCreatePaymentAccount() { + CreatePaymentAccountTest test = new CreatePaymentAccountTest(); + test.testCreatePerfectMoneyUSDPaymentAccount(); + } + + @AfterAll + public static void tearDown() { + tearDownScaffold(); + } + +} diff --git a/apitest/src/test/java/bisq/apitest/scenario/StartupTest.java b/apitest/src/test/java/bisq/apitest/scenario/StartupTest.java index fa81ddff6b..26a95f3c77 100644 --- a/apitest/src/test/java/bisq/apitest/scenario/StartupTest.java +++ b/apitest/src/test/java/bisq/apitest/scenario/StartupTest.java @@ -34,7 +34,6 @@ import static org.junit.jupiter.api.Assertions.fail; -import bisq.apitest.method.CreatePaymentAccountTest; import bisq.apitest.method.GetVersionTest; import bisq.apitest.method.MethodTest; import bisq.apitest.method.RegisterDisputeAgentsTest; @@ -71,13 +70,6 @@ public class StartupTest extends MethodTest { test.testRegisterRefundAgent(); } - @Test - @Order(3) - public void testCreatePaymentAccount() { - CreatePaymentAccountTest test = new CreatePaymentAccountTest(); - test.testCreatePerfectMoneyUSDPaymentAccount(); - } - @AfterAll public static void tearDown() { tearDownScaffold(); diff --git a/cli/src/main/java/bisq/cli/CliMain.java b/cli/src/main/java/bisq/cli/CliMain.java index efc03fc310..188a937288 100644 --- a/cli/src/main/java/bisq/cli/CliMain.java +++ b/cli/src/main/java/bisq/cli/CliMain.java @@ -28,6 +28,7 @@ import bisq.proto.grpc.GetFundingAddressesRequest; import bisq.proto.grpc.GetOfferRequest; import bisq.proto.grpc.GetOffersRequest; import bisq.proto.grpc.GetPaymentAccountsRequest; +import bisq.proto.grpc.GetPaymentMethodsRequest; import bisq.proto.grpc.GetTradeRequest; import bisq.proto.grpc.GetUnusedBsqAddressRequest; import bisq.proto.grpc.GetVersionRequest; @@ -86,6 +87,7 @@ public class CliMain { confirmpaymentreceived, keepfunds, withdrawfunds, + getpaymentmethods, createpaymentacct, getpaymentaccts, getversion, @@ -416,6 +418,11 @@ public class CliMain { out.printf("funds from trade '%s' sent to btc address '%s'", tradeId, address); return; } + case getpaymentmethods: { + var request = GetPaymentMethodsRequest.newBuilder().build(); + var reply = paymentAccountsService.getPaymentMethods(request); + reply.getPaymentMethodsList().forEach(out::println); + } case createpaymentacct: { if (nonOptionArgs.size() < 5) throw new IllegalArgumentException( @@ -552,6 +559,7 @@ public class CliMain { stream.format(rowFormat, "confirmpaymentreceived", "trade id", "Confirm payment received"); stream.format(rowFormat, "keepfunds", "trade id", "Keep received funds in Bisq wallet"); stream.format(rowFormat, "withdrawfunds", "trade id, bitcoin wallet address", "Withdraw received funds to external wallet address"); + stream.format(rowFormat, "getpaymentmethods", "", "Get list of supported payment account method ids"); stream.format(rowFormat, "createpaymentacct", "account name, account number, currency code", "Create PerfectMoney dummy account"); stream.format(rowFormat, "getpaymentaccts", "", "Get user payment accounts"); stream.format(rowFormat, "lockwallet", "", "Remove wallet password from memory, locking the wallet"); diff --git a/core/src/main/java/bisq/core/api/CoreApi.java b/core/src/main/java/bisq/core/api/CoreApi.java index cd5ce5b53f..cc50da2acd 100644 --- a/core/src/main/java/bisq/core/api/CoreApi.java +++ b/core/src/main/java/bisq/core/api/CoreApi.java @@ -24,6 +24,7 @@ import bisq.core.monetary.Price; import bisq.core.offer.Offer; import bisq.core.offer.OfferPayload; import bisq.core.payment.PaymentAccount; +import bisq.core.payment.payload.PaymentMethod; import bisq.core.trade.Trade; import bisq.core.trade.statistics.TradeStatistics3; import bisq.core.trade.statistics.TradeStatisticsManager; @@ -168,6 +169,10 @@ public class CoreApi { return paymentAccountsService.getPaymentAccounts(); } + public List getPaymentMethods() { + return paymentAccountsService.getPaymentMethods(); + } + /////////////////////////////////////////////////////////////////////////////////////////// // Prices /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/main/java/bisq/core/api/CorePaymentAccountsService.java b/core/src/main/java/bisq/core/api/CorePaymentAccountsService.java index a202b0dbdb..8d8dc3f42a 100644 --- a/core/src/main/java/bisq/core/api/CorePaymentAccountsService.java +++ b/core/src/main/java/bisq/core/api/CorePaymentAccountsService.java @@ -29,7 +29,10 @@ import bisq.common.config.Config; import javax.inject.Inject; +import java.util.Comparator; +import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; @@ -75,6 +78,13 @@ class CorePaymentAccountsService { return user.getPaymentAccounts(); } + List getPaymentMethods() { + return PaymentMethod.getPaymentMethods().stream() + .filter(paymentMethod -> !paymentMethod.isAsset()) + .sorted(Comparator.comparing(PaymentMethod::getId)) + .collect(Collectors.toList()); + } + private PaymentAccount getNewPaymentAccount(String paymentMethodId, String accountName, String accountNumber, diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcPaymentAccountsService.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcPaymentAccountsService.java index 91060cbc82..64175f3d0f 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcPaymentAccountsService.java +++ b/daemon/src/main/java/bisq/daemon/grpc/GrpcPaymentAccountsService.java @@ -19,11 +19,14 @@ package bisq.daemon.grpc; import bisq.core.api.CoreApi; import bisq.core.payment.PaymentAccount; +import bisq.core.payment.payload.PaymentMethod; import bisq.proto.grpc.CreatePaymentAccountReply; import bisq.proto.grpc.CreatePaymentAccountRequest; import bisq.proto.grpc.GetPaymentAccountsReply; import bisq.proto.grpc.GetPaymentAccountsRequest; +import bisq.proto.grpc.GetPaymentMethodsReply; +import bisq.proto.grpc.GetPaymentMethodsRequest; import bisq.proto.grpc.PaymentAccountsGrpc; import io.grpc.stub.StreamObserver; @@ -65,4 +68,16 @@ class GrpcPaymentAccountsService extends PaymentAccountsGrpc.PaymentAccountsImpl responseObserver.onNext(reply); responseObserver.onCompleted(); } + + @Override + public void getPaymentMethods(GetPaymentMethodsRequest req, + StreamObserver responseObserver) { + var paymentMethods = coreApi.getPaymentMethods().stream() + .map(PaymentMethod::toProtoMessage) + .collect(Collectors.toList()); + var reply = GetPaymentMethodsReply.newBuilder() + .addAllPaymentMethods(paymentMethods).build(); + responseObserver.onNext(reply); + responseObserver.onCompleted(); + } } diff --git a/proto/src/main/proto/grpc.proto b/proto/src/main/proto/grpc.proto index 6dc0be30a5..b29ad979eb 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -125,6 +125,8 @@ service PaymentAccounts { } rpc GetPaymentAccounts (GetPaymentAccountsRequest) returns (GetPaymentAccountsReply) { } + rpc GetPaymentMethods (GetPaymentMethodsRequest) returns (GetPaymentMethodsReply) { + } } message CreatePaymentAccountRequest { @@ -145,6 +147,13 @@ message GetPaymentAccountsReply { repeated PaymentAccount paymentAccounts = 1; } +message GetPaymentMethodsRequest { +} + +message GetPaymentMethodsReply { + repeated PaymentMethod paymentMethods = 1; +} + /////////////////////////////////////////////////////////////////////////////////////////// // Price ///////////////////////////////////////////////////////////////////////////////////////////