From 5de95fe2835e4a99291c96289a2cc06a94a669b8 Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Fri, 17 Nov 2023 14:32:47 +0100 Subject: [PATCH] Add list-lsps snippets --- snippets/csharp/ConnectingLsp.cs | 14 ++++ .../dart_snippets/lib/connecting_lsp.dart | 6 ++ snippets/go/connecting_lsp.go | 8 +++ .../com/example/kotlinmpplib/ConnectingLsp.kt | 9 +++ snippets/python/src/connecting_lsp.py | 9 +++ snippets/react-native/connecting_lsp.ts | 8 ++- snippets/rust/src/connecting_lsp.rs | 8 +++ .../Sources/ConnectingLsp.swift | 6 +- src/guide/connecting_lsp.md | 70 ++++++++++++++++++- 9 files changed, 135 insertions(+), 3 deletions(-) diff --git a/snippets/csharp/ConnectingLsp.cs b/snippets/csharp/ConnectingLsp.cs index 7981e3f..8e683a4 100644 --- a/snippets/csharp/ConnectingLsp.cs +++ b/snippets/csharp/ConnectingLsp.cs @@ -17,6 +17,20 @@ public class ConnectingLspSnippets // ANCHOR_END: get-lsp-info } + public void ListLsps(BlockingBreezServices sdk) + { + // ANCHOR: list-lsps + try + { + var availableLsps = sdk.ListLsps(); + } + catch (Exception) + { + // Handle error + } + // ANCHOR_END: list-lsps + } + public void ConnectLsp(BlockingBreezServices sdk, string? lspId) { // ANCHOR: connect-lsp diff --git a/snippets/dart_snippets/lib/connecting_lsp.dart b/snippets/dart_snippets/lib/connecting_lsp.dart index 3443741..4d911ef 100644 --- a/snippets/dart_snippets/lib/connecting_lsp.dart +++ b/snippets/dart_snippets/lib/connecting_lsp.dart @@ -10,6 +10,12 @@ Future getLspInfo() async { // ANCHOR_END: get-lsp-info } +Future listLsps() async { + // ANCHOR: list-lsps + List availableLsps = await BreezSDK().listLsps(); + // ANCHOR_END: list-lsps +} + Future connectLsp(String lspId) async { // ANCHOR: connect-lsp await BreezSDK().connectLSP(lspId); diff --git a/snippets/go/connecting_lsp.go b/snippets/go/connecting_lsp.go index 852aff3..2d735da 100644 --- a/snippets/go/connecting_lsp.go +++ b/snippets/go/connecting_lsp.go @@ -16,6 +16,14 @@ func GetLspInfo() { // ANCHOR_END: get-lsp-info } +func ListLsps() { + // ANCHOR: list-lsps + if err := sdk.ListLsps(); err != nil { + log.Printf("%#v", err) + } + // ANCHOR_END: list-lsps +} + func ConnectLsp() { // ANCHOR: connect-lsp lspId := "your selected lsp id" diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ConnectingLsp.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ConnectingLsp.kt index 8b99667..efd1ba2 100644 --- a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ConnectingLsp.kt +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ConnectingLsp.kt @@ -17,6 +17,15 @@ class ConnectingLsp { // ANCHOR_END: get-lsp-info } + fun list_lsps(sdk: BlockingBreezServices) { + // ANCHOR: list-lsps + try { + let availableLsps = sdk.listLsps() + } catch (e: Exception) { + // Handle error + } + // ANCHOR_END: list-lsps + } fun connect_lsp(sdk: BlockingBreezServices, lspId: String) { // ANCHOR: connect-lsp try { diff --git a/snippets/python/src/connecting_lsp.py b/snippets/python/src/connecting_lsp.py index d51aca2..d2bac09 100644 --- a/snippets/python/src/connecting_lsp.py +++ b/snippets/python/src/connecting_lsp.py @@ -10,6 +10,15 @@ def get_lsp_info(sdk_services): print(error) raise +def list_lsps(sdk_services): + try: + # ANCHOR: list-lsps + available_lsps = sdk_services.list_lsps() + # ANCHOR_END: list-lsps + except Exception as error: + print(error) + raise + def connect_lsp(sdk_services,lsp_id): try: # ANCHOR: connect-lsp diff --git a/snippets/react-native/connecting_lsp.ts b/snippets/react-native/connecting_lsp.ts index 094a05a..e5497d7 100644 --- a/snippets/react-native/connecting_lsp.ts +++ b/snippets/react-native/connecting_lsp.ts @@ -1,4 +1,4 @@ -import { connectLsp, lspId, lspInfo } from '@breeztech/react-native-breez-sdk' +import { connectLsp, listLsps, lspId, lspInfo } from '@breeztech/react-native-breez-sdk' const exampleAutoConnect = async () => { // ANCHOR: get-lsp-info @@ -7,6 +7,12 @@ const exampleAutoConnect = async () => { // ANCHOR_END: get-lsp-info } +const exampleListLsps = async () => { + // ANCHOR: list-lsps + const availableLsps = await listLsps() + // ANCHOR_END: list-lsps +} + const exampleManualConnect = async () => { // ANCHOR: connect-lsp const id = 'your selected lsp id' diff --git a/snippets/rust/src/connecting_lsp.rs b/snippets/rust/src/connecting_lsp.rs index ae5cc71..58b2657 100644 --- a/snippets/rust/src/connecting_lsp.rs +++ b/snippets/rust/src/connecting_lsp.rs @@ -12,6 +12,14 @@ async fn get_lsp_info(sdk: Arc) -> Result { Ok(lsp_info) } +async fn list_lsps(sdk: Arc) -> Result<()> { + // ANCHOR: list-lsps + let available_lsps = sdk.list_lsps().await?; + // ANCHOR_END: list-lsps + + Ok(()) +} + async fn connect_lsp(sdk: Arc, lsp_id: String) -> Result<()> { // ANCHOR: connect-lsp sdk.connect_lsp(lsp_id).await?; diff --git a/snippets/swift/BreezSDKExamples/Sources/ConnectingLsp.swift b/snippets/swift/BreezSDKExamples/Sources/ConnectingLsp.swift index 367c9c5..636269c 100644 --- a/snippets/swift/BreezSDKExamples/Sources/ConnectingLsp.swift +++ b/snippets/swift/BreezSDKExamples/Sources/ConnectingLsp.swift @@ -16,10 +16,14 @@ func getLspInfo(sdk: BlockingBreezServices) -> LspInformation?{ return lspInfo } +func listLsps(sdk: BlockingBreezServices) { + // ANCHOR: list-lsps + let availableLsps = try? sdk.listLsps() + // ANCHOR_END: list-lsps +} func connectLsp(sdk: BlockingBreezServices, lspId: String) { // ANCHOR: connect-lsp try? sdk.connectLsp(lspId: lspId) // ANCHOR_END: connect-lsp - } diff --git a/src/guide/connecting_lsp.md b/src/guide/connecting_lsp.md index 073cc4c..e6e123c 100644 --- a/src/guide/connecting_lsp.md +++ b/src/guide/connecting_lsp.md @@ -68,7 +68,75 @@ Based on the API key provided to the Breez SDK, a default LSP is selected for yo -When you have selected an LSP you may then connect to it. +In order to list all available LSPs you may connect to, you may do the following: + + +
Rust
+
+ +```rust,ignore +{{#include ../../snippets/rust/src/connecting_lsp.rs:list-lsps}} +``` +
+ +
Swift
+
+ +```swift,ignore +{{#include ../../snippets/swift/BreezSDKExamples/Sources/ConnectingLsp.swift:list-lsps}} +``` +
+ +
Kotlin
+
+ +```kotlin,ignore +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ConnectingLsp.kt:list-lsps}} +``` +
+ +
React Native
+
+ +```typescript +{{#include ../../snippets/react-native/connecting_lsp.ts:list-lsps}} +``` +
+ +
Dart
+
+ +```dart,ignore +{{#include ../../snippets/dart_snippets/lib/connecting_lsp.dart:list-lsps}} +``` +
+ +
Python
+
+ +```python,ignore +{{#include ../../snippets/python/src/connecting_lsp.py:list-lsps}} +``` +
+ +
Go
+
+ +```go,ignore +{{#include ../../snippets/go/connecting_lsp.go:list-lsps}} +``` +
+ +
C#
+
+ +```cs,ignore +{{#include ../../snippets/csharp/ConnectingLsp.cs:list-lsps}} +``` +
+
+ +When you have selected an LSP you may then connect to it:
Rust