mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-17 13:54:20 +01:00
Extract Kotlin snippets
This commit is contained in:
10
snippets/kotlin_mpp_lib/.gitignore
vendored
Normal file
10
snippets/kotlin_mpp_lib/.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
*.iml
|
||||||
|
.gradle
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
build
|
||||||
|
captures
|
||||||
|
.externalNativeBuild
|
||||||
|
.cxx
|
||||||
|
local.properties
|
||||||
|
xcuserdata
|
||||||
6
snippets/kotlin_mpp_lib/build.gradle.kts
Normal file
6
snippets/kotlin_mpp_lib/build.gradle.kts
Normal file
@@ -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
|
||||||
|
}
|
||||||
11
snippets/kotlin_mpp_lib/gradle.properties
Normal file
11
snippets/kotlin_mpp_lib/gradle.properties
Normal file
@@ -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
|
||||||
24
snippets/kotlin_mpp_lib/gradle/libs.versions.toml
Normal file
24
snippets/kotlin_mpp_lib/gradle/libs.versions.toml
Normal file
@@ -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" }
|
||||||
BIN
snippets/kotlin_mpp_lib/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
snippets/kotlin_mpp_lib/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
snippets/kotlin_mpp_lib/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
snippets/kotlin_mpp_lib/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -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
|
||||||
185
snippets/kotlin_mpp_lib/gradlew
vendored
Executable file
185
snippets/kotlin_mpp_lib/gradlew
vendored
Executable file
@@ -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" "$@"
|
||||||
89
snippets/kotlin_mpp_lib/gradlew.bat
vendored
Normal file
89
snippets/kotlin_mpp_lib/gradlew.bat
vendored
Normal file
@@ -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
|
||||||
20
snippets/kotlin_mpp_lib/settings.gradle.kts
Normal file
20
snippets/kotlin_mpp_lib/settings.gradle.kts
Normal file
@@ -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")
|
||||||
49
snippets/kotlin_mpp_lib/shared/build.gradle.kts
Normal file
49
snippets/kotlin_mpp_lib/shared/build.gradle.kts
Normal file
@@ -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:+")
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
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 connect_lsp(sdk: BlockingBreezServices, lspId: String) {
|
||||||
|
// ANCHOR: connect-lsp
|
||||||
|
try {
|
||||||
|
sdk.connectLsp(lspId)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// Handle error
|
||||||
|
}
|
||||||
|
// ANCHOR_END: connect-lsp
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
fun get_fiat_currencies_and_rates(sdk: BlockingBreezServices) {
|
||||||
|
// ANCHOR: get-fiat-currencies-and-rates
|
||||||
|
fun fiatCurrenciesAndRate(): Map<FiatCurrency, Rate> = try {
|
||||||
|
val fiatCurrencies = sdk.listFiatCurrencies()
|
||||||
|
val fiatRates = sdk.fetchFiatRates()
|
||||||
|
|
||||||
|
val ratesMap = mutableMapOf<String, Rate>()
|
||||||
|
for (rate in fiatRates) {
|
||||||
|
ratesMap[rate.coin.lowercase()] = rate
|
||||||
|
}
|
||||||
|
|
||||||
|
val sorted = fiatCurrencies.sortedBy { it.info.name }
|
||||||
|
val result = LinkedHashMap<FiatCurrency, Rate>()
|
||||||
|
for (currency in sorted) {
|
||||||
|
val rate = ratesMap[currency.id.lowercase()]
|
||||||
|
if (rate != null) {
|
||||||
|
result[currency] = rate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
// Handle error
|
||||||
|
emptyMap()
|
||||||
|
}
|
||||||
|
// ANCHOR_END: get-fiat-currencies-and-rates
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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("<mnemonic words>")
|
||||||
|
val inviteCode = "<invite code>"
|
||||||
|
val apiKey = "<api key>"
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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)) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 destinationAddress = "..."
|
||||||
|
val satPerVbyte = 1.toUInt()
|
||||||
|
try {
|
||||||
|
sdk.refund(RefundRequest(swapAddress, destinationAddress, 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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("<working directory>"))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// handle error
|
||||||
|
}
|
||||||
|
// ANCHOR_END: static-channel-backup
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,16 +28,7 @@ Once the buy is completed, the provider will transfer the Bitcoin to the generat
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
try {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/BuyBtc.kt:buy-btc}}
|
||||||
// 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
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -23,16 +23,7 @@ Based on the API key provided to the Breez SDK, a default LSP is selected for yo
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
try {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ConnectingLsp.kt:get-lsp-info}}
|
||||||
val lspId = sdk.lspId()
|
|
||||||
if (lspId != null) {
|
|
||||||
val lspInfo = sdk.lspInfo()
|
|
||||||
} else {
|
|
||||||
// Handle no lsp id scenario
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// Handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -100,11 +91,7 @@ When you have selected an LSP you may then connect to it.
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
try {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ConnectingLsp.kt:connect-lsp}}
|
||||||
sdk.connectLsp(lspId)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// Handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -23,11 +23,7 @@ In order to list the available fiat currencies:
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
try {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/FiatCurrencies.kt:list-fiat-currencies}}
|
||||||
val fiatCurrencyList = sdk.listFiatCurrencies()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -95,11 +91,7 @@ To get the current BTC rate for the currencies:
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
try {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/FiatCurrencies.kt:fetch-fiat-rates}}
|
||||||
val fiatRatesMap = sdk.fetchFiatRates()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -171,29 +163,7 @@ At the example project you can see these methods combined:
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
fun fiatCurrenciesAndRate(): Map<FiatCurrency, Rate> = try {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/FiatCurrencies.kt:get-fiat-currencies-and-rates}}
|
||||||
val fiatCurrencies = sdk.listFiatCurrencies()
|
|
||||||
val fiatRates = sdk.fetchFiatRates()
|
|
||||||
|
|
||||||
val ratesMap = mutableMapOf<String, Rate>()
|
|
||||||
for (rate in fiatRates) {
|
|
||||||
ratesMap[rate.coin.lowercase()] = rate
|
|
||||||
}
|
|
||||||
|
|
||||||
val sorted = fiatCurrencies.sortedBy { it.info.name }
|
|
||||||
val result = LinkedHashMap<FiatCurrency, Rate>()
|
|
||||||
for (currency in sorted) {
|
|
||||||
val rate = ratesMap[currency.id.lowercase()]
|
|
||||||
if (rate != null) {
|
|
||||||
result[currency] = rate
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
// Handle error
|
|
||||||
emptyMap()
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -60,32 +60,7 @@ Now you are ready to interact with the SDK.
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
// SDK events listener
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/GettingStarted.kt:init-sdk}}
|
||||||
class SDKListener : EventListener {
|
|
||||||
override fun onEvent(e: BreezEvent) {
|
|
||||||
Log.v("SDKListener", "Received event $e")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select your seed, invite code and eviroment
|
|
||||||
val seed = mnemonicToSeed("<mnemonic words>")
|
|
||||||
val inviteCode = "<invite code>"
|
|
||||||
val apiKey = "<api key>"
|
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
@@ -155,13 +130,7 @@ At any point we can fetch our balance from the Greenlight node:
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
try {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/GettingStarted.kt:fetch-balance}}
|
||||||
val nodeInfo = sdk.nodeInfo()
|
|
||||||
val lnBalance = nodeInfo?.channelsBalanceMsat
|
|
||||||
val onchainBalance = nodeInfo?.onchainBalanceMsat
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -23,11 +23,7 @@ To view your payment history you can list and filter all the sent and received p
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
try {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ListPayments.kt:list-payments}}
|
||||||
val payments = sdk.listPayments(ListPaymentsRequest(PaymentTypeFilter.ALL))
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -95,11 +91,7 @@ You can optionally filter payments by timestamp and include failed payments.
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
try {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ListPayments.kt:list-payments-filtered}}
|
||||||
val payments = sdk.listPayments(ListPaymentsRequest(PaymentTypeFilter.SENT, fromTimestamp = 1696880000, includeFailures = true))
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -22,21 +22,7 @@
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
// Endpoint can also be of the form:
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/LnurlAuth.kt:lnurl-auth}}
|
||||||
// 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
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -23,20 +23,7 @@
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
// Endpoint can also be of the form:
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/LnurlPay.kt:lnurl-pay}}
|
||||||
// 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
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -24,21 +24,7 @@
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
// Endpoint can also be of the form:
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/LnurlWithdraw.kt:lnurl-withdraw}}
|
||||||
// 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
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -26,13 +26,7 @@ In order to receive funds you first have to be connected to an [LSP](connecting_
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
try {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt:generate-receive-onchain-address}}
|
||||||
val swapInfo = sdk.receiveOnchain(ReceiveOnchainRequest())
|
|
||||||
// Send your funds to the bellow bitcoin address
|
|
||||||
val address = swapInfo.bitcoinAddress
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -100,11 +94,7 @@ Once you've sent the funds to the above address, the SDK will monitor this addre
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
try {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt:in-progress-swap}}
|
||||||
val swapInfo = sdk.inProgressSwap()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -178,11 +168,7 @@ In order to execute a refund, you need to supply an on-chain address to where th
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
try {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt:list-refundables}}
|
||||||
val refundables = sdk.listRefundables()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -250,14 +236,7 @@ Once you have a refundable swap in hand, use the following code to execute a ref
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
val swapAddress = "..."
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceiveOnchain.kt:execute-refund}}
|
||||||
val destinationAddress = "..."
|
|
||||||
val satPerVbyte = 1.toUInt()
|
|
||||||
try {
|
|
||||||
sdk.refund(swapAddress, destinationAddress, satPerVbyte)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -329,7 +308,7 @@ To calculate the fees for a channel being opened by the LSP:
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```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}}
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -24,14 +24,7 @@ The Breez SDK automatically connects your node to the LSP peer and you can now r
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
try {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/ReceivePayment.kt:receive-payment}}
|
||||||
val invoice = sdk.receivePayment(ReceivePaymentRequest(
|
|
||||||
3_000_000L.toULong(),
|
|
||||||
"Invoice for 3000 sats",
|
|
||||||
))
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -25,12 +25,7 @@ First, fetch the current reverse swap fees:
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
try {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendOnchain.kt:estimate-current-reverse-swap-total-fees}}
|
||||||
val fees = sdk.fetchReverseSwapFees(ReverseSwapFeesRequest(50000))
|
|
||||||
Log.v("Breez", "Total estimated fees for reverse swap: ${fees.totalEstimatedFees}")
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -102,8 +97,7 @@ Fetching the fees also tells you what is the range of amounts you can send:
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
Log.v("Breez", "Minimum amount, in sats: ${fees.min}")
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendOnchain.kt:get-current-reverse-swap-min-max}}
|
||||||
Log.v("Breez", "Maximum amount, in sats: ${fees.max}")
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -171,14 +165,7 @@ Once you checked the fees are acceptable, you can start the reverse swap:
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
val address = "bc1.."
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendOnchain.kt:start-reverse-swap}}
|
||||||
val amountSat = 123L.toULong()
|
|
||||||
val satPerVbyte = 1L.toULong()
|
|
||||||
try {
|
|
||||||
sdk.sendOnchain(amountSat, address, fees.feesHash, satPerVbyte)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -250,9 +237,7 @@ You can check its status with:
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
for (rs in sdk.inProgressReverseSwaps()) {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendOnchain.kt:check-reverse-swaps-status}}
|
||||||
Log.v("Breez", "Reverse swap ${rs.id} in progress, status is ${rs.status}")
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -23,16 +23,7 @@ Once you have outbound liquidity you can start sending payments too.
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
val bolt11 = "..."
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendPayment.kt:send-payment}}
|
||||||
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
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -23,14 +23,7 @@ They can even be spontaneous payments to a node without a bolt11 invoice.
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
val nodeId = "..."
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/SendSpontaneousPayment.kt:send-spontaneous-payment}}
|
||||||
val amountMsat = 3000000L.toULong()
|
|
||||||
try {
|
|
||||||
val response = sdk.sendSpontaneousPayment(
|
|
||||||
SendSpontaneousPaymentRequest(nodeId, amountMsat))
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -30,11 +30,7 @@ In order to use the recoverchannel method, the user needs to provide the static
|
|||||||
<section>
|
<section>
|
||||||
|
|
||||||
```kotlin,ignore
|
```kotlin,ignore
|
||||||
try {
|
{{#include ../../snippets/kotlin_mpp_lib/shared/src/commonMain/kotlin/com/example/kotlinmpplib/StaticChannelBackup.kt:static-channel-backup}}
|
||||||
val backupData = staticBackup(StaticBackupRequest("<working directory>"))
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// handle error
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
Reference in New Issue
Block a user