Skip to content

Commit

Permalink
Add 'confirmpaymentreceived' api method
Browse files Browse the repository at this point in the history
- Implement confirmpaymentsent on server and cli side

- Enable confirmpaymentreceived method tests
  • Loading branch information
ghubstan committed Oct 20, 2020
1 parent 3d2b90f commit ac8ed8d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import lombok.extern.slf4j.Slf4j;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -113,7 +112,6 @@ public void testAlicesConfirmPaymentStarted() {
}
}

@Disabled
@Test
@Order(3)
public void testBobsConfirmPaymentReceived() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import lombok.extern.slf4j.Slf4j;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -116,7 +115,6 @@ public void testBobsConfirmPaymentStarted() {
}
}

@Disabled
@Test
@Order(3)
public void testAlicesConfirmPaymentReceived() {
Expand Down
15 changes: 15 additions & 0 deletions cli/src/main/java/bisq/cli/CliMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package bisq.cli;

import bisq.proto.grpc.ConfirmPaymentReceivedRequest;
import bisq.proto.grpc.ConfirmPaymentStartedRequest;
import bisq.proto.grpc.CreateOfferRequest;
import bisq.proto.grpc.CreatePaymentAccountRequest;
Expand Down Expand Up @@ -74,6 +75,7 @@ private enum Method {
getoffers,
takeoffer,
confirmpaymentstarted,
confirmpaymentreceived,
createpaymentacct,
getpaymentaccts,
getversion,
Expand Down Expand Up @@ -285,6 +287,18 @@ public static void run(String[] args) {
out.printf("trade '%s' payment started message sent", tradeId);
return;
}
case confirmpaymentreceived: {
if (nonOptionArgs.size() < 2)
throw new IllegalArgumentException("incorrect parameter count, expecting trade id");

var tradeId = nonOptionArgs.get(1);
var request = ConfirmPaymentReceivedRequest.newBuilder()
.setTradeId(tradeId)
.build();
tradesService.confirmPaymentReceived(request);
out.printf("trade '%s' payment received message sent", tradeId);
return;
}
case createpaymentacct: {
if (nonOptionArgs.size() < 5)
throw new IllegalArgumentException(
Expand Down Expand Up @@ -414,6 +428,7 @@ private static void printHelp(OptionParser parser, PrintStream stream) {
stream.format(rowFormat, "getoffers", "buy | sell, currency code", "Get current offers");
stream.format(rowFormat, "takeoffer", "offer id", "Take offer with id");
stream.format(rowFormat, "confirmpaymentstarted", "trade id", "Confirm payment started");
stream.format(rowFormat, "confirmpaymentreceived", "trade id", "Confirm payment received");
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
4 changes: 4 additions & 0 deletions core/src/main/java/bisq/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ public void confirmPaymentStarted(String tradeId) {
coreTradesService.confirmPaymentStarted(tradeId);
}

public void confirmPaymentReceived(String tradeId) {
coreTradesService.confirmPaymentReceived(tradeId);
}

public Trade getTrade(String tradeId) {
return coreTradesService.getTrade(tradeId);
}
Expand Down
17 changes: 17 additions & 0 deletions core/src/main/java/bisq/core/api/CoreTradesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import bisq.core.trade.Trade;
import bisq.core.trade.TradeManager;
import bisq.core.trade.protocol.BuyerProtocol;
import bisq.core.trade.protocol.SellerProtocol;
import bisq.core.user.User;

import javax.inject.Inject;
Expand Down Expand Up @@ -96,6 +97,22 @@ void confirmPaymentStarted(String tradeId) {
}
}

void confirmPaymentReceived(String tradeId) {
var trade = getTradeWithId(tradeId);
if (isFollowingBuyerProtocol(trade)) {
throw new IllegalStateException("you are the buyer, and not receiving payment");
} else {
var tradeProtocol = tradeManager.getTradeProtocol(trade);
((SellerProtocol) tradeProtocol).onPaymentReceived(
() -> {
},
errorMessage -> {
throw new IllegalStateException(errorMessage);
}
);
}
}

Trade getTrade(String tradeId) {
return getTradeWithId(tradeId);
}
Expand Down
17 changes: 17 additions & 0 deletions daemon/src/main/java/bisq/daemon/grpc/GrpcTradesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import bisq.core.api.model.TradeInfo;
import bisq.core.trade.Trade;

import bisq.proto.grpc.ConfirmPaymentReceivedReply;
import bisq.proto.grpc.ConfirmPaymentReceivedRequest;
import bisq.proto.grpc.ConfirmPaymentStartedReply;
import bisq.proto.grpc.ConfirmPaymentStartedRequest;
import bisq.proto.grpc.GetTradeReply;
Expand Down Expand Up @@ -101,4 +103,19 @@ public void confirmPaymentStarted(ConfirmPaymentStartedRequest req,
throw ex;
}
}

@Override
public void confirmPaymentReceived(ConfirmPaymentReceivedRequest req,
StreamObserver<ConfirmPaymentReceivedReply> responseObserver) {
try {
coreApi.confirmPaymentReceived(req.getTradeId());
var reply = ConfirmPaymentReceivedReply.newBuilder().build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
} catch (IllegalStateException | IllegalArgumentException cause) {
var ex = new StatusRuntimeException(Status.UNKNOWN.withDescription(cause.getMessage()));
responseObserver.onError(ex);
throw ex;
}
}
}

0 comments on commit ac8ed8d

Please sign in to comment.