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 for payment started with XMR auto conf params #7036

Merged
merged 1 commit into from Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions cli/src/main/java/bisq/cli/CliMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,19 @@ public static void run(String[] args) {
out.printf("trade %s payment started message sent%n", tradeId);
return;
}
case confirmpaymentstartedxmr: {
var opts = new GetTradeOptionParser(args).parse();
if (opts.isForHelp()) {
out.println(client.getMethodHelp(method));
return;
}
var tradeId = opts.getTradeId();
var txId = opts.getTxId();
var txKey = opts.getTxKey();
client.confirmPaymentStartedXmr(tradeId, txId, txKey);
out.printf("trade %s payment started message sent%n", tradeId);
return;
}
case confirmpaymentreceived: {
var opts = new GetTradeOptionParser(args).parse();
if (opts.isForHelp()) {
Expand Down
3 changes: 3 additions & 0 deletions cli/src/main/java/bisq/cli/GrpcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ public List<TradeInfo> getTradeHistory(GetTradesRequest.Category category) {
public void confirmPaymentStarted(String tradeId) {
tradesServiceRequest.confirmPaymentStarted(tradeId);
}
public void confirmPaymentStartedXmr(String tradeId, String txId, String txKey) {
tradesServiceRequest.confirmPaymentStartedXmr(tradeId, txId, txKey);
}

public void confirmPaymentReceived(String tradeId) {
tradesServiceRequest.confirmPaymentReceived(tradeId);
Expand Down
3 changes: 2 additions & 1 deletion cli/src/main/java/bisq/cli/Method.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ public enum Method {
unsettxfeerate,
withdrawfunds,
stop,
getdaostatus
getdaostatus,
confirmpaymentstartedxmr
}
18 changes: 18 additions & 0 deletions cli/src/main/java/bisq/cli/opts/GetTradeOptionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import static bisq.cli.opts.OptLabel.OPT_SHOW_CONTRACT;
import static bisq.cli.opts.OptLabel.OPT_TRADE_ID;
import static bisq.cli.opts.OptLabel.OPT_TX_ID;
import static bisq.cli.opts.OptLabel.OPT_TX_KEY;

public class GetTradeOptionParser extends AbstractMethodOptionParser implements MethodOpts {

Expand All @@ -33,6 +35,16 @@ public class GetTradeOptionParser extends AbstractMethodOptionParser implements
.ofType(boolean.class)
.defaultsTo(Boolean.FALSE);

final OptionSpec<String> txIdOpt = parser.accepts(OPT_TX_ID, "optional tx id")
.withOptionalArg()
.ofType(String.class)
.defaultsTo("");

final OptionSpec<String> txKeyOpt = parser.accepts(OPT_TX_KEY, "optional tx key")
.withOptionalArg()
.ofType(String.class)
.defaultsTo("");

public GetTradeOptionParser(String[] args) {
super(args);
}
Expand All @@ -57,4 +69,10 @@ public String getTradeId() {
public boolean getShowContract() {
return options.has(showContractOpt) ? options.valueOf(showContractOpt) : false;
}
public String getTxId() {
return options.has(txIdOpt) ? options.valueOf(txIdOpt) : "";
}
public String getTxKey() {
return options.has(txKeyOpt) ? options.valueOf(txKeyOpt) : "";
}
}
2 changes: 2 additions & 0 deletions cli/src/main/java/bisq/cli/opts/OptLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ public class OptLabel {
public final static String OPT_TX_FEE_RATE = "tx-fee-rate";
public final static String OPT_WALLET_PASSWORD = "wallet-password";
public final static String OPT_NEW_WALLET_PASSWORD = "new-wallet-password";
public final static String OPT_TX_ID = "tx-id";
public final static String OPT_TX_KEY = "tx-key";
}
11 changes: 11 additions & 0 deletions cli/src/main/java/bisq/cli/request/TradesServiceRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import bisq.proto.grpc.CloseTradeRequest;
import bisq.proto.grpc.ConfirmPaymentReceivedRequest;
import bisq.proto.grpc.ConfirmPaymentStartedRequest;
import bisq.proto.grpc.ConfirmPaymentStartedXmrRequest;
import bisq.proto.grpc.FailTradeRequest;
import bisq.proto.grpc.GetTradeRequest;
import bisq.proto.grpc.GetTradesRequest;
Expand Down Expand Up @@ -115,6 +116,16 @@ public void confirmPaymentStarted(String tradeId) {
grpcStubs.tradesService.confirmPaymentStarted(request);
}

public void confirmPaymentStartedXmr(String tradeId, String txId, String txKey) {
var request = ConfirmPaymentStartedXmrRequest.newBuilder()
.setTradeId(tradeId)
.setTxId(txId)
.setTxKey(txKey)
.build();
//noinspection ResultOfMethodCallIgnored
grpcStubs.tradesService.confirmPaymentStartedXmr(request);
}

public void confirmPaymentReceived(String tradeId) {
var request = ConfirmPaymentReceivedRequest.newBuilder()
.setTradeId(tradeId)
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/bisq/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Nullable;

import static bisq.proto.grpc.EditOfferRequest.EditType;

/**
Expand Down Expand Up @@ -318,8 +320,8 @@ public void takeOffer(String offerId,
errorMessageHandler);
}

public void confirmPaymentStarted(String tradeId) {
coreTradesService.confirmPaymentStarted(tradeId);
public void confirmPaymentStarted(String tradeId, @Nullable String txId, @Nullable String txKey) {
coreTradesService.confirmPaymentStarted(tradeId, txId, txKey);
}

public void confirmPaymentReceived(String tradeId) {
Expand Down
9 changes: 8 additions & 1 deletion core/src/main/java/bisq/core/api/CoreTradesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@

import lombok.extern.slf4j.Slf4j;

import javax.annotation.Nullable;

import static bisq.core.btc.model.AddressEntry.Context.TRADE_PAYOUT;
import static bisq.proto.grpc.GetTradesRequest.Category.CLOSED;
import static java.lang.String.format;
Expand Down Expand Up @@ -186,7 +188,7 @@ void takeOffer(Offer offer,
);
}

void confirmPaymentStarted(String tradeId) {
void confirmPaymentStarted(String tradeId, @Nullable String txId, @Nullable String txKey) {
var trade = getTrade(tradeId);
if (isFollowingBuyerProtocol(trade)) {
if (!trade.isDepositConfirmed()) {
Expand All @@ -196,6 +198,11 @@ void confirmPaymentStarted(String tradeId) {
trade.getId(),
trade.getDepositTxId()));
}
// pass along counter currency tx proof info if provided
if (txId != null && txKey != null && !txId.isEmpty() && !txKey.isEmpty()) {
trade.setCounterCurrencyTxId(txId);
trade.setCounterCurrencyExtraData(txKey);
}
var tradeProtocol = tradeManager.getTradeProtocol(trade);
((BuyerProtocol) tradeProtocol).onPaymentStarted(
() -> {
Expand Down
14 changes: 13 additions & 1 deletion core/src/main/java/bisq/core/api/model/TradeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public class TradeInfo implements Payload {
private final boolean isCompleted;
private final String contractAsJson;
private final ContractInfo contract;
private final String autoConfTxId;
private final String autoConfTxKey;
private final boolean hasFailed;
private final String errorMessage;
// Optional BSQ swap trade protocol details (post v1).
Expand Down Expand Up @@ -126,6 +128,8 @@ public TradeInfo(TradeInfoV1Builder builder) {
this.isCompleted = builder.isCompleted();
this.contractAsJson = builder.getContractAsJson();
this.contract = builder.getContract();
this.autoConfTxId = builder.getAutoConfTxId();
this.autoConfTxKey = builder.getAutoConfTxKey();
this.bsqSwapTradeInfo = null;
this.closingStatus = builder.getClosingStatus();
this.hasFailed = builder.isHasFailed();
Expand Down Expand Up @@ -188,7 +192,7 @@ public static TradeInfo toTradeInfo(BsqSwapTrade bsqSwapTrade,
.withPhase(bsqSwapTrade.getTradePhase().name())
// N/A for bsq-swaps: tradePeriodState, isDepositPublished, isDepositConfirmed
// N/A for bsq-swaps: isPaymentStartedMessageSent, isPaymentReceivedMessageSent, isPayoutPublished
// N/A for bsq-swaps: isCompleted, contractAsJson, contract
// N/A for bsq-swaps: isCompleted, contractAsJson, contract, autoConfTxId, autoConfTxKey
.withClosingStatus(closingStatus)
.build();
tradeInfo.bsqSwapTradeInfo = toBsqSwapTradeInfo(bsqSwapTrade, isMyOffer, numConfirmations);
Expand Down Expand Up @@ -247,6 +251,8 @@ private static TradeInfo toTradeInfo(Trade trade,
.withContractAsJson(trade.getContractAsJson())
.withContract(contractInfo)
.withClosingStatus(closingStatus)
.withAutoConfTxId(trade.getCounterCurrencyTxId() == null ? "" : trade.getCounterCurrencyTxId())
.withAutoConfTxKey(trade.getCounterCurrencyExtraData() == null ? "" : trade.getCounterCurrencyExtraData())
.withHasFailed(trade.hasFailed())
.withErrorMessage(trade.hasErrorMessage() ? trade.getErrorMessage() : "")
.build();
Expand Down Expand Up @@ -286,6 +292,8 @@ public bisq.proto.grpc.TradeInfo toProtoMessage() {
.setIsCompleted(isCompleted)
.setHasFailed(hasFailed)
.setErrorMessage(errorMessage == null ? "" : errorMessage)
.setAutoConfTxId(autoConfTxId == null ? "" : autoConfTxId)
.setAutoConfTxKey(autoConfTxKey == null ? "" : autoConfTxKey)
.setClosingStatus(closingStatus);
if (offer.isBsqSwapOffer()) {
protoBuilder.setBsqSwapTradeInfo(bsqSwapTradeInfo.toProtoMessage());
Expand Down Expand Up @@ -328,6 +336,8 @@ public static TradeInfo fromProto(bisq.proto.grpc.TradeInfo proto) {
.withClosingStatus(proto.getClosingStatus())
.withHasFailed(proto.getHasFailed())
.withErrorMessage(proto.getErrorMessage())
.withAutoConfTxId(proto.getAutoConfTxId())
.withAutoConfTxKey(proto.getAutoConfTxKey())
.build();

if (proto.getOffer().getIsBsqSwapOffer())
Expand Down Expand Up @@ -369,6 +379,8 @@ public String toString() {
", closingStatus=" + closingStatus + "\n" +
", hasFailed=" + hasFailed + "\n" +
", errorMessage=" + errorMessage + "\n" +
", autoConfTxId=" + autoConfTxId + "\n" +
", autoConfTxKey=" + autoConfTxKey + "\n" +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public final class TradeInfoV1Builder {
private ContractInfo contract;
private String closingStatus;
private String errorMessage;
private String autoConfTxId;
private String autoConfTxKey;

public TradeInfoV1Builder withOffer(OfferInfo offer) {
this.offer = offer;
Expand Down Expand Up @@ -207,6 +209,16 @@ public TradeInfoV1Builder withClosingStatus(String closingStatus) {
return this;
}

public TradeInfoV1Builder withAutoConfTxId(String autoConfTxId) {
this.autoConfTxId = autoConfTxId;
return this;
}

public TradeInfoV1Builder withAutoConfTxKey(String autoConfTxKey) {
this.autoConfTxKey = autoConfTxKey;
return this;
}

public TradeInfo build() {
return new TradeInfo(this);
}
Expand Down
16 changes: 15 additions & 1 deletion daemon/src/main/java/bisq/daemon/grpc/GrpcTradesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import bisq.proto.grpc.ConfirmPaymentReceivedRequest;
import bisq.proto.grpc.ConfirmPaymentStartedReply;
import bisq.proto.grpc.ConfirmPaymentStartedRequest;
import bisq.proto.grpc.ConfirmPaymentStartedXmrRequest;
import bisq.proto.grpc.FailTradeReply;
import bisq.proto.grpc.FailTradeRequest;
import bisq.proto.grpc.GetTradeReply;
Expand Down Expand Up @@ -174,7 +175,20 @@ public void getTrades(GetTradesRequest req,
public void confirmPaymentStarted(ConfirmPaymentStartedRequest req,
StreamObserver<ConfirmPaymentStartedReply> responseObserver) {
try {
coreApi.confirmPaymentStarted(req.getTradeId());
coreApi.confirmPaymentStarted(req.getTradeId(), null, null);
var reply = ConfirmPaymentStartedReply.newBuilder().build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
} catch (Throwable cause) {
exceptionHandler.handleException(log, cause, responseObserver);
}
}

@Override
public void confirmPaymentStartedXmr(ConfirmPaymentStartedXmrRequest req,
StreamObserver<ConfirmPaymentStartedReply> responseObserver) {
try {
coreApi.confirmPaymentStarted(req.getTradeId(), req.getTxId(), req.getTxKey());
var reply = ConfirmPaymentStartedReply.newBuilder().build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
Expand Down
13 changes: 13 additions & 0 deletions proto/src/main/proto/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ service Trades {
// Send a 'payment started' message to a trading peer (the BTC seller).
rpc ConfirmPaymentStarted (ConfirmPaymentStartedRequest) returns (ConfirmPaymentStartedReply) {
}
// Send a 'payment started' message with optional XMR specific parameters to a trading peer (the BTC seller).
rpc ConfirmPaymentStartedXmr (ConfirmPaymentStartedXmrRequest) returns (ConfirmPaymentStartedReply) {
}
// Send a 'payment received' message to a trading peer (the BTC buyer).
rpc ConfirmPaymentReceived (ConfirmPaymentReceivedRequest) returns (ConfirmPaymentReceivedReply) {
}
Expand Down Expand Up @@ -538,6 +541,12 @@ message ConfirmPaymentStartedRequest {
string trade_id = 1; // The unique identifier of the open trade.
}

message ConfirmPaymentStartedXmrRequest {
string trade_id = 1; // The unique identifier of the open trade.
string tx_id = 2; // XMR txId for payment proof
string tx_key = 3; // XMR txKey for payment proof
}

message ConfirmPaymentStartedReply {
}

Expand Down Expand Up @@ -664,6 +673,10 @@ message TradeInfo {
bool has_failed = 30;
// Error message applicable when trade is failed.
string error_message = 31;
// txId used for XMR auto conf.
string auto_conf_tx_id = 32;
// tx key used for XMR auto conf.
string auto_conf_tx_key = 33;
}

message ContractInfo {
Expand Down