diff --git a/snippets/csharp/ServiceStatus.cs b/snippets/csharp/ServiceStatus.cs new file mode 100644 index 0000000..06d248a --- /dev/null +++ b/snippets/csharp/ServiceStatus.cs @@ -0,0 +1,36 @@ +using Breez.Sdk; + +public class ServiceStatusSnippets +{ + public void HealthCheckStatus(BlockingBreezServices sdk) + { + // ANCHOR: health-check-status + try + { + var healthCheck = sdk.ServiceHealthCheck(); + Console.WriteLine($"Current service status is: {currentFees.totalEstimatedFees}"); + } + catch (Exception) + { + // Handle error + } + // ANCHOR_END: health-check-status + } + + public void ReportPaymentFailure(BlockingBreezServices sdk) + { + // ANCHOR: report-payment-failure + var paymentHash = "..."; + try + { + sdk.ReportIssue(new ReportIssueRequest.PaymentFailure( + new ReportPaymentFailureDetails(paymentHash) + )); + } + catch (Exception) + { + // Handle error + } + // ANCHOR_END: report-payment-failure + } +} diff --git a/snippets/dart_snippets/lib/service_status.dart b/snippets/dart_snippets/lib/service_status.dart new file mode 100644 index 0000000..c73c669 --- /dev/null +++ b/snippets/dart_snippets/lib/service_status.dart @@ -0,0 +1,16 @@ +import 'package:breez_sdk/breez_sdk.dart'; +import 'package:breez_sdk/bridge_generated.dart'; + +Future healthCheckStatus() async { + // ANCHOR: health-check-status + ServiceHealthCheckResponse healthCheck = await BreezSDK().serviceHealthCheck(); + print("Current service status is: ${healthCheck.status}"); + // ANCHOR_END: health-check-status +} + +Future reportPaymentFailure() async { + // ANCHOR: report-payment-failure + String paymentHash = "..."; + await BreezSDK().reportIssue(ReportIssueRequest.paymentFailure(paymentHash: paymentHash)); + // ANCHOR_END: report-payment-failure +} diff --git a/snippets/go/service_status.go b/snippets/go/service_status.go new file mode 100644 index 0000000..1d41408 --- /dev/null +++ b/snippets/go/service_status.go @@ -0,0 +1,29 @@ +package example + +import ( + "log" + + "github.com/breez/breez-sdk-go/breez_sdk" +) + +func HealthCheckStatus() { + // ANCHOR: health-check-status + if healthCheck, err := sdk.ServiceHealthCheck(); err != nil { + log.Printf("Current service status is: %v", healthCheck.Status) + } + // ANCHOR_END: health-check-status +} + +func ReportPaymentFailure() { + // ANCHOR: report-payment-failure + paymentHash := "..." + reportIssueRequest := breez_sdk.ReportIssueRequestPaymentFailure{ + Data: breez_sdk.ReportPaymentFailureDetails{ + PaymentHash: paymentHash, + }, + } + if err := sdk.ReportIssue(reportIssueRequest); err != nil { + log.Printf("%#v", err) + } + // ANCHOR_END: report-payment-failure +} diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ServiceStatus.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ServiceStatus.kt new file mode 100644 index 0000000..e5a88f3 --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ServiceStatus.kt @@ -0,0 +1,27 @@ +package com.example.kotlinmpplib + +import breez_sdk.* +class ConnectingLsp { + fun getServiceStatus(sdk: BlockingBreezServices) { + // ANCHOR: health-check-status + try { + val healthCheck = sdk.serviceHealthCheck() + // Log.v("Breez", "Current service status is: ${healthCheck.status}") + } catch (e: Exception) { + // Handle error + } + // ANCHOR_END: health-check-status + } + + fun reportPaymentFailure(sdk: BlockingBreezServices) { + // ANCHOR: report-payment-failure + val paymentHash = "..." + try { + sdk.reportIssue(ReportIssueRequest.PaymentFailure( + ReportPaymentFailureDetails(paymentHash))) + } catch (e: Exception) { + // Handle error + } + // ANCHOR_END: report-payment-failure + } +} \ No newline at end of file diff --git a/snippets/python/src/service_status.py b/snippets/python/src/service_status.py new file mode 100644 index 0000000..18e1187 --- /dev/null +++ b/snippets/python/src/service_status.py @@ -0,0 +1,23 @@ +import breez_sdk + +def health_check_status(sdk_services): + try: + # ANCHOR: health-check-status + health_check = sdk_services.service_health_check() + print("Current service status is: ", health_check.status) + # ANCHOR_END: health-check-status + except Exception as error: + print(error) + raise + +def report_payment_failure(sdk_services): + try: + # ANCHOR: report-payment-failure + payment_hash = "..." + sdk_services.report_issue( + breez_sdk.ReportIssueRequest.PAYMENT_FAILURE( + breez_sdk.ReportPaymentFailureDetails(payment_hash))) + # ANCHOR_END: report-payment-failure + except Exception as error: + print(error) + raise diff --git a/snippets/react-native/service_status.ts b/snippets/react-native/service_status.ts new file mode 100644 index 0000000..a358b5b --- /dev/null +++ b/snippets/react-native/service_status.ts @@ -0,0 +1,18 @@ +import { serviceHealthCheck, reportIssue, ReportIssueRequestVariant } from '@breeztech/react-native-breez-sdk' + +const healthCheckStatus = async () => { + // ANCHOR: health-check-status + const healthCheck = await serviceHealthCheck() + console.log(`Current service status is: ${healthCheck.status}`) + // ANCHOR_END: health-check-status +} + +const reportPaymentFailure = async () => { + // ANCHOR: report-payment-failure + const paymentHash = "..." + await reportIssue({ + type: ReportIssueRequestVariant.PAYMENT_FAILURE, + data: { paymentHash } + }) + // ANCHOR_END: report-payment-failure +} diff --git a/snippets/rust/src/main.rs b/snippets/rust/src/main.rs index 9c0d04e..5df75ef 100644 --- a/snippets/rust/src/main.rs +++ b/snippets/rust/src/main.rs @@ -11,6 +11,7 @@ mod receive_payment; mod send_onchain; mod send_payment; mod send_spontaneous_payment; +mod service_status; mod static_channel_backup; use anyhow::Result; diff --git a/snippets/rust/src/service_status.rs b/snippets/rust/src/service_status.rs new file mode 100644 index 0000000..afe6eb5 --- /dev/null +++ b/snippets/rust/src/service_status.rs @@ -0,0 +1,30 @@ +use std::sync::Arc; + +use anyhow::Result; +use breez_sdk_core::*; +use log::info; + +async fn health_check_status(sdk: Arc) -> Result<()> { + // ANCHOR: health-check-status + let health_check = sdk.service_health_check().await?; + info!("Current service status is: {:?}", health_check.status); + // ANCHOR_END: health-check-status + + Ok(()) +} + +async fn report_payment_failure(sdk: Arc) -> Result<()> { + // ANCHOR: report-payment-failure + let payment_hash = String::from("..."); + + sdk.report_issue(ReportIssueRequest::PaymentFailure { + data: ReportPaymentFailureDetails { + payment_hash, + comment: None, + }, + }) + .await?; + // ANCHOR_END: report-payment-failure + + Ok(()) +} diff --git a/snippets/swift/BreezSDKExamples/Sources/ServiceStatus.swift b/snippets/swift/BreezSDKExamples/Sources/ServiceStatus.swift new file mode 100644 index 0000000..67aea0d --- /dev/null +++ b/snippets/swift/BreezSDKExamples/Sources/ServiceStatus.swift @@ -0,0 +1,27 @@ +// +// ServiceStatus.swift +// +// +// Created by dangeross on 27/11/2023. +// + +import Foundation +import BreezSDK + +func getServiceStatus(sdk: BlockingBreezServices) -> ServiceHealthCheckResponse? { + // ANCHOR: health-check-status + let healthCheck = try? sdk.serviceHealthCheck() + print("Current service status is: \(healthCheck?.status)") + // ANCHOR_END: health-check-status + return healthCheck +} + +func reportPaymentFailure(sdk: BlockingBreezServices) { + // ANCHOR: report-payment-failure + let paymentHash = "..." + + try? sdk.reportIssue( + req: ReportIssueRequest.paymentFailure( + data: ReportPaymentFailureDetails(paymentHash: paymentHash))) + // ANCHOR_END: report-payment-failure +} diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 9d2fbb7..1949dc8 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -20,4 +20,5 @@ - [Supporting fiat currencies](guide/fiat_currencies.md) - [Buy Bitcoin](guide/buy_btc.md) - [Static Channel Backup](guide/static_channel_backup.md) +- [Service status](guide/service_status.md) - [Moving to production](guide/production.md) diff --git a/src/guide/service_status.md b/src/guide/service_status.md new file mode 100644 index 0000000..dfba30d --- /dev/null +++ b/src/guide/service_status.md @@ -0,0 +1,140 @@ +# Health Check Status + +You can check the general health status of the services providered by the Breez SDK. +The response status will inform you if there is maintenance occurring, a service distruption or the services are operational. + + +
Rust
+
+ +```rust,ignore +{{#include ../../snippets/rust/src/service_status.rs:health-check-status}} +``` +
+ +
Swift
+
+ +```swift,ignore +{{#include ../../snippets/swift/BreezSDKExamples/Sources/ServiceStatus.swift:health-check-status}} +``` +
+ +
Kotlin
+
+ +```kotlin,ignore +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ServiceStatus.kt:health-check-status}} +``` +
+ +
React Native
+
+ +```typescript +{{#include ../../snippets/react-native/service_status.ts:health-check-status}} +``` +
+ +
Dart
+
+ +```dart,ignore +{{#include ../../snippets/dart_snippets/lib/service_status.dart:health-check-status}} +``` +
+ +
Python
+
+ +```python,ignore +{{#include ../../snippets/python/src/service_status.py:health-check-status}} +``` +
+ +
Go
+
+ +```go,ignore +{{#include ../../snippets/go/service_status.go:health-check-status}} +``` +
+ +
C#
+
+ +```cs,ignore +{{#include ../../snippets/csharp/ServiceStatus.cs:health-check-status}} +``` +
+
+ +# Reporting a Payment Failure + +While attempting to send payments it may be that sometimes payment failures occur. Reporting these issues through the Breez SDK will help us to improve LSP routing. + + +
Rust
+
+ +```rust,ignore +{{#include ../../snippets/rust/src/service_status.rs:report-payment-failure}} +``` +
+ +
Swift
+
+ +```swift,ignore +{{#include ../../snippets/swift/BreezSDKExamples/Sources/ServiceStatus.swift:report-payment-failure}} +``` +
+ +
Kotlin
+
+ +```kotlin,ignore +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ServiceStatus.kt:report-payment-failure}} +``` +
+ +
React Native
+
+ +```typescript +{{#include ../../snippets/react-native/service_status.ts:report-payment-failure}} +``` +
+ +
Dart
+
+ +```dart,ignore +{{#include ../../snippets/dart_snippets/lib/service_status.dart:report-payment-failure}} +``` +
+ +
Python
+
+ +```python,ignore +{{#include ../../snippets/python/src/service_status.py:report-payment-failure}} +``` +
+ +
Go
+
+ +```go,ignore +{{#include ../../snippets/go/service_status.go:report-payment-failure}} +``` +
+ +
C#
+
+ +```cs,ignore +{{#include ../../snippets/csharp/ServiceStatus.cs:report-payment-failure}} +``` +
+