From 37f4b34b5edc93d6d7e6453b7b55448146d16fab Mon Sep 17 00:00:00 2001 From: Kukks Date: Fri, 29 May 2020 10:04:28 +0200 Subject: [PATCH 1/2] Add Lightmoney json converter + do swagger defs for ln api --- .../JsonConverters/LightMoneyJsonConverter.cs | 15 + .../Models/LightningInvoiceData.cs | 2 +- .../Models/LightningNodeInformationData.cs | 5 +- .../LightningNodeApiController.Internal.cs | 4 +- .../v1/swagger.template.lightning.common.json | 64 +-- .../swagger.template.lightning.internal.json | 470 +++++++++++++++ .../v1/swagger.template.lightning.store.json | 542 ++++++++++++++++++ 7 files changed, 1060 insertions(+), 42 deletions(-) create mode 100644 BTCPayServer.Client/JsonConverters/LightMoneyJsonConverter.cs create mode 100644 BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.internal.json create mode 100644 BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.store.json diff --git a/BTCPayServer.Client/JsonConverters/LightMoneyJsonConverter.cs b/BTCPayServer.Client/JsonConverters/LightMoneyJsonConverter.cs new file mode 100644 index 000000000..71581c2e6 --- /dev/null +++ b/BTCPayServer.Client/JsonConverters/LightMoneyJsonConverter.cs @@ -0,0 +1,15 @@ +using System.Globalization; +using BTCPayServer.Lightning; +using Newtonsoft.Json; + +namespace BTCPayServer.Client.JsonConverters +{ + public class LightMoneyJsonConverter : BTCPayServer.Lightning.JsonConverters.LightMoneyJsonConverter + { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + if (value != null) + writer.WriteValue(((LightMoney)value).MilliSatoshi.ToString(CultureInfo.InvariantCulture)); + } + } +} diff --git a/BTCPayServer.Client/Models/LightningInvoiceData.cs b/BTCPayServer.Client/Models/LightningInvoiceData.cs index 6a76e25f9..8a22439c4 100644 --- a/BTCPayServer.Client/Models/LightningInvoiceData.cs +++ b/BTCPayServer.Client/Models/LightningInvoiceData.cs @@ -1,6 +1,6 @@ using System; +using BTCPayServer.Client.JsonConverters; using BTCPayServer.Lightning; -using BTCPayServer.Lightning.JsonConverters; using Newtonsoft.Json; using Newtonsoft.Json.Converters; diff --git a/BTCPayServer.Client/Models/LightningNodeInformationData.cs b/BTCPayServer.Client/Models/LightningNodeInformationData.cs index 11d83def4..e3e8a7b18 100644 --- a/BTCPayServer.Client/Models/LightningNodeInformationData.cs +++ b/BTCPayServer.Client/Models/LightningNodeInformationData.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using BTCPayServer.Client.JsonConverters; using BTCPayServer.Lightning; using NBitcoin; using NBitcoin.JsonConverters; @@ -20,10 +21,10 @@ namespace BTCPayServer.Client.Models public bool IsActive { get; set; } - [JsonProperty(ItemConverterType = typeof(MoneyJsonConverter))] + [JsonProperty(ItemConverterType = typeof(LightMoneyJsonConverter))] public LightMoney Capacity { get; set; } - [JsonProperty(ItemConverterType = typeof(MoneyJsonConverter))] + [JsonProperty(ItemConverterType = typeof(LightMoneyJsonConverter))] public LightMoney LocalBalance { get; set; } public string ChannelPoint { get; set; } diff --git a/BTCPayServer/Controllers/GreenField/LightningNodeApiController.Internal.cs b/BTCPayServer/Controllers/GreenField/LightningNodeApiController.Internal.cs index c1f2f9572..2933e1b07 100644 --- a/BTCPayServer/Controllers/GreenField/LightningNodeApiController.Internal.cs +++ b/BTCPayServer/Controllers/GreenField/LightningNodeApiController.Internal.cs @@ -13,14 +13,14 @@ namespace BTCPayServer.Controllers.GreenField { [ApiController] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)] - public class InternalLightningNodeApiInternalController : LightningNodeApiController + public class InternalLightningNodeApiController : LightningNodeApiController { private readonly BTCPayServerOptions _btcPayServerOptions; private readonly BTCPayNetworkProvider _btcPayNetworkProvider; private readonly LightningClientFactoryService _lightningClientFactory; - public InternalLightningNodeApiInternalController(BTCPayServerOptions btcPayServerOptions, + public InternalLightningNodeApiController(BTCPayServerOptions btcPayServerOptions, BTCPayNetworkProvider btcPayNetworkProvider, BTCPayServerEnvironment btcPayServerEnvironment, CssThemeManager cssThemeManager, LightningClientFactoryService lightningClientFactory) : base( btcPayNetworkProvider, btcPayServerEnvironment, cssThemeManager) diff --git a/BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.common.json b/BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.common.json index a00ca9bae..1a86f2222 100644 --- a/BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.common.json +++ b/BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.common.json @@ -4,41 +4,35 @@ "ConnectToNodeRequest": { "oneOf": [ { - "$ref": "#/components/schemas/ConnectToNodeRequest1" + "type": "object", + "additionalProperties": false, + "properties": { + "nodeInfo": { + "type": "string", + "nullable": true + } + } }, { - "$ref": "#/components/schemas/ConnectToNodeRequest2" + "type": "object", + "additionalProperties": false, + "properties": { + "nodeId": { + "type": "string", + "nullable": true + }, + "nodeHost": { + "type": "string", + "nullable": true + }, + "nodePort": { + "type": "integer", + "format": "int32" + } + } } ] }, - "ConnectToNodeRequest1": { - "type": "object", - "additionalProperties": false, - "properties": { - "nodeInfo": { - "type": "string", - "nullable": true - } - } - }, - "ConnectToNodeRequest2": { - "type": "object", - "additionalProperties": false, - "properties": { - "nodeId": { - "type": "string", - "nullable": true - }, - "nodeHost": { - "type": "string", - "nullable": true - }, - "nodePort": { - "type": "integer", - "format": "int32" - } - } - }, "CreateLightningInvoiceRequest": { "type": "object", "additionalProperties": false, @@ -65,8 +59,9 @@ } }, "LightMoney": { - "type": "integer", + "type": "string", "format": "int64", + "description": "The id of the store", "additionalProperties": false }, "LightningChannelData": { @@ -235,10 +230,5 @@ ] } } - }, - "tags": [ - { - "name": "Lightning" - } - ] + } } diff --git a/BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.internal.json b/BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.internal.json new file mode 100644 index 000000000..e91204b8d --- /dev/null +++ b/BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.internal.json @@ -0,0 +1,470 @@ +{ + "paths": { + "/api/v1/server/lightning/{cryptoCode}/info": { + "get": { + "tags": [ + "Lightning (Internal Node)" + ], + "summary": "Get node information", + "parameters": [ + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + } + ], + "description": "View information about the lightning node", + "operationId": "InternalLightningNodeApi_GetInfo", + "responses": { + "200": { + "description": "Lightning node information such as reachable nodeinfos", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LightningNodeInformationData" + } + } + } + }, + "400": { + "description": "A list of errors that occurred", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "security": [ + { + "API Key": [ + "btcpay.server.canuseinternallightningnode" + ], + "Basic": [] + } + ] + } + }, + "/api/v1/server/lightning/{cryptoCode}/connect": { + "post": { + "tags": [ + "Lightning (Internal Node)" + ], + "summary": "Connect to lightning node", + "parameters": [ + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + } + ], + "description": "Connect to another lightning node.", + "operationId": "InternalLightningNodeApi_ConnectToNode", + "responses": { + "200": { + "description": "Successfully connected" + }, + "400": { + "description": "A list of errors that occurred when attempting to connect to the lightning node", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ConnectToNodeRequest" + } + } + } + }, + "security": [ + { + "API Key": [ + "btcpay.server.canuseinternallightningnode" + ], + "Basic": [] + } + ] + } + }, + "/api/v1/server/lightning/{cryptoCode}/channels": { + "get": { + "tags": [ + "Lightning (Internal Node)" + ], + "summary": "Get channels", + "parameters": [ + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + } + ], + "description": "View information about the current channels of the lightning node", + "operationId": "InternalLightningNodeApi_GetChannels", + "responses": { + "200": { + "description": "list of channels", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/LightningChannelData" + } + } + } + } + }, + "400": { + "description": "A list of errors that occurred", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "security": [ + { + "API Key": [ + "btcpay.server.canuseinternallightningnode" + ], + "Basic": [] + } + ] + }, + "post": { + "tags": [ + "Lightning (Internal Node)" + ], + "summary": "Open channel", + "parameters": [ + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + } + ], + "description": "Open a channel with another lightning node. You should connect to that node first.", + "operationId": "InternalLightningNodeApi_OpenChannel", + "responses": { + "200": { + "description": "Successfully opened" + }, + "400": { + "description": "A list of errors that occurred when attempting to connect to the lightning node", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/OpenLightningChannelRequest" + } + } + } + }, + "security": [ + { + "API Key": [ + "btcpay.server.canuseinternallightningnode" + ], + "Basic": [] + } + ] + } + }, + "/api/v1/server/lightning/{cryptoCode}/address": { + "get": { + "tags": [ + "Lightning (Internal Node)" + ], + "summary": "Get deposit address", + "parameters": [ + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + } + ], + "description": "Get an on-chain deposit address for the lightning node ", + "operationId": "InternalLightningNodeApi_GetDepositAddress", + "responses": { + "200": { + "description": "deposit address", + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + } + }, + "400": { + "description": "A list of errors that occurred", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "security": [ + { + "API Key": [ + "btcpay.server.canuseinternallightningnode" + ], + "Basic": [] + } + ] + } + }, + + "/api/v1/server/lightning/{cryptoCode}/invoices/{id}": { + "get": { + "tags": [ + "Lightning (Internal Node)" + ], + "summary": "Get invoice", + "parameters": [ + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + } , { + "name": "id", + "in": "path", + "required": true, + "description": "The id of the lightning invoice.", + "schema": { + "type": "string" + } + } + ], + "description": "View information about the requested lightning invoice", + "operationId": "InternalLightningNodeApi_GetInvoice", + "responses": { + "200": { + "description": "Lightning invoice data", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LightningInvoiceData" + } + } + } + }, + "400": { + "description": "A list of errors that occurred", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "security": [ + { + "API Key": [ + "btcpay.server.canuseinternallightningnode" + ], + "Basic": [] + } + ] + } + }, + "/api/v1/server/lightning/{cryptoCode}/invoices/pay": { + "post": { + "tags": [ + "Lightning (Internal Node)" + ], + "summary": "Pay Lightning Invoice", + "parameters": [ + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + } + ], + "description": "Pay a lightning invoice.", + "operationId": "InternalLightningNodeApi_PayInvoice", + "responses": { + "200": { + "description": "Successfully paid" + }, + "400": { + "description": "A list of errors that occurred when attempting to pay the lightning invoice", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/PayLightningInvoiceRequest" + } + } + } + }, + "security": [ + { + "API Key": [ + "btcpay.server.canuseinternallightningnode" + ], + "Basic": [] + } + ] + } + }, + "/api/v1/server/lightning/{cryptoCode}/invoices": { + "post": { + "tags": [ + "Lightning (Internal Node)" + ], + "summary": "Create lightning invoice", + "parameters": [ + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + } + ], + "description": "Create a lightning invoice.", + "operationId": "InternalLightningNodeApi_CreateInvoice", + "responses": { + "200": { + "description": "Successfully created", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LightningInvoiceData" + } + } + } + }, + "400": { + "description": "A list of errors that occurred when attempting to create the lightning invoice", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/PayLightningInvoiceRequest" + } + } + } + }, + "security": [ + { + "API Key": [ + "btcpay.server.cancreatelightninginvoiceinternalnode" + ], + "Basic": [] + } + ] + } + } + }, + "tags": [ + { + "name": "Lightning (Internal Node)" + } + ] +} diff --git a/BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.store.json b/BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.store.json new file mode 100644 index 000000000..dd3095b09 --- /dev/null +++ b/BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.store.json @@ -0,0 +1,542 @@ +{ + "paths": { + "/api/v1/stores/{storeId}/lightning/{cryptoCode}/info": { + "get": { + "tags": [ + "Lightning (Store)" + ], + "summary": "Get node information", + "parameters": [ + { + "name": "storeId", + "in": "path", + "required": true, + "description": "The store id with the lightning node configuration you wish to use", + "schema": { + "type": "string" + } + }, + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + } + ], + "description": "View information about the lightning node", + "operationId": "StoreLightningNodeApi_GetInfo", + "responses": { + "200": { + "description": "Lightning node information such as reachable nodeinfos", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LightningNodeInformationData" + } + } + } + }, + "400": { + "description": "A list of errors that occurred", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "security": [ + { + "API Key": [ + "btcpay.store.canuselightningnode" + ], + "Basic": [] + } + ] + } + }, + "/api/v1/stores/{storeId}/lightning/{cryptoCode}/connect": { + "post": { + "tags": [ + "Lightning (Store)" + ], + "summary": "Connect to lightning node", + "parameters": [ + { + "name": "storeId", + "in": "path", + "required": true, + "description": "The store id with the lightning node configuration you wish to use", + "schema": { + "type": "string" + } + }, + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + } + ], + "description": "Connect to another lightning node.", + "operationId": "StoreLightningNodeApi_ConnectToNode", + "responses": { + "200": { + "description": "Successfully connected" + }, + "400": { + "description": "A list of errors that occurred when attempting to connect to the lightning node", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ConnectToNodeRequest" + } + } + } + }, + "security": [ + { + "API Key": [ + "btcpay.store.canuselightningnode" + ], + "Basic": [] + } + ] + } + }, + "/api/v1/stores/{storeId}/lightning/{cryptoCode}/channels": { + "get": { + "tags": [ + "Lightning (Store)" + ], + "summary": "Get channels", + "parameters": [ + { + "name": "storeId", + "in": "path", + "required": true, + "description": "The store id with the lightning node configuration you wish to use", + "schema": { + "type": "string" + } + }, + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + } + ], + "description": "View information about the current channels of the lightning node", + "operationId": "StoreLightningNodeApi_GetChannels", + "responses": { + "200": { + "description": "list of channels", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/LightningChannelData" + } + } + } + } + }, + "400": { + "description": "A list of errors that occurred", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "security": [ + { + "API Key": [ + "btcpay.store.canuselightningnode" + ], + "Basic": [] + } + ] + }, + "post": { + "tags": [ + "Lightning (Store)" + ], + "summary": "Open channel", + "parameters": [ + { + "name": "storeId", + "in": "path", + "required": true, + "description": "The store id with the lightning node configuration you wish to use", + "schema": { + "type": "string" + } + }, + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + } + ], + "description": "Open a channel with another lightning node. You should connect to that node first.", + "operationId": "StoreLightningNodeApi_OpenChannel", + "responses": { + "200": { + "description": "Successfully opened" + }, + "400": { + "description": "A list of errors that occurred when attempting to connect to the lightning node", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/OpenLightningChannelRequest" + } + } + } + }, + "security": [ + { + "API Key": [ + "btcpay.store.canuselightningnode" + ], + "Basic": [] + } + ] + } + }, + "/api/v1/stores/{storeId}/lightning/{cryptoCode}/address": { + "get": { + "tags": [ + "Lightning (Store)" + ], + "summary": "Get deposit address", + "parameters": [ + { + "name": "storeId", + "in": "path", + "required": true, + "description": "The store id with the lightning node configuration you wish to use", + "schema": { + "type": "string" + } + }, + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + } + ], + "description": "Get an on-chain deposit address for the lightning node ", + "operationId": "StoreLightningNodeApi_GetDepositAddress", + "responses": { + "200": { + "description": "deposit address", + "content": { + "application/json": { + "schema": { + "type": "string" + } + } + } + }, + "400": { + "description": "A list of errors that occurred", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "security": [ + { + "API Key": [ + "btcpay.store.canuselightningnode" + ], + "Basic": [] + } + ] + } + }, + "/api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices/{id}": { + "get": { + "tags": [ + "Lightning (Store)" + ], + "summary": "Get invoice", + "parameters": [ + { + "name": "storeId", + "in": "path", + "required": true, + "description": "The store id with the lightning node configuration you wish to use", + "schema": { + "type": "string" + } + }, + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + }, + { + "name": "id", + "in": "path", + "required": true, + "description": "The id of the lightning invoice.", + "schema": { + "type": "string" + } + } + ], + "description": "View information about the requested lightning invoice", + "operationId": "StoreLightningNodeApi_GetInvoice", + "responses": { + "200": { + "description": "Lightning invoice data", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LightningInvoiceData" + } + } + } + }, + "400": { + "description": "A list of errors that occurred", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "security": [ + { + "API Key": [ + "btcpay.store.canuselightningnode" + ], + "Basic": [] + } + ] + } + }, + "/api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices/pay": { + "post": { + "tags": [ + "Lightning (Store)" + ], + "summary": "Pay Lightning Invoice", + "parameters": [ + { + "name": "storeId", + "in": "path", + "required": true, + "description": "The store id with the lightning node configuration you wish to use", + "schema": { + "type": "string" + } + }, + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + } + ], + "description": "Pay a lightning invoice.", + "operationId": "StoreLightningNodeApi_PayInvoice", + "responses": { + "200": { + "description": "Successfully paid" + }, + "400": { + "description": "A list of errors that occurred when attempting to pay the lightning invoice", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/PayLightningInvoiceRequest" + } + } + } + }, + "security": [ + { + "API Key": [ + "btcpay.store.canuselightningnode" + ], + "Basic": [] + } + ] + } + }, + "/api/v1/stores/{storeId}/lightning/{cryptoCode}/invoices": { + "post": { + "tags": [ + "Lightning (Store)" + ], + "summary": "Create lightning invoice", + "parameters": [ + { + "name": "storeId", + "in": "path", + "required": true, + "description": "The store id with the lightning node configuration you wish to use", + "schema": { + "type": "string" + } + }, + { + "name": "cryptoCode", + "in": "path", + "required": true, + "description": "The cryptoCode of the lightning-node to query", + "schema": { + "type": "string" + } + } + ], + "description": "Create a lightning invoice.", + "operationId": "StoreLightningNodeApi_CreateInvoice", + "responses": { + "200": { + "description": "Successfully created", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LightningInvoiceData" + } + } + } + }, + "400": { + "description": "A list of errors that occurred when attempting to create the lightning invoice", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ValidationProblemDetails" + } + } + } + }, + "403": { + "description": "If you are authenticated but forbidden" + } + }, + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/PayLightningInvoiceRequest" + } + } + } + }, + "security": [ + { + "API Key": [ + "btcpay.store.cancreatelightninginvoice" + ], + "Basic": [] + } + ] + } + } + }, + "tags": [ + { + "name": "Lightning (Store)" + } + ] +} From 4947fa4d45a169396424b48870843e1572a5d087 Mon Sep 17 00:00:00 2001 From: Kukks Date: Fri, 29 May 2020 10:15:01 +0200 Subject: [PATCH 2/2] Add also money json converter --- .../JsonConverters/MoneyJsonConverter.cs | 25 +++++++++++++++++++ .../Models/OpenLightningChannelRequest.cs | 1 + .../v1/swagger.template.lightning.common.json | 7 +++--- 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 BTCPayServer.Client/JsonConverters/MoneyJsonConverter.cs diff --git a/BTCPayServer.Client/JsonConverters/MoneyJsonConverter.cs b/BTCPayServer.Client/JsonConverters/MoneyJsonConverter.cs new file mode 100644 index 000000000..865a99c0d --- /dev/null +++ b/BTCPayServer.Client/JsonConverters/MoneyJsonConverter.cs @@ -0,0 +1,25 @@ +using System; +using System.Globalization; +using NBitcoin; +using Newtonsoft.Json; + +namespace BTCPayServer.Client.JsonConverters +{ + public class MoneyJsonConverter : NBitcoin.JsonConverters.MoneyJsonConverter + { + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + if (reader.TokenType == JsonToken.String) + { + return new Money( long.Parse((string) reader.Value)); + } + return base.ReadJson(reader, objectType, existingValue, serializer); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + if (value != null) + writer.WriteValue(((Money)value).Satoshi.ToString(CultureInfo.InvariantCulture)); + } + } +} diff --git a/BTCPayServer.Client/Models/OpenLightningChannelRequest.cs b/BTCPayServer.Client/Models/OpenLightningChannelRequest.cs index 192c14fd9..1ee015475 100644 --- a/BTCPayServer.Client/Models/OpenLightningChannelRequest.cs +++ b/BTCPayServer.Client/Models/OpenLightningChannelRequest.cs @@ -1,6 +1,7 @@ using NBitcoin; using NBitcoin.JsonConverters; using Newtonsoft.Json; +using MoneyJsonConverter = BTCPayServer.Client.JsonConverters.MoneyJsonConverter; namespace BTCPayServer.Client.Models { diff --git a/BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.common.json b/BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.common.json index 1a86f2222..80cadab7a 100644 --- a/BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.common.json +++ b/BTCPayServer/wwwroot/swagger/v1/swagger.template.lightning.common.json @@ -61,7 +61,7 @@ "LightMoney": { "type": "string", "format": "int64", - "description": "The id of the store", + "description": "a number amount wrapped in a string, represented in millistatoshi (00000000001BTC = 1 mSAT)", "additionalProperties": false }, "LightningChannelData": { @@ -214,8 +214,9 @@ } }, "Money": { - "type": "integer", - "format": "int64" + "type": "string", + "format": "int64", + "description": "a number amount wrapped in a string, represented in satoshi (00000001BTC = 1 sat)" }, "FeeRate": { "oneOf": [