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

Add api method 'getpaymentmethods' #4818

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fc8af8c
Define new grpc bsq/btc balances protos
ghubstan Nov 13, 2020
faf45ec
Add proto wrappers for serving bsq, btc or all balances
ghubstan Nov 13, 2020
4c03b46
Define proto for api method 'getunusedbsqaddress'
ghubstan Nov 13, 2020
3e98910
Define proto fapi method 'sendbsq'
ghubstan Nov 13, 2020
9f033ee
Add proto fields to support trade fee currency choice
ghubstan Nov 13, 2020
c1c099c
Implement and test api method 'getunusedbsqaddress'
ghubstan Nov 13, 2020
7c2068e
Add teardown to test case
ghubstan Nov 13, 2020
8dc1a74
Remove trailing spaces in blank line
ghubstan Nov 13, 2020
208a37b
Implement and test new getbalance(s) api methods
ghubstan Nov 13, 2020
7f0f949
Resolve unnecessary use of fully qualified name for codacy
ghubstan Nov 13, 2020
0d3b3a6
Stub out api method 'sendbsq' in core
ghubstan Nov 13, 2020
dc3274f
Re comment sendbsq tests so travis ci does not fail
ghubstan Nov 13, 2020
446bd32
Refactor desktop's BsqSendView, share with api
ghubstan Nov 13, 2020
4a90b40
Resolve 'Avoid creating BigDecimal with a decimal' issue for codacy
ghubstan Nov 13, 2020
722460e
Support paying trade fees in bsq or btc (api)
ghubstan Nov 13, 2020
8157f8f
Delete deprecated api test, adjust api build/run doc
ghubstan Nov 13, 2020
7e9ab22
Refactor api getbalance methods.
ghubstan Nov 14, 2020
187a85f
Fix typo
ghubstan Nov 14, 2020
34efc04
Remove unnecessary fully qualified name
ghubstan Nov 14, 2020
530a9f9
Remove unused imports
ghubstan Nov 14, 2020
ec38152
Add api method 'getpaymentmethods'
ghubstan Nov 18, 2020
a465261
Avoid codacy issue over use of fully qualified name
ghubstan Nov 18, 2020
0046b08
Revert "Avoid codacy issue over use of fully qualified name"
ghubstan Nov 18, 2020
7a7d5ba
Print the payment method id (only)
ghubstan Nov 18, 2020
0e0af20
Avoid codacy issue over use of fully qualified name
ghubstan Nov 18, 2020
7d0648a
Make codacy happy again
ghubstan Nov 18, 2020
773ef63
Resolve BsqSendView file conflict
ghubstan Nov 26, 2020
04b0cb6
Merge branch 'master' into 13-getpaymentmethods
ghubstan Nov 26, 2020
ef16bc2
Adjust to changed CoinUtil
ghubstan Nov 26, 2020
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
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);
ghubstan marked this conversation as resolved.
Show resolved Hide resolved
}

@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(p -> out.println(p.getId()));
}
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> getFiatPaymentMethods() {
return paymentAccountsService.getFiatPaymentMethods();
}

///////////////////////////////////////////////////////////////////////////////////////////
// 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> getFiatPaymentMethods() {
return 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.getFiatPaymentMethods().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