Lightning payment info and fee handling (#3454)

* Lightning payment info and fee handling

Builds on the additions in btcpayserver/BTCPayServer.Lightning#59 and btcpayserver/BTCPayServer.Lightning#61.

Adds payment information (total amount and fees) to the API response and allows to set an optional maximum fee percentage when paying.

* Add max fee flat
This commit is contained in:
d11n
2022-02-17 10:01:39 +01:00
committed by GitHub
parent 2a884d6f38
commit cd3807a3d8
11 changed files with 97 additions and 26 deletions

View File

@@ -178,19 +178,23 @@ namespace BTCPayServer.Controllers.Greenfield
{
return this.CreateValidationError(ModelState);
}
var result = await lightningClient.Pay(lightningInvoice.BOLT11);
switch (result.Result)
var param = lightningInvoice?.MaxFeeFlat != null || lightningInvoice?.MaxFeePercent != null
? new PayInvoiceParams { MaxFeePercent = lightningInvoice.MaxFeePercent, MaxFeeFlat = lightningInvoice.MaxFeeFlat }
: null;
var result = await lightningClient.Pay(lightningInvoice.BOLT11, param);
return result.Result switch
{
case PayResult.CouldNotFindRoute:
return this.CreateAPIError("could-not-find-route", "Impossible to find a route to the peer");
case PayResult.Error:
return this.CreateAPIError("generic-error", result.ErrorDetail);
case PayResult.Ok:
return Ok();
default:
throw new NotSupportedException("Unsupported Payresult");
}
PayResult.CouldNotFindRoute => this.CreateAPIError("could-not-find-route", "Impossible to find a route to the peer"),
PayResult.Error => this.CreateAPIError("generic-error", result.ErrorDetail),
PayResult.Ok => Ok(new LightningPaymentData
{
TotalAmount = result.Details?.TotalAmount,
FeeAmount = result.Details?.FeeAmount
}),
_ => throw new NotSupportedException("Unsupported Payresult")
};
}
public virtual async Task<IActionResult> GetInvoice(string cryptoCode, string id)
@@ -253,7 +257,7 @@ namespace BTCPayServer.Controllers.Greenfield
private LightningInvoiceData ToModel(LightningInvoice invoice)
{
return new LightningInvoiceData()
return new LightningInvoiceData
{
Amount = invoice.Amount,
Id = invoice.Id,