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/csharp/FiatCurrencies.cs b/snippets/csharp/FiatCurrencies.cs index 7ceced3..41acdbc 100644 --- a/snippets/csharp/FiatCurrencies.cs +++ b/snippets/csharp/FiatCurrencies.cs @@ -29,11 +29,4 @@ public class FiatCurrenciesSnippets } // ANCHOR_END: fetch-fiat-rates } - - public void GetFiatCurrenciesAndRates(BlockingBreezServices sdk) - { - // ANCHOR: get-fiat-currencies-and-rates - // TODO - // ANCHOR_END: get-fiat-currencies-and-rates - } } diff --git a/snippets/dart_snippets/lib/connecting_lsp.dart b/snippets/dart_snippets/lib/connecting_lsp.dart index 3443741..5a8b61c 100644 --- a/snippets/dart_snippets/lib/connecting_lsp.dart +++ b/snippets/dart_snippets/lib/connecting_lsp.dart @@ -10,6 +10,13 @@ Future getLspInfo() async { // ANCHOR_END: get-lsp-info } +Future> listLsps() async { + // ANCHOR: list-lsps + List availableLsps = await BreezSDK().listLsps(); + // ANCHOR_END: list-lsps + return availableLsps; +} + Future connectLsp(String lspId) async { // ANCHOR: connect-lsp await BreezSDK().connectLSP(lspId); diff --git a/snippets/dart_snippets/lib/fiat_currencies.dart b/snippets/dart_snippets/lib/fiat_currencies.dart index 9d2c4b0..9de0f5c 100644 --- a/snippets/dart_snippets/lib/fiat_currencies.dart +++ b/snippets/dart_snippets/lib/fiat_currencies.dart @@ -16,25 +16,3 @@ Future> fetchFiatRates(String lspId) async { // ANCHOR_END: fetch-fiat-rates return fiatRatesMap; } - -Future> fiatCurrenciesAndRate() async { - // ANCHOR: get-fiat-currencies-and-rates - List fiatCurrencies = await BreezSDK().listFiatCurrencies(); - Map fiatRates = await BreezSDK().fetchFiatRates(); - - var sorted = fiatCurrencies.toList(); - sorted.sort((f1, f2) { - return f1.id.compareTo(f2.id); - }); - - Map result = {}; - for (var currency in sorted) { - var rate = fiatRates[currency.id]; - if (rate != null) { - result[currency] = rate; - } - } - - return result; - // ANCHOR_END: get-fiat-currencies-and-rates -} diff --git a/snippets/go/connecting_lsp.go b/snippets/go/connecting_lsp.go index 852aff3..e9ccce3 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 lspList, err := sdk.ListLsps(); err == nil { + log.Printf("%#v", lspList) + } + // ANCHOR_END: list-lsps +} + func ConnectLsp() { // ANCHOR: connect-lsp lspId := "your selected lsp id" diff --git a/snippets/go/fiat_currencies.go b/snippets/go/fiat_currencies.go index 28ee688..5e2ffe8 100644 --- a/snippets/go/fiat_currencies.go +++ b/snippets/go/fiat_currencies.go @@ -19,9 +19,3 @@ func FetchFiatRates() { } // ANCHOR_END: fetch-fiat-rates } - -func GetFiatCurrenciesAndRates() { - // ANCHOR: get-fiat-currencies-and-rates - // TODO - // ANCHOR_END: get-fiat-currencies-and-rates -} diff --git a/snippets/kotlin_mpp_lib/.gitignore b/snippets/kotlin_mpp_lib/.gitignore new file mode 100644 index 0000000..e510fa9 --- /dev/null +++ b/snippets/kotlin_mpp_lib/.gitignore @@ -0,0 +1,10 @@ +*.iml +.gradle +.idea +.DS_Store +build +captures +.externalNativeBuild +.cxx +local.properties +xcuserdata \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/README.md b/snippets/kotlin_mpp_lib/README.md new file mode 100644 index 0000000..f7822a6 --- /dev/null +++ b/snippets/kotlin_mpp_lib/README.md @@ -0,0 +1,6 @@ +## Steps to compile the snippets locally + +```bash +cd snippets/kotlin_mpp_lib/ +./gradlew build +``` \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/build.gradle.kts b/snippets/kotlin_mpp_lib/build.gradle.kts new file mode 100644 index 0000000..dc0608f --- /dev/null +++ b/snippets/kotlin_mpp_lib/build.gradle.kts @@ -0,0 +1,6 @@ +plugins { + //trick: for the same plugin versions in all sub-modules + alias(libs.plugins.androidLibrary).apply(false) + alias(libs.plugins.kotlinMultiplatform).apply(false) + id("org.jetbrains.kotlin.android") version "1.9.20" apply false +} diff --git a/snippets/kotlin_mpp_lib/gradle.properties b/snippets/kotlin_mpp_lib/gradle.properties new file mode 100644 index 0000000..7f53ad4 --- /dev/null +++ b/snippets/kotlin_mpp_lib/gradle.properties @@ -0,0 +1,11 @@ +#Gradle +org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M" +org.gradle.caching=true +org.gradle.configuration-cache=true + +#Kotlin +kotlin.code.style=official + +#Android +android.useAndroidX=true +android.nonTransitiveRClass=true \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/gradle/libs.versions.toml b/snippets/kotlin_mpp_lib/gradle/libs.versions.toml new file mode 100644 index 0000000..0203aee --- /dev/null +++ b/snippets/kotlin_mpp_lib/gradle/libs.versions.toml @@ -0,0 +1,24 @@ +[versions] +agp = "8.1.2" +kotlin = "1.9.20" +compose = "1.5.4" +compose-compiler = "1.5.4" +compose-material3 = "1.1.2" +androidx-activityCompose = "1.8.0" + +[libraries] +breez = { module = "technology.breez:breez-sdk-kmp", version = "0.2.9" } +kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } +androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } +compose-ui = { module = "androidx.compose.ui:ui", version.ref = "compose" } +compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" } +compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" } +compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "compose" } +compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "compose-material3" } + +[plugins] +androidApplication = { id = "com.android.application", version.ref = "agp" } +androidLibrary = { id = "com.android.library", version.ref = "agp" } +kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +kotlinCocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" } diff --git a/snippets/kotlin_mpp_lib/gradle/wrapper/gradle-wrapper.jar b/snippets/kotlin_mpp_lib/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e708b1c Binary files /dev/null and b/snippets/kotlin_mpp_lib/gradle/wrapper/gradle-wrapper.jar differ diff --git a/snippets/kotlin_mpp_lib/gradle/wrapper/gradle-wrapper.properties b/snippets/kotlin_mpp_lib/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..3c87baa --- /dev/null +++ b/snippets/kotlin_mpp_lib/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Tue Nov 14 14:40:53 CET 2023 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/snippets/kotlin_mpp_lib/gradlew b/snippets/kotlin_mpp_lib/gradlew new file mode 100755 index 0000000..4f906e0 --- /dev/null +++ b/snippets/kotlin_mpp_lib/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/snippets/kotlin_mpp_lib/gradlew.bat b/snippets/kotlin_mpp_lib/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/snippets/kotlin_mpp_lib/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/snippets/kotlin_mpp_lib/settings.gradle.kts b/snippets/kotlin_mpp_lib/settings.gradle.kts new file mode 100644 index 0000000..b3f29f3 --- /dev/null +++ b/snippets/kotlin_mpp_lib/settings.gradle.kts @@ -0,0 +1,20 @@ +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") +pluginManagement { + repositories { + google() + gradlePluginPortal() + mavenCentral() + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + maven("https://mvn.breez.technology/releases") + } +} + +rootProject.name = "Kotlin_MPP_Lib" +include(":shared") \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/shared/build.gradle.kts b/snippets/kotlin_mpp_lib/shared/build.gradle.kts new file mode 100644 index 0000000..f10fdbe --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/build.gradle.kts @@ -0,0 +1,49 @@ +plugins { + alias(libs.plugins.kotlinMultiplatform) + alias(libs.plugins.androidLibrary) +} + +kotlin { + androidTarget { + compilations.all { + kotlinOptions { + jvmTarget = "1.8" + } + } + } + + listOf( + iosX64(), + iosArm64(), + iosSimulatorArm64() + ).forEach { + it.binaries.framework { + baseName = "shared" + isStatic = true + } + } + + sourceSets { + commonMain.dependencies { + //put your multiplatform dependencies here + implementation(libs.breez) + + } + commonTest.dependencies { + implementation(libs.kotlin.test) + } + } +} + +android { + namespace = "com.example.kotlinmpplib" + compileSdk = 34 + defaultConfig { + minSdk = 34 + } +} + +dependencies { + implementation(libs.breez) + implementation("androidx.core:core-ktx:+") +} \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/BuyBtc.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/BuyBtc.kt new file mode 100644 index 0000000..4d0ea20 --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/BuyBtc.kt @@ -0,0 +1,18 @@ +package com.example.kotlinmpplib + +import breez_sdk.* + +class BuyBtc { + fun buy_btc(sdk: BlockingBreezServices) { + // ANCHOR: buy-btc + try { + // Choose your provider + val provider = BuyBitcoinProvider.MOONPAY + // request the url to proceed with the Bitcoin acquisition + val url = sdk.buyBitcoin(BuyBitcoinRequest(provider)).url + } catch (e: Exception) { + // Handle error + } + // ANCHOR_END: buy-btc + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..efd1ba2 --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ConnectingLsp.kt @@ -0,0 +1,38 @@ +package com.example.kotlinmpplib + +import breez_sdk.* +class ConnectingLsp { + fun get_lsp_info(sdk: BlockingBreezServices) { + // ANCHOR: get-lsp-info + try { + val lspId = sdk.lspId() + if (lspId != null) { + val lspInfo = sdk.lspInfo() + } else { + // Handle no lsp id scenario + } + } catch (e: Exception) { + // Handle error + } + // 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 { + sdk.connectLsp(lspId) + } catch (e: Exception) { + // Handle error + } + // ANCHOR_END: connect-lsp + } +} \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/FiatCurrencies.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/FiatCurrencies.kt new file mode 100644 index 0000000..e80b001 --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/FiatCurrencies.kt @@ -0,0 +1,25 @@ +package com.example.kotlinmpplib + +import breez_sdk.* + +class FiatCurrencies { + fun list_fiat_currencies(sdk: BlockingBreezServices) { + // ANCHOR: list-fiat-currencies + try { + val fiatCurrencyList = sdk.listFiatCurrencies() + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: list-fiat-currencies + } + + fun fetch_fiat_rates(sdk: BlockingBreezServices) { + // ANCHOR: fetch-fiat-rates + try { + val fiatRatesMap = sdk.fetchFiatRates() + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: fetch-fiat-rates + } +} \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/GettingStarted.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/GettingStarted.kt new file mode 100644 index 0000000..8c85d7e --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/GettingStarted.kt @@ -0,0 +1,47 @@ +package com.example.kotlinmpplib + +import breez_sdk.* +class GettingStarted { + fun start() { + // ANCHOR: init-sdk + // SDK events listener + class SDKListener : EventListener { + override fun onEvent(e: BreezEvent) { + // Log.v("SDKListener", "Received event $e") + } + } + + // Select your seed, invite code and eviroment + val seed = mnemonicToSeed("") + val inviteCode = "" + val apiKey = "" + + // Create the default config + val greenlightNodeConfig = GreenlightNodeConfig(null, inviteCode) + val nodeConfig = NodeConfig.Greenlight(greenlightNodeConfig) + val config = defaultConfig(EnvironmentType.PRODUCTION, apiKey, nodeConfig) + + // Customize the config object according to your needs + config.workingDir = "path to an existing directory" + + try { + // Connect to the Breez SDK make it ready for use + val sdk = connect(config, seed, SDKListener()) + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: init-sdk + } + + fun fetch_balance(sdk: BlockingBreezServices) { + // ANCHOR: fetch-balance + try { + val nodeInfo = sdk.nodeInfo() + val lnBalance = nodeInfo?.channelsBalanceMsat + val onchainBalance = nodeInfo?.onchainBalanceMsat + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: fetch-balance + } +} \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ListPayments.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ListPayments.kt new file mode 100644 index 0000000..9b6bf5a --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ListPayments.kt @@ -0,0 +1,29 @@ +package com.example.kotlinmpplib + +import breez_sdk.* +class ListPayments { + fun list_payments(sdk: BlockingBreezServices) { + // ANCHOR: list-payments + try { + val payments = sdk.listPayments(ListPaymentsRequest()) + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: list-payments + } + + fun list_payments_filtered(sdk: BlockingBreezServices) { + // ANCHOR: list-payments-filtered + try { + val payments = sdk.listPayments( + ListPaymentsRequest( + listOf(PaymentTypeFilter.SENT), + fromTimestamp = 1696880000, + includeFailures = true + )) + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: list-payments-filtered + } +} \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/LnurlAuth.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/LnurlAuth.kt new file mode 100644 index 0000000..c25a10f --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/LnurlAuth.kt @@ -0,0 +1,23 @@ +package com.example.kotlinmpplib + +import breez_sdk.* +class LnurlAuth { + fun lnurl_auth(sdk: BlockingBreezServices) { + // ANCHOR: lnurl-auth + // Endpoint can also be of the form: + // keyauth://domain.com/auth?key=val + val lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7..." + try { + val inputType = parseInput(lnurlAuthUrl) + if (inputType is InputType.LnUrlAuth) { + when (val result = sdk.lnurlAuth(inputType.data)) { + is LnUrlCallbackStatus.Ok -> {} // Log.v("Breez", "Successfully authenticated") + is LnUrlCallbackStatus.ErrorStatus -> {} // Log.v("Breez", "Failed to authenticate: ${result.data.reason}") + } + } + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: lnurl-auth + } +} \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/LnurlPay.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/LnurlPay.kt new file mode 100644 index 0000000..3054a76 --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/LnurlPay.kt @@ -0,0 +1,23 @@ +package com.example.kotlinmpplib + +import breez_sdk.* +class LnurlPay { + fun lnurl_pay(sdk: BlockingBreezServices) { + // ANCHOR: lnurl-pay + // Endpoint can also be of the form: + // lnurlp://domain.com/lnurl-pay?key=val + // lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf + val lnurlPayUrl = "lightning@address.com"; + try { + val inputType = parseInput(lnurlPayUrl) + if (inputType is InputType.LnUrlPay) { + val requestData = inputType.data + val amountMsat = requestData.minSendable + sdk.payLnurl(LnUrlPayRequest(requestData, amountMsat, "comment")) + } + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: lnurl-pay + } +} \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/LnurlWithdraw.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/LnurlWithdraw.kt new file mode 100644 index 0000000..4f3f7e8 --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/LnurlWithdraw.kt @@ -0,0 +1,23 @@ +package com.example.kotlinmpplib + +import breez_sdk.* +class LnurlWithdraw { + fun lnurl_withdraw(sdk: BlockingBreezServices) { + // ANCHOR: lnurl-withdraw + // Endpoint can also be of the form: + // lnurlw://domain.com/lnurl-withdraw?key=val + val lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7..." + try { + val inputType = parseInput(lnurlWithdrawUrl) + if (inputType is InputType.LnUrlWithdraw) { + val requestData = inputType.data + val amountMsat = requestData.minWithdrawable + val comment = "Any comment" + sdk.withdrawLnurl(LnUrlWithdrawRequest(requestData, amountMsat, comment)) + } + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: lnurl-withdraw + } +} \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt new file mode 100644 index 0000000..aaf3f45 --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt @@ -0,0 +1,60 @@ +package com.example.kotlinmpplib + +import breez_sdk.* +class ReceiveOnchain { + fun generate_receive_onchain_address(sdk: BlockingBreezServices) { + // ANCHOR: generate-receive-onchain-address + try { + val swapInfo = sdk.receiveOnchain(ReceiveOnchainRequest()) + // Send your funds to the bellow bitcoin address + val address = swapInfo.bitcoinAddress + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: generate-receive-onchain-address + } + + fun in_progress_swap(sdk: BlockingBreezServices) { + // ANCHOR: in-progress-swap + try { + val swapInfo = sdk.inProgressSwap() + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: in-progress-swap + } + + fun list_refundables(sdk: BlockingBreezServices) { + // ANCHOR: list-refundables + try { + val refundables = sdk.listRefundables() + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: list-refundables + } + + fun execute_refund(sdk: BlockingBreezServices) { + // ANCHOR: execute-refund + val swapAddress = "..." + val toAddress = "..." + val satPerVbyte = 1.toUInt() + try { + sdk.refund(RefundRequest(swapAddress, toAddress, satPerVbyte)) + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: execute-refund + } + + fun get_channel_opening_fees(sdk: BlockingBreezServices) { + // ANCHOR: get-channel-opening-fees + try { + val amountMsat = 5_000.toULong(); + val channelFees = sdk.openChannelFee(OpenChannelFeeRequest(amountMsat)) + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: get-channel-opening-fees + } +} \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceivePayment.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceivePayment.kt new file mode 100644 index 0000000..946ef7a --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceivePayment.kt @@ -0,0 +1,17 @@ +package com.example.kotlinmpplib + +import breez_sdk.* +class ReceivePayment { + fun receive_payment(sdk: BlockingBreezServices) { + // ANCHOR: receive-payment + try { + val invoice = sdk.receivePayment(ReceivePaymentRequest( + 3_000_000.toULong(), + "Invoice for 3000 sats", + )) + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: receive-payment + } +} \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendOnchain.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendOnchain.kt new file mode 100644 index 0000000..36987af --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendOnchain.kt @@ -0,0 +1,43 @@ +package com.example.kotlinmpplib + +import breez_sdk.* +class SendOnchain { + fun estimate_current_rev_swap_fees(sdk: BlockingBreezServices) { + // ANCHOR: estimate-current-reverse-swap-total-fees + try { + val fees = sdk.fetchReverseSwapFees(ReverseSwapFeesRequest(50_000_u)) + // Log.v("Breez", "Total estimated fees for reverse swap: ${fees.totalEstimatedFees}") + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: estimate-current-reverse-swap-total-fees + } + + fun get_current_rev_swap_min_max(sdk: BlockingBreezServices, fees: ReverseSwapPairInfo) { + // ANCHOR: get-current-reverse-swap-min-max + // Log.v("Breez", "Minimum amount, in sats: ${fees.min}") + // Log.v("Breez", "Maximum amount, in sats: ${fees.max}") + // ANCHOR_END: get-current-reverse-swap-min-max + } + + fun start_reverse_swap(sdk: BlockingBreezServices, fees: ReverseSwapPairInfo) { + // ANCHOR: start-reverse-swap + val address = "bc1.." + val amountSat = 123.toULong() + val satPerVbyte = 1.toUInt() + try { + sdk.sendOnchain(SendOnchainRequest(amountSat, address, fees.feesHash, satPerVbyte)) + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: start-reverse-swap + } + + fun check_rev_swap_status(sdk: BlockingBreezServices) { + // ANCHOR: check-reverse-swaps-status + for (rs in sdk.inProgressReverseSwaps()) { + // Log.v("Breez", "Reverse swap ${rs.id} in progress, status is ${rs.status}") + } + // ANCHOR_END: check-reverse-swaps-status + } +} \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendPayment.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendPayment.kt new file mode 100644 index 0000000..a9af7f4 --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendPayment.kt @@ -0,0 +1,19 @@ +package com.example.kotlinmpplib + +import breez_sdk.* +class SendPayment { + fun send_payment(sdk: BlockingBreezServices) { + // ANCHOR: send-payment + val bolt11 = "..." + try { + // The `amountMsat` param is optional and should only passed if the bolt11 doesn't specify an amount. + // The amountMsat is required in case an amount is not specified in the bolt11 invoice'. + val amountMsat = 3_000_000.toULong() + val req = SendPaymentRequest(bolt11, amountMsat) + val response = sdk.sendPayment(req) + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: send-payment + } +} \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendSpontaneousPayment.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendSpontaneousPayment.kt new file mode 100644 index 0000000..1d0948f --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendSpontaneousPayment.kt @@ -0,0 +1,17 @@ +package com.example.kotlinmpplib + +import breez_sdk.* +class SendSpontaneousPayment { + fun send_spontaneous_payment(sdk: BlockingBreezServices) { + // ANCHOR: send-spontaneous-payment + val nodeId = "..." + val amountMsat = 3_000_000.toULong() + try { + val response = sdk.sendSpontaneousPayment( + SendSpontaneousPaymentRequest(nodeId, amountMsat)) + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: send-spontaneous-payment + } +} \ No newline at end of file diff --git a/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/StaticChannelBackup.kt b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/StaticChannelBackup.kt new file mode 100644 index 0000000..748cc9a --- /dev/null +++ b/snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/StaticChannelBackup.kt @@ -0,0 +1,14 @@ +package com.example.kotlinmpplib + +import breez_sdk.* +class StaticChannelBackup { + fun backup(sdk: BlockingBreezServices) { + // ANCHOR: static-channel-backup + try { + val backupData = staticBackup(StaticBackupRequest("")) + } catch (e: Exception) { + // handle error + } + // ANCHOR_END: static-channel-backup + } +} \ No newline at end of file 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/react-native/fiat_currencies.ts b/snippets/react-native/fiat_currencies.ts index 5ed40ea..d318100 100644 --- a/snippets/react-native/fiat_currencies.ts +++ b/snippets/react-native/fiat_currencies.ts @@ -14,9 +14,3 @@ const exampleFetchRates = async () => { const fiatRates = await fetchFiatRates() // ANCHOR_END: fetch-fiat-rates } - -const exampleListCurrenciesAndRates = async () => { - // ANCHOR: get-fiat-currencies-and-rates - // TODO - // ANCHOR_END: get-fiat-currencies-and-rates -} 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/rust/src/fiat_currencies.rs b/snippets/rust/src/fiat_currencies.rs index d7151dc..674ad81 100644 --- a/snippets/rust/src/fiat_currencies.rs +++ b/snippets/rust/src/fiat_currencies.rs @@ -1,4 +1,3 @@ -use std::collections::HashMap; use std::sync::Arc; use anyhow::Result; @@ -19,30 +18,3 @@ async fn get_current_rates(sdk: Arc) -> Result<()> { Ok(()) } - -async fn get_fiat_currencies_and_rates( - sdk: Arc, -) -> Result> { - // ANCHOR: get-fiat-currencies-and-rates - let supported_fiat_currencies = sdk.list_fiat_currencies().await?; - let fiat_rates = sdk.fetch_fiat_rates().await?; - - let mut rates_map: HashMap = HashMap::new(); - for rate in fiat_rates { - rates_map.insert(rate.coin.to_string().to_lowercase(), rate); - } - - let mut sorted = supported_fiat_currencies.clone(); - sorted.sort_by_key(|f| f.info.name.clone()); - - let mut result: Vec<(FiatCurrency, Rate)> = Vec::new(); - for currency in sorted { - let rate = rates_map.get(¤cy.id.to_lowercase()); - if let Some(rate) = rate.cloned() { - result.push((currency, rate)); - } - } - - Ok(result) - // ANCHOR_END: get-fiat-currencies-and-rates -} diff --git a/snippets/swift/BreezSDKExamples/Sources/ConnectingLsp.swift b/snippets/swift/BreezSDKExamples/Sources/ConnectingLsp.swift index 367c9c5..9dcfb9a 100644 --- a/snippets/swift/BreezSDKExamples/Sources/ConnectingLsp.swift +++ b/snippets/swift/BreezSDKExamples/Sources/ConnectingLsp.swift @@ -16,10 +16,15 @@ func getLspInfo(sdk: BlockingBreezServices) -> LspInformation?{ return lspInfo } +func listLsps(sdk: BlockingBreezServices) -> [LspInformation]? { + // ANCHOR: list-lsps + let availableLsps = try? sdk.listLsps() + // ANCHOR_END: list-lsps + return availableLsps +} func connectLsp(sdk: BlockingBreezServices, lspId: String) { // ANCHOR: connect-lsp try? sdk.connectLsp(lspId: lspId) // ANCHOR_END: connect-lsp - } diff --git a/snippets/swift/BreezSDKExamples/Sources/FiatCurrencies.swift b/snippets/swift/BreezSDKExamples/Sources/FiatCurrencies.swift index bdca755..792f560 100644 --- a/snippets/swift/BreezSDKExamples/Sources/FiatCurrencies.swift +++ b/snippets/swift/BreezSDKExamples/Sources/FiatCurrencies.swift @@ -21,28 +21,3 @@ func getCurrentRates(sdk:BlockingBreezServices) -> [Rate]? { // ANCHOR_END: fetch-fiat-rates return fiatRates } - -func getFiatCurrencyAndRates(sdk: BlockingBreezServices) -> [(FiatCurrency,Rate)]? { - // ANCHOR: get-fiat-currencies-and-rates - var ratesMap = [String:Rate]() - if let supportedFiatCurrencies = try? sdk.listFiatCurrencies(), let fiatRates = try? sdk.fetchFiatRates() { - for fiatRate in fiatRates { - ratesMap[fiatRate.coin.lowercased()] = fiatRate - } - - let sorted = supportedFiatCurrencies.sorted(by: { f1, f2 in - f1.id ```kotlin,ignore -try { - // Choose your provider - val provider = BuyBitcoinProvider.MOONPAY - // request the url to proceed with the Bitcoin acquisition - val url = sdk.buyBitcoin(BuyBitcoinRequest(provider)).url - // Opens the url in the browser to buy on provider's site - startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) -} catch (e: Exception) { - // Handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/BuyBtc.kt:buy-btc}} ``` diff --git a/src/guide/connecting_lsp.md b/src/guide/connecting_lsp.md index 98e68fd..e6e123c 100644 --- a/src/guide/connecting_lsp.md +++ b/src/guide/connecting_lsp.md @@ -23,16 +23,7 @@ Based on the API key provided to the Breez SDK, a default LSP is selected for yo
```kotlin,ignore -try { - val lspId = sdk.lspId() - if (lspId != null) { - val lspInfo = sdk.lspInfo() - } else { - // Handle no lsp id scenario - } -} catch (e: Exception) { - // Handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ConnectingLsp.kt:get-lsp-info}} ```
@@ -77,7 +68,75 @@ try { -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
@@ -100,11 +159,7 @@ When you have selected an LSP you may then connect to it.
```kotlin,ignore -try { - sdk.connectLsp(lspId) -} catch (e: Exception) { - // Handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ConnectingLsp.kt:connect-lsp}} ```
diff --git a/src/guide/fiat_currencies.md b/src/guide/fiat_currencies.md index ea0e8ce..e41181e 100644 --- a/src/guide/fiat_currencies.md +++ b/src/guide/fiat_currencies.md @@ -1,6 +1,6 @@ # Supporting fiat currencies -In order to list the available fiat currencies: +You can get the full details of supported fiat currencies, such as symbols and localized names:
Rust
@@ -23,11 +23,7 @@ In order to list the available fiat currencies:
```kotlin,ignore -try { - val fiatCurrencyList = sdk.listFiatCurrencies() -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/FiatCurrencies.kt:list-fiat-currencies}} ```
@@ -72,7 +68,7 @@ try {
-To get the current BTC rate for the currencies: +To get the current BTC rate in the various supported fiat currencies:
Rust
@@ -95,11 +91,7 @@ To get the current BTC rate for the currencies:
```kotlin,ignore -try { - val fiatRatesMap = sdk.fetchFiatRates() -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/FiatCurrencies.kt:fetch-fiat-rates}} ```
@@ -123,11 +115,7 @@ try {
```python,ignore -try: - fiat_rates = sdk_services.fetch_fiat_rates() - # print your desired rate -except Exception as error: - # Handle error +{{#include ../../snippets/python/src/fiat_currencies.py:fetch-fiat-rates}} ```
@@ -147,93 +135,3 @@ except Exception as error: ```
- -At the example project you can see these methods combined: - - -
Rust
-
- -```rust,ignore -{{#include ../../snippets/rust/src/fiat_currencies.rs:get-fiat-currencies-and-rates}} -``` -
- -
Swift
-
- -```swift,ignore -{{#include ../../snippets/swift/BreezSDKExamples/Sources/FiatCurrencies.swift:get-fiat-currencies-and-rates}} -``` -
- -
Kotlin
-
- -```kotlin,ignore -fun fiatCurrenciesAndRate(): Map = try { - val fiatCurrencies = sdk.listFiatCurrencies() - val fiatRates = sdk.fetchFiatRates() - - val ratesMap = mutableMapOf() - for (rate in fiatRates) { - ratesMap[rate.coin.lowercase()] = rate - } - - val sorted = fiatCurrencies.sortedBy { it.info.name } - val result = LinkedHashMap() - for (currency in sorted) { - val rate = ratesMap[currency.id.lowercase()] - if (rate != null) { - result[currency] = rate - } - } - - result -} catch (e: Throwable) { - // Handle error - emptyMap() -} -``` -
- -
React Native
-
- -```typescript -{{#include ../../snippets/react-native/fiat_currencies.ts:get-fiat-currencies-and-rates}} -``` -
- -
Dart
-
- -```dart,ignore -{{#include ../../snippets/dart_snippets/lib/fiat_currencies.dart:get-fiat-currencies-and-rates}} -``` -
- -
Python
-
- -```python,ignore -# TODO -``` -
- -
Go
-
- -```go,ignore -{{#include ../../snippets/go/fiat_currencies.go:get-fiat-currencies-and-rates}} -``` -
- -
C#
-
- -```cs,ignore -{{#include ../../snippets/csharp/FiatCurrencies.cs:get-fiat-currencies-and-rates}} -``` -
-
\ No newline at end of file diff --git a/src/guide/getting_started.md b/src/guide/getting_started.md index 4386d3e..423fdbc 100644 --- a/src/guide/getting_started.md +++ b/src/guide/getting_started.md @@ -60,32 +60,7 @@ Now you are ready to interact with the SDK.
```kotlin,ignore -// SDK events listener -class SDKListener : EventListener { - override fun onEvent(e: BreezEvent) { - Log.v("SDKListener", "Received event $e") - } -} - -// Select your seed, invite code and eviroment -val seed = mnemonicToSeed("") -val inviteCode = "" -val apiKey = "" - -// Create the default config -val greenlightNodeConfig = GreenlightNodeConfig(null, inviteCode) -val nodeConfig = NodeConfig.Greenlight(greenlightNodeConfig) -val config = defaultConfig(EnvironmentType.PRODUCTION, apiKey, nodeConfig) - -// Customize the config object according to your needs -config.workingDir = "path to an existing directory" - -try { - // Connect to the Breez SDK make it ready for use - val sdk = connect(config, seed, SDKListener()) -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/GettingStarted.kt:init-sdk}} ```
@@ -155,13 +130,7 @@ At any point we can fetch our balance from the Greenlight node:
```kotlin,ignore -try { - val nodeInfo = sdk.nodeInfo() - val lnBalance = nodeInfo?.channelsBalanceMsat - val onchainBalance = nodeInfo?.onchainBalanceMsat -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/GettingStarted.kt:fetch-balance}} ```
diff --git a/src/guide/list_payments.md b/src/guide/list_payments.md index 29f8aaf..6c996dc 100644 --- a/src/guide/list_payments.md +++ b/src/guide/list_payments.md @@ -23,11 +23,7 @@ To view your payment history you can list and filter all the sent and received p
```kotlin,ignore -try { - val payments = sdk.listPayments(ListPaymentsRequest(PaymentTypeFilter.ALL)) -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ListPayments.kt:list-payments}} ```
@@ -95,11 +91,7 @@ You can optionally filter payments by timestamp and include failed payments.
```kotlin,ignore -try { - val payments = sdk.listPayments(ListPaymentsRequest(PaymentTypeFilter.SENT, fromTimestamp = 1696880000, includeFailures = true)) -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ListPayments.kt:list-payments-filtered}} ```
diff --git a/src/guide/lnurl_auth.md b/src/guide/lnurl_auth.md index 2d93a93..899f0f9 100644 --- a/src/guide/lnurl_auth.md +++ b/src/guide/lnurl_auth.md @@ -22,21 +22,7 @@
```kotlin,ignore -// Endpoint can also be of the form: -// keyauth://domain.com/auth?key=val -// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7… -val lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7…" -try { - val inputType = parseInput(lnurlPayUrl) - if (inputType is InputType.LnUrlAuth) { - when (val result = sdk.lnurlAuth(inputType.data)) { - LnUrlCallbackStatus.Ok -> Log.v("Breez", "Successfully authenticated") - is LnUrlCallbackStatus.ErrorStatus -> Log.v("Breez", "Failed to authenticate: ${result.data.reason}") - } - } -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/LnurlAuth.kt:lnurl-auth}} ```
diff --git a/src/guide/lnurl_pay.md b/src/guide/lnurl_pay.md index f6c8ebf..8b85c0a 100644 --- a/src/guide/lnurl_pay.md +++ b/src/guide/lnurl_pay.md @@ -23,20 +23,7 @@
```kotlin,ignore -// Endpoint can also be of the form: -// lnurlp://domain.com/lnurl-pay?key=val -// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf -val lnurlPayUrl = "lightning@address.com"; -try { - val inputType = parseInput(lnurlPayUrl) - if (inputType is InputType.LnUrlPay) { - val requestData = inputType.data - val amountMsat = requestData.minSendable - sdk.payLnurl(LnUrlPayRequest(requestData, amountMsat, "comment")) - } -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/LnurlPay.kt:lnurl-pay}} ```
diff --git a/src/guide/lnurl_withdraw.md b/src/guide/lnurl_withdraw.md index d6a3150..cc10375 100644 --- a/src/guide/lnurl_withdraw.md +++ b/src/guide/lnurl_withdraw.md @@ -24,21 +24,7 @@
```kotlin,ignore -// Endpoint can also be of the form: -// lnurlw://domain.com/lnurl-withdraw?key=val -// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7… -val lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7…" -try { - val inputType = parseInput(lnurlPayUrl) - if (inputType is InputType.LnUrlWithdraw) { - val requestData = inputType.data - val amountMsat = requestData.minWithdrawable - val comment = "Any comment" - sdk.withdrawLnurl(LnUrlWithdrawRequest(requestData, amountMsat, comment) - } -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/LnurlWithdraw.kt:lnurl-withdraw}} ```
diff --git a/src/guide/receive_onchain.md b/src/guide/receive_onchain.md index 86f784a..6562f53 100644 --- a/src/guide/receive_onchain.md +++ b/src/guide/receive_onchain.md @@ -26,13 +26,7 @@ In order to receive funds you first have to be connected to an [LSP](connecting_
```kotlin,ignore -try { - val swapInfo = sdk.receiveOnchain(ReceiveOnchainRequest()) - // Send your funds to the bellow bitcoin address - val address = swapInfo.bitcoinAddress -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt:generate-receive-onchain-address}} ```
@@ -100,11 +94,7 @@ Once you've sent the funds to the above address, the SDK will monitor this addre
```kotlin,ignore -try { - val swapInfo = sdk.inProgressSwap() -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt:in-progress-swap}} ```
@@ -178,11 +168,7 @@ In order to execute a refund, you need to supply an on-chain address to where th
```kotlin,ignore -try { - val refundables = sdk.listRefundables() -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt:list-refundables}} ```
@@ -250,14 +236,7 @@ Once you have a refundable swap in hand, use the following code to execute a ref
```kotlin,ignore -val swapAddress = "..." -val destinationAddress = "..." -val satPerVbyte = 1.toUInt() -try { - sdk.refund(swapAddress, destinationAddress, satPerVbyte) -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt:execute-refund}} ```
@@ -329,7 +308,7 @@ To calculate the fees for a channel being opened by the LSP:
```kotlin,ignore -// TODO add example for openChannelFee +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt:get-channel-opening-fees}} ```
diff --git a/src/guide/receive_payment.md b/src/guide/receive_payment.md index 5f780cc..7a42014 100644 --- a/src/guide/receive_payment.md +++ b/src/guide/receive_payment.md @@ -24,14 +24,7 @@ The Breez SDK automatically connects your node to the LSP peer and you can now r
```kotlin,ignore -try { - val invoice = sdk.receivePayment(ReceivePaymentRequest( - 3_000_000L.toULong(), - "Invoice for 3000 sats", - )) -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceivePayment.kt:receive-payment}} ```
diff --git a/src/guide/send_onchain.md b/src/guide/send_onchain.md index 260003b..061247c 100644 --- a/src/guide/send_onchain.md +++ b/src/guide/send_onchain.md @@ -25,12 +25,7 @@ First, fetch the current reverse swap fees:
```kotlin,ignore -try { - val fees = sdk.fetchReverseSwapFees(ReverseSwapFeesRequest(50000)) - Log.v("Breez", "Total estimated fees for reverse swap: ${fees.totalEstimatedFees}") -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendOnchain.kt:estimate-current-reverse-swap-total-fees}} ```
@@ -102,8 +97,7 @@ Fetching the fees also tells you what is the range of amounts you can send:
```kotlin,ignore -Log.v("Breez", "Minimum amount, in sats: ${fees.min}") -Log.v("Breez", "Maximum amount, in sats: ${fees.max}") +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendOnchain.kt:get-current-reverse-swap-min-max}} ```
@@ -171,14 +165,7 @@ Once you checked the fees are acceptable, you can start the reverse swap:
```kotlin,ignore -val address = "bc1.." -val amountSat = 123L.toULong() -val satPerVbyte = 1L.toULong() -try { - sdk.sendOnchain(amountSat, address, fees.feesHash, satPerVbyte) -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendOnchain.kt:start-reverse-swap}} ```
@@ -250,9 +237,7 @@ You can check its status with:
```kotlin,ignore -for (rs in sdk.inProgressReverseSwaps()) { - Log.v("Breez", "Reverse swap ${rs.id} in progress, status is ${rs.status}") -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendOnchain.kt:check-reverse-swaps-status}} ```
diff --git a/src/guide/send_payment.md b/src/guide/send_payment.md index aadc01d..5f18390 100644 --- a/src/guide/send_payment.md +++ b/src/guide/send_payment.md @@ -23,16 +23,7 @@ Once you have outbound liquidity you can start sending payments too.
```kotlin,ignore -val bolt11 = "..." -try { - // The `amountMsat` param is optional and should only passed if the bolt11 doesn't specify an amount. - // The amountMsat is required in case an amount is not specified in the bolt11 invoice'. - val amountMsat = 3000000L.toULong() - val req = SendPaymentRequest(bolt11, amountMsat) - val response = sdk.sendPayment(req) -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendPayment.kt:send-payment}} ```
diff --git a/src/guide/send_spontaneous_payment.md b/src/guide/send_spontaneous_payment.md index bdd4257..c736b24 100644 --- a/src/guide/send_spontaneous_payment.md +++ b/src/guide/send_spontaneous_payment.md @@ -23,14 +23,7 @@ They can even be spontaneous payments to a node without a bolt11 invoice.
```kotlin,ignore -val nodeId = "..." -val amountMsat = 3000000L.toULong() -try { - val response = sdk.sendSpontaneousPayment( - SendSpontaneousPaymentRequest(nodeId, amountMsat)) -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendSpontaneousPayment.kt:send-spontaneous-payment}} ```
diff --git a/src/guide/static_channel_backup.md b/src/guide/static_channel_backup.md index 23acee7..049d652 100644 --- a/src/guide/static_channel_backup.md +++ b/src/guide/static_channel_backup.md @@ -30,11 +30,7 @@ In order to use the recoverchannel method, the user needs to provide the static
```kotlin,ignore -try { - val backupData = staticBackup(StaticBackupRequest("")) -} catch (e: Exception) { - // handle error -} +{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/StaticChannelBackup.kt:static-channel-backup}} ```