Skip to content

Commit

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

- Enable confirmpaymentsent method tests
  • Loading branch information
ghubstan committed Oct 20, 2020
1 parent e809af3 commit 3d2b90f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public void testTakeAlicesBuyOffer() {
}
}

@Disabled
@Test
@Order(2)
public void testAlicesConfirmPaymentStarted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public void testTakeAlicesSellOffer() {
}
}

@Disabled
@Test
@Order(2)
public void testBobsConfirmPaymentStarted() {
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.ConfirmPaymentStartedRequest;
import bisq.proto.grpc.CreateOfferRequest;
import bisq.proto.grpc.CreatePaymentAccountRequest;
import bisq.proto.grpc.GetAddressBalanceRequest;
Expand Down Expand Up @@ -72,6 +73,7 @@ private enum Method {
getoffer,
getoffers,
takeoffer,
confirmpaymentstarted,
createpaymentacct,
getpaymentaccts,
getversion,
Expand Down Expand Up @@ -271,6 +273,18 @@ public static void run(String[] args) {
out.printf("trade '%s' successfully taken", reply.getTrade().getShortId());
return;
}
case confirmpaymentstarted: {
if (nonOptionArgs.size() < 2)
throw new IllegalArgumentException("incorrect parameter count, expecting trade id");

var tradeId = nonOptionArgs.get(1);
var request = ConfirmPaymentStartedRequest.newBuilder()
.setTradeId(tradeId)
.build();
tradesService.confirmPaymentStarted(request);
out.printf("trade '%s' payment started message sent", tradeId);
return;
}
case createpaymentacct: {
if (nonOptionArgs.size() < 5)
throw new IllegalArgumentException(
Expand Down Expand Up @@ -399,6 +413,7 @@ private static void printHelp(OptionParser parser, PrintStream stream) {
stream.format(rowFormat, "getoffer", "offer id", "Get current offer with id");
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, "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 @@ -181,6 +181,10 @@ public void takeOffer(String offerId,
resultHandler);
}

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

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

import javax.inject.Inject;
Expand Down Expand Up @@ -79,6 +80,21 @@ void takeOffer(Offer offer,
);
}

void confirmPaymentStarted(String tradeId) {
var trade = getTradeWithId(tradeId);
if (isFollowingBuyerProtocol(trade)) {
var tradeProtocol = tradeManager.getTradeProtocol(trade);
((BuyerProtocol) tradeProtocol).onPaymentStarted(
() -> {
},
errorMessage -> {
throw new IllegalStateException(errorMessage);
}
);
} else {
throw new IllegalStateException("you are the seller and not sending payment");
}
}

Trade getTrade(String tradeId) {
return getTradeWithId(tradeId);
Expand All @@ -88,4 +104,8 @@ private Trade getTradeWithId(String tradeId) {
return tradeManager.getTradeById(tradeId).orElseThrow(() ->
new IllegalArgumentException(format("trade with id '%s' not found", tradeId)));
}

private boolean isFollowingBuyerProtocol(Trade trade) {
return tradeManager.getTradeProtocol(trade) instanceof BuyerProtocol;
}
}
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.ConfirmPaymentStartedReply;
import bisq.proto.grpc.ConfirmPaymentStartedRequest;
import bisq.proto.grpc.GetTradeReply;
import bisq.proto.grpc.GetTradeRequest;
import bisq.proto.grpc.TakeOfferReply;
Expand Down Expand Up @@ -84,4 +86,19 @@ public void takeOffer(TakeOfferRequest req,
throw ex;
}
}

@Override
public void confirmPaymentStarted(ConfirmPaymentStartedRequest req,
StreamObserver<ConfirmPaymentStartedReply> responseObserver) {
try {
coreApi.confirmPaymentStarted(req.getTradeId());
var reply = ConfirmPaymentStartedReply.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 3d2b90f

Please sign in to comment.