Skip to content

Commit

Permalink
fix: lightning get payment implementation (#50)
Browse files Browse the repository at this point in the history
* chore: bump client to v2.3.6

* fix(lightning): get swap by payment hash instead of calling `ListSwaps`

* refactor: use `TrimStart` for removing v prefix of version
  • Loading branch information
jackstar12 committed Jan 22, 2025
1 parent e05154c commit ac5f37e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
10 changes: 8 additions & 2 deletions BTCPayServer.Plugins.Boltz/BoltzClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Autoswaprpc;
using Boltzrpc;
using BTCPayServer.Plugins.Boltz.Models;
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using Grpc.Core;
using Grpc.Net.Client;
Expand Down Expand Up @@ -97,13 +98,18 @@ public async Task<ListSwapsResponse> ListSwaps(ListSwapsRequest request)

public async Task<GetSwapInfoResponse> GetSwapInfo(string id)
{
return await _client.GetSwapInfoAsync(new GetSwapInfoRequest { Id = id }, _metadata);
return await _client.GetSwapInfoAsync(new GetSwapInfoRequest { SwapId = id }, _metadata);
}

public async Task<GetSwapInfoResponse> GetSwapInfo(byte[] paymentHash)
{
return await _client.GetSwapInfoAsync(new GetSwapInfoRequest { PaymentHash = ByteString.CopyFrom(paymentHash) }, _metadata);
}

public AsyncServerStreamingCall<GetSwapInfoResponse> GetSwapInfoStream(string id,
CancellationToken cancellationToken = default)
{
return _client.GetSwapInfoStream(new GetSwapInfoRequest { Id = id }, _metadata,
return _client.GetSwapInfoStream(new GetSwapInfoRequest { SwapId = id }, _metadata,
cancellationToken: cancellationToken);
}

Expand Down
4 changes: 2 additions & 2 deletions BTCPayServer.Plugins.Boltz/BoltzDaemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class BoltzDaemon(
BTCPayNetworkProvider btcPayNetworkProvider
)
{
private static readonly Version ClientVersion = new("2.3.4");
private static readonly Version ClientVersion = new("2.3.7");

private Stream? _downloadStream;
private Task? _startTask;
Expand Down Expand Up @@ -457,7 +457,7 @@ public async Task Init()
}
else
{
currentVersion = stdout.Split("\n").First().Split("-").First().Remove(0, 1);
currentVersion = stdout.Split("\n").First().Split("-").First().TrimStart('v');
}
}

Expand Down
17 changes: 15 additions & 2 deletions BTCPayServer.Plugins.Boltz/BoltzLightningClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,21 @@ public async Task<LightningInvoice[]> ListInvoices(ListInvoicesParams request,
public async Task<LightningPayment> GetPayment(string paymentHash,
CancellationToken cancellation = new CancellationToken())
{
var payments = await ListPayments(cancellation);
return payments.ToList().Find(payment => payment.PaymentHash == paymentHash)!;
var client = await GetClient();
try
{
var info = await client.GetSwapInfo(Convert.FromHexString(paymentHash));
return PaymentFromSwapInfo(info.Swap);
}
catch (RpcException e) when (e.StatusCode == StatusCode.NotFound)
{
return new LightningPayment
{
Id = paymentHash,
// this will be the case when the initial pay call failed, yet btcpay still tries to check if there was a payment
Status = LightningPaymentStatus.Failed
};
}
}

public async Task<LightningPayment[]> ListPayments(CancellationToken cancellation = new CancellationToken())
Expand Down
9 changes: 7 additions & 2 deletions BTCPayServer.Plugins.Boltz/Protos/boltzrpc/boltzrpc.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";

package boltzrpc;
option go_package = "github.com/BoltzExchange/boltz-client/boltzrpc";
option go_package = "github.com/BoltzExchange/boltz-client/v2/pkg/boltzrpc";
import "google/protobuf/empty.proto";

service Boltz {
Expand Down Expand Up @@ -499,7 +499,12 @@ message ClaimSwapsResponse {
}

message GetSwapInfoRequest {
string id = 1;
string id = 1 [deprecated = true];
oneof identifier {
string swap_id = 2;
// Only implemented for submarine swaps
bytes payment_hash = 3;
}
}
message GetSwapInfoResponse {
SwapInfo swap = 1;
Expand Down
4 changes: 2 additions & 2 deletions BTCPayServer.Plugins.Boltz/Protos/boltzrpc/cp.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cp ~/dev/boltz-client/boltzrpc/autoswaprpc/autoswaprpc.proto ./autoswaprpc/
cp ~/dev/boltz-client/boltzrpc/boltzrpc.proto .
cp ~/dev/boltz-client/pkg/boltzrpc/autoswaprpc/autoswaprpc.proto ./autoswaprpc/
cp ~/dev/boltz-client/pkg/boltzrpc/boltzrpc.proto .

0 comments on commit ac5f37e

Please sign in to comment.