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

[Greenfield] Add sentTimestamp field to delivery data (Fix #3146) #3278

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions BTCPayServer.Client/Models/WebhookDeliveryData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class WebhookDeliveryData
public string Id { get; set; }
[JsonConverter(typeof(NBitcoin.JsonConverters.DateTimeToUnixTimeConverter))]
public DateTimeOffset Timestamp { get; set; }
[JsonConverter(typeof(NBitcoin.JsonConverters.DateTimeToUnixTimeConverter))]
public DateTimeOffset? SentTimestamp { get; set; }
public int? HttpCode { get; set; }
public string ErrorMessage { get; set; }
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
Expand Down
2 changes: 2 additions & 0 deletions BTCPayServer.Tests/GreenfieldAPITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,8 @@ void AssertHook(FakeServer fakeServer, Client.Models.StoreWebhookData hook)
fakeServer.Done();
var newDelivery = await clientProfile.GetWebhookDelivery(user.StoreId, hook.Id, newDeliveryId);
Assert.NotNull(newDelivery);
Assert.NotNull(newDelivery.SentTimestamp);
Assert.True(newDelivery.Timestamp - newDelivery.SentTimestamp < TimeSpan.FromSeconds(5.0));
Assert.Equal(404, newDelivery.HttpCode);
var req = await clientProfile.GetWebhookDeliveryRequest(user.StoreId, hook.Id, newDeliveryId);
Assert.Equal(delivery.Id, req.OriginalDeliveryId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ private Client.Models.WebhookDeliveryData FromModel(Data.WebhookDeliveryData dat
{
Id = data.Id,
Timestamp = data.Timestamp,
SentTimestamp = b.SentTimestamp,
Status = b.Status,
ErrorMessage = b.ErrorMessage,
HttpCode = b.HttpCode
Expand Down
3 changes: 3 additions & 0 deletions BTCPayServer/Data/WebhookDataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class WebhookDeliveryBlob
public int? HttpCode { get; set; }
public string ErrorMessage { get; set; }
public byte[] Request { get; set; }
[JsonConverter(typeof(NBitcoin.JsonConverters.DateTimeToUnixTimeConverter))]
public DateTimeOffset? SentTimestamp { get; set; }

public T ReadRequestAs<T>()
{
return JsonConvert.DeserializeObject<T>(UTF8Encoding.UTF8.GetString(Request), HostedServices.WebhookNotificationManager.DefaultSerializerSettings);
Expand Down
1 change: 1 addition & 0 deletions BTCPayServer/HostedServices/WebhookNotificationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ private async Task<DeliveryResult> SendDelivery(WebhookDeliveryRequest ctx)
request.Content = content;
var deliveryBlob = ctx.Delivery.Blob is null ? new WebhookDeliveryBlob() : ctx.Delivery.GetBlob();
deliveryBlob.Request = bytes;
deliveryBlob.SentTimestamp = DateTimeOffset.UtcNow;
try
{
using var response = await httpClient.SendAsync(request, CancellationToken);
Expand Down
11 changes: 10 additions & 1 deletion BTCPayServer/wwwroot/swagger/v1/swagger.template.webhooks.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,16 @@
},
"timestamp": {
"nullable": false,
"description": "Timestamp of when the delivery got broadcasted",
"description": "Timestamp of when the delivery got created.",
"allOf": [
{
"$ref": "#/components/schemas/UnixTimestamp"
}
]
},
"sentTimestamp": {
"nullable": true,
"description": "Timestamp of when the delivery got broadcasted. (Deliveries are queued to ensure orderly delivery, if the server is slow to respond, queued deliveries may be broadcasted late)",
"allOf": [
{
"$ref": "#/components/schemas/UnixTimestamp"
Expand Down