Skip to content

Commit

Permalink
Add api method 'getpaymentmethods'
Browse files Browse the repository at this point in the history
Returns a list of supported payment method IDs.  This gives CLI users
the correct payment method id for creating a new payment account.

- Added gRPC service GetPaymentMethods to grpc.proto.

- Added gRPC boilerplate method to GrpcPaymentAccountsService.

- Added implimentation to CoreApi -> CorePaymentAccountsService.

- Refactored PaymentAccountTest hierarchy.

- Add api method to CLI.
  • Loading branch information
ghubstan committed Nov 18, 2020
1 parent 530a9f9 commit ec38152
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 9 deletions.
8 changes: 8 additions & 0 deletions apitest/src/test/java/bisq/apitest/method/MethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand All @@ -46,7 +47,9 @@
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;
Expand Down Expand Up @@ -244,6 +247,11 @@ protected final String getUnusedBtcAddress(BisqAppConfig bisqAppConfig) {
.getAddress();
}

protected final List<PaymentMethod> getPaymentMethods(BisqAppConfig bisqAppConfig) {
var req = GetPaymentMethodsRequest.newBuilder().build();
return grpcStubs(bisqAppConfig).paymentAccountsService.getPaymentMethods(req).getPaymentMethodsList();
}

protected final CreatePaymentAccountRequest createCreatePerfectMoneyPaymentAccountRequest(
String accountName,
String accountNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.apitest.method;
package bisq.apitest.method.payment;

import bisq.proto.grpc.GetPaymentAccountsRequest;

Expand All @@ -41,6 +41,10 @@
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> paymentMethodIds = getPaymentMethods(alicedaemon)
.stream()
.map(p -> p.getId())
.collect(Collectors.toList());
assertTrue(paymentMethodIds.size() > 25);
}

@AfterAll
public static void tearDown() {
tearDownScaffold();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}

}
8 changes: 0 additions & 8 deletions apitest/src/test/java/bisq/apitest/scenario/StartupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@



import bisq.apitest.method.CreatePaymentAccountTest;
import bisq.apitest.method.GetVersionTest;
import bisq.apitest.method.MethodTest;
import bisq.apitest.method.RegisterDisputeAgentsTest;
Expand Down Expand Up @@ -71,13 +70,6 @@ public void testRegisterDisputeAgents() {
test.testRegisterRefundAgent();
}

@Test
@Order(3)
public void testCreatePaymentAccount() {
CreatePaymentAccountTest test = new CreatePaymentAccountTest();
test.testCreatePerfectMoneyUSDPaymentAccount();
}

@AfterAll
public static void tearDown() {
tearDownScaffold();
Expand Down
8 changes: 8 additions & 0 deletions cli/src/main/java/bisq/cli/CliMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -86,6 +87,7 @@ private enum Method {
confirmpaymentreceived,
keepfunds,
withdrawfunds,
getpaymentmethods,
createpaymentacct,
getpaymentaccts,
getversion,
Expand Down Expand Up @@ -416,6 +418,11 @@ public static void run(String[] args) {
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(
Expand Down Expand Up @@ -552,6 +559,7 @@ private static void printHelp(OptionParser parser, PrintStream stream) {
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");
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/bisq/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -168,6 +169,10 @@ public Set<PaymentAccount> getPaymentAccounts() {
return paymentAccountsService.getPaymentAccounts();
}

public List<PaymentMethod> getPaymentMethods() {
return paymentAccountsService.getPaymentMethods();
}

///////////////////////////////////////////////////////////////////////////////////////////
// Prices
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/bisq/core/api/CorePaymentAccountsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@

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;

Expand Down Expand Up @@ -75,6 +78,13 @@ Set<PaymentAccount> getPaymentAccounts() {
return user.getPaymentAccounts();
}

List<PaymentMethod> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@

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;
Expand Down Expand Up @@ -65,4 +68,16 @@ public void getPaymentAccounts(GetPaymentAccountsRequest req,
responseObserver.onNext(reply);
responseObserver.onCompleted();
}

@Override
public void getPaymentMethods(GetPaymentMethodsRequest req,
StreamObserver<GetPaymentMethodsReply> responseObserver) {
var paymentMethods = coreApi.getPaymentMethods().stream()
.map(PaymentMethod::toProtoMessage)
.collect(Collectors.toList());
var reply = GetPaymentMethodsReply.newBuilder()
.addAllPaymentMethods(paymentMethods).build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
}
}
9 changes: 9 additions & 0 deletions proto/src/main/proto/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ service PaymentAccounts {
}
rpc GetPaymentAccounts (GetPaymentAccountsRequest) returns (GetPaymentAccountsReply) {
}
rpc GetPaymentMethods (GetPaymentMethodsRequest) returns (GetPaymentMethodsReply) {
}
}

message CreatePaymentAccountRequest {
Expand All @@ -145,6 +147,13 @@ message GetPaymentAccountsReply {
repeated PaymentAccount paymentAccounts = 1;
}

message GetPaymentMethodsRequest {
}

message GetPaymentMethodsReply {
repeated PaymentMethod paymentMethods = 1;
}

///////////////////////////////////////////////////////////////////////////////////////////
// Price
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit ec38152

Please sign in to comment.