diff --git a/DotNut/Api/CashuHttpClient.cs b/DotNut/Api/CashuHttpClient.cs index 9a5780f..06cac54 100644 --- a/DotNut/Api/CashuHttpClient.cs +++ b/DotNut/Api/CashuHttpClient.cs @@ -201,6 +201,16 @@ public async Task BatchMint( return await HandleResponse(response, cancellationToken); } + public async Task 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(response, cancellationToken); + } + protected async Task HandleResponse( HttpResponseMessage response, CancellationToken cancellationToken diff --git a/DotNut/Api/ICashuApi.cs b/DotNut/Api/ICashuApi.cs index 48a7c7c..494b238 100644 --- a/DotNut/Api/ICashuApi.cs +++ b/DotNut/Api/ICashuApi.cs @@ -63,6 +63,8 @@ Task BatchCheckMintQuoteState( PostBatchedMintQuoteStateRequest request, CancellationToken cancellationToken = default ); + + Task GetMintQuotesByPubkeys(PostMintQuoteBolt11Request request, CancellationToken cancellationToken = default); Task BatchMint( string method, diff --git a/DotNut/ApiModels/PostMintQuotesByPubkeyRequest.cs b/DotNut/ApiModels/PostMintQuotesByPubkeyRequest.cs new file mode 100644 index 0000000..8c63df4 --- /dev/null +++ b/DotNut/ApiModels/PostMintQuotesByPubkeyRequest.cs @@ -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; } +} \ No newline at end of file diff --git a/DotNut/ApiModels/PostMintQuotesByPubkeyResponse.cs b/DotNut/ApiModels/PostMintQuotesByPubkeyResponse.cs new file mode 100644 index 0000000..33ae95e --- /dev/null +++ b/DotNut/ApiModels/PostMintQuotesByPubkeyResponse.cs @@ -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; } +} \ No newline at end of file diff --git a/DotNut/JsonConverters/QuotesByPubkeyConverter.cs b/DotNut/JsonConverters/QuotesByPubkeyConverter.cs new file mode 100644 index 0000000..365b855 --- /dev/null +++ b/DotNut/JsonConverters/QuotesByPubkeyConverter.cs @@ -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 +{ + 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(); + var bolt12 = new List(); + + foreach (var element in root.GetProperty("quotes").EnumerateArray()) + { + var raw = element.GetRawText(); + if (element.TryGetProperty(Bolt12Discriminator, out _)) + bolt12.Add(JsonSerializer.Deserialize(raw, options)!); + else + bolt11.Add(JsonSerializer.Deserialize(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(); + } +} \ No newline at end of file