mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 06:55:08 +01:00
Add api method 'getpaymentmethods'
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.
This commit is contained in:
parent
530a9f95a4
commit
ec381522ff
10 changed files with 169 additions and 9 deletions
|
@ -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<PaymentMethod> getPaymentMethods(BisqAppConfig bisqAppConfig) {
|
||||
var req = GetPaymentMethodsRequest.newBuilder().build();
|
||||
return grpcStubs(bisqAppConfig).paymentAccountsService.getPaymentMethods(req).getPaymentMethodsList();
|
||||
}
|
||||
|
||||
protected final CreatePaymentAccountRequest createCreatePerfectMoneyPaymentAccountRequest(
|
||||
String accountName,
|
||||
String accountNumber,
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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)
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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<PaymentMethod> getPaymentMethods() {
|
||||
return paymentAccountsService.getPaymentMethods();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Prices
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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<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,
|
||||
|
|
|
@ -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<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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Reference in a new issue