Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions DotNut/Api/CashuHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ public async Task<PostBatchedMintResponse> BatchMint(
return await HandleResponse<PostBatchedMintResponse>(response, cancellationToken);
}

public async Task<PostMintQuotesByPubkeyResponse> GetMintQuotesByPubkeys(PostMintQuoteBolt11Request request,
CancellationToken cancellationToken = default)
{
var response = await _httpClient.PostAsync(
"https://mint.host:3338/v1/mint/quote/bolt11/pubkey",
new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json"),
cancellationToken);
return await HandleResponse<PostMintQuotesByPubkeyResponse>(response, cancellationToken);
}

protected async Task<T> HandleResponse<T>(
HttpResponseMessage response,
CancellationToken cancellationToken
Expand Down
2 changes: 2 additions & 0 deletions DotNut/Api/ICashuApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Task<TResponse> BatchCheckMintQuoteState<TResponse>(
PostBatchedMintQuoteStateRequest request,
CancellationToken cancellationToken = default
);

Task<PostMintQuotesByPubkeyResponse> GetMintQuotesByPubkeys(PostMintQuoteBolt11Request request, CancellationToken cancellationToken = default);

Task<PostBatchedMintResponse> BatchMint(
string method,
Expand Down
12 changes: 12 additions & 0 deletions DotNut/ApiModels/PostMintQuotesByPubkeyRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;

namespace DotNut.ApiModels;

public class PostMintQuotesByPubkeyRequest
{
[JsonPropertyName("pubkeys")]
public string[] Pubkeys { get; set; }

[JsonPropertyName("pubkey_signatures")]
public string[] PubKey_Signatures { get; set; }
}
11 changes: 11 additions & 0 deletions DotNut/ApiModels/PostMintQuotesByPubkeyResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Text.Json.Serialization;
using DotNut.ApiModels.Mint.bolt12;

namespace DotNut.ApiModels;

[JsonConverter(typeof(PostMintQuotesByPubkeyResponseConverter))]
public class PostMintQuotesByPubkeyResponse
{
public PostMintQuoteBolt11Response[] Bolt11Quotes { get; set; }
public PostMintQuoteBolt12Response[] Bolt12Quotes { get; set; }
}
54 changes: 54 additions & 0 deletions DotNut/JsonConverters/QuotesByPubkeyConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using DotNut.ApiModels.Mint.bolt12;

namespace DotNut.ApiModels;

public class PostMintQuotesByPubkeyResponseConverter : JsonConverter<PostMintQuotesByPubkeyResponse>
{
private const string Bolt12Discriminator = "amount_paid";

public override PostMintQuotesByPubkeyResponse Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options)
{
using var doc = JsonDocument.ParseValue(ref reader);
var root = doc.RootElement;

var bolt11 = new List<PostMintQuoteBolt11Response>();
var bolt12 = new List<PostMintQuoteBolt12Response>();

foreach (var element in root.GetProperty("quotes").EnumerateArray())
{
var raw = element.GetRawText();
if (element.TryGetProperty(Bolt12Discriminator, out _))
bolt12.Add(JsonSerializer.Deserialize<PostMintQuoteBolt12Response>(raw, options)!);
else
bolt11.Add(JsonSerializer.Deserialize<PostMintQuoteBolt11Response>(raw, options)!);
}

return new PostMintQuotesByPubkeyResponse
{
Bolt11Quotes = bolt11.ToArray(),
Bolt12Quotes = bolt12.ToArray()
};
}

public override void Write(
Utf8JsonWriter writer,
PostMintQuotesByPubkeyResponse value,
JsonSerializerOptions options)
{
writer.WriteStartObject();
writer.WriteStartArray("quotes");

foreach (var q in value.Bolt11Quotes)
JsonSerializer.Serialize(writer, q, options);
foreach (var q in value.Bolt12Quotes)
JsonSerializer.Serialize(writer, q, options);

writer.WriteEndArray();
writer.WriteEndObject();
}
}