move swift examples (#100)

* move swift examples

* swift workflow

* fixup

* rewirte gettingStarted

* add README for swift

* update fiat examples and addresss feedback
This commit is contained in:
Ruben
2023-11-16 14:06:30 +01:00
committed by ok300
parent ec8108abf2
commit b541595840
35 changed files with 561 additions and 209 deletions

View File

@@ -269,6 +269,24 @@ jobs:
working-directory: snippets/python working-directory: snippets/python
run: python3 -m compileall src run: python3 -m compileall src
check-swift:
name: Check Swift snippets
runs-on: macos-13
steps:
- uses: actions/checkout@v4
- name: Set up Swift
uses: swift-actions/setup-swift@v1
with:
swift-version: "5"
- name: Build
working-directory: snippets/swift/BreezSDKExamples
run: |
swift build
build: build:
name: Build mdbook name: Build mdbook
runs-on: ubuntu-latest runs-on: ubuntu-latest

3
.gitignore vendored
View File

@@ -1,5 +1,4 @@
book book
.DS_Store .DS_Store
.idea .idea
*.nupkg
*.nupkg

View File

@@ -0,0 +1,5 @@
storage.sql
sync/
sync_storage.sql
.swiftpm
.build

View File

@@ -0,0 +1,23 @@
{
"pins" : [
{
"identity" : "breez-sdk-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/breez/breez-sdk-swift",
"state" : {
"revision" : "dcbb39d45bc6797447bf20f52bc22344026d0662",
"version" : "0.2.9"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531",
"version" : "1.2.3"
}
}
],
"version" : 2
}

View File

@@ -0,0 +1,24 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "BreezSDKDocs",
platforms: [.macOS(.v12)],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.3"),
.package(url: "https://github.com/breez/breez-sdk-swift", from:"0.2.9")
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "BreezSDKDocs",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "BreezSDK", package: "breez-sdk-swift"),
],
path: "Sources"),
]
)

View File

@@ -0,0 +1,17 @@
//
// BuyBtc.swift
//
//
// Created by ruben on 14/11/2023.
//
import Foundation
import BreezSDK
func buy(sdk: BlockingBreezServices) -> BuyBitcoinResponse? {
// ANCHOR: buy-btc
let buyBitcoinResponse = try? sdk.buyBitcoin(
req: BuyBitcoinRequest(provider: .moonpay))
// ANCHOR_END: buy-btc
return buyBitcoinResponse
}

View File

@@ -0,0 +1,25 @@
//
// ConnectingLsp.swift
//
//
// Created by ruben on 14/11/2023.
//
import Foundation
import BreezSDK
func getLspInfo(sdk: BlockingBreezServices) -> LspInformation?{
// ANCHOR: get-lsp-info
let lspId = try? sdk.lspId()
let lspInfo = try? sdk.lspInfo()
// ANCHOR_END: get-lsp-info
return lspInfo
}
func connectLsp(sdk: BlockingBreezServices, lspId: String) {
// ANCHOR: connect-lsp
try? sdk.connectLsp(lspId: lspId)
// ANCHOR_END: connect-lsp
}

View File

@@ -0,0 +1,48 @@
//
// FiatCurrencies.swift
//
//
// Created by ruben on 14/11/2023.
//
import Foundation
import BreezSDK
func listSupportedFiatCurrencies(sdk: BlockingBreezServices) -> [FiatCurrency]? {
// ANCHOR: list-fiat-currencies
let supportedFiatCurrencies = try? sdk.listFiatCurrencies()
// ANCHOR_END: list-fiat-currencies
return supportedFiatCurrencies
}
func getCurrentRates(sdk:BlockingBreezServices) -> [Rate]? {
// ANCHOR: fetch-fiat-rates
let fiatRates = try? sdk.fetchFiatRates()
// 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<f2.id
})
var result = [(FiatCurrency,Rate)]()
for currency in sorted {
if let rate = ratesMap[currency.id.lowercased()] {
result.append((currency, rate))
}
}
return result
}
// ANCHOR_END: get-fiat-currencies-and-rates
return nil
}

View File

@@ -0,0 +1,51 @@
//
// GettingStarted.swift
//
//
// Created by ruben on 13/11/2023.
//
import BreezSDK
// ANCHOR: init-sdk
// SDK events listener
class SDKListener: EventListener {
func onEvent(e: BreezEvent) {
print("received event ", e)
}
}
func gettingStarted() throws -> BlockingBreezServices? {
// Create the default config
let seed = try? mnemonicToSeed(phrase: "<mnemonic words>")
let inviteCode = "<invite code>"
let apiKey = "<api key>"
var config = defaultConfig(envType: EnvironmentType.production, apiKey: apiKey,
nodeConfig: NodeConfig.greenlight(
config: GreenlightNodeConfig(partnerCredentials: nil, inviteCode: inviteCode)))
// Customize the config object according to your needs
config.workingDir = "path to an existing directory"
// Connect to the Breez SDK make it ready for use
guard seed != nil else {
return nil
}
let sdk = try? connect(config: config, seed: seed!, listener: SDKListener())
return sdk
}
// ANCHOR_END: init-sdk
func gettingStartedNodeInfo(sdk: BlockingBreezServices) {
// ANCHOR: fetch-balance
if let nodeInfo = try? sdk.nodeInfo() {
let lnBalance = nodeInfo.channelsBalanceMsat
let onchainBalance = nodeInfo.onchainBalanceMsat
}
// ANCHOR_END: fetch-balance
}

View File

@@ -0,0 +1,27 @@
//
// ListPayments.swift
//
//
// Created by ruben on 13/11/2023.
//
import Foundation
import BreezSDK
func ListPayments(sdk: BlockingBreezServices) -> [Payment]? {
// ANCHOR: list-payments
let payments = try? sdk.listPayments(req: ListPaymentsRequest())
// ANCHOR_END: list-payments
return payments
}
func ListPaymentsFiltered(sdk: BlockingBreezServices) -> [Payment]? {
// ANCHOR: list-payments-filtered
let payments = try? sdk.listPayments(
req: ListPaymentsRequest(
filters: [.sent],
fromTimestamp: 1696880000,
includeFailures: true))
// ANCHOR_END: list-payments-filtered
return payments
}

View File

@@ -0,0 +1,32 @@
//
// LnurlAuth.swift
//
//
// Created by ruben on 14/11/2023.
//
import Foundation
import BreezSDK
func auth(sdk: BlockingBreezServices) {
// ANCHOR: lnurl-withdraw
// Endpoint can also be of the form:
// keyauth://domain.com/auth?key=val
let lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"
if let inputType = try? parseInput(s: lnurlAuthUrl) {
if case .lnUrlAuth(let `data`) = inputType {
let result = try? sdk.lnurlAuth(reqData: data)
switch result {
case .ok:
print("Successfully authenticated")
case .errorStatus(let error):
print("Failed to authenticate: \(error)")
case .none:
print("Failed to authenticate")
}
}
}
// ANCHOR_END: lnurl-withdraw
}

View File

@@ -0,0 +1,26 @@
//
// LnurlPay.swift
//
//
// Created by ruben on 14/11/2023.
//
import Foundation
import BreezSDK
func pay(sdk: BlockingBreezServices) -> LnUrlPayResult? {
// ANCHOR: lnurl-pay
// Endpoint can also be of the form:
// lnurlp://domain.com/lnurl-pay?key=val
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
var response: LnUrlPayResult?
let lnurlPayUrl = "lightning@address.com"
if let inputType = try? parseInput(s: lnurlPayUrl) {
if case.lnUrlPay(let `data`) = inputType {
let amountMSat = data.minSendable
response = try? sdk.payLnurl(req: LnUrlPayRequest(data: data, amountMsat: amountMSat, comment: "comment"))
}
}
// ANCHOR_END: lnurl-pay
return response
}

View File

@@ -0,0 +1,27 @@
//
// LnurlWithdraw.swift
//
//
// Created by ruben on 14/11/2023.
//
import Foundation
import BreezSDK
func withdraw(sdk: BlockingBreezServices) -> LnUrlWithdrawResult? {
// ANCHOR: lnurl-withdraw
// Endpoint can also be of the form:
// lnurlw://domain.com/lnurl-withdraw?key=val
var response: LnUrlWithdrawResult?
let lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"
if let inputType = try? parseInput(s: lnurlWithdrawUrl){
if case.lnUrlWithdraw(let `data`) = inputType {
let amountMsat = data.maxWithdrawable
let description = "Test withdraw"
response = try? sdk.withdrawLnurl(request: LnUrlWithdrawRequest(data: data, amountMsat: amountMsat))
}
}
// ANCHOR_END: lnurl-withdraw
return response
}

View File

@@ -0,0 +1,48 @@
//
// ReceiveOnchain.swift
//
//
// Created by ruben on 14/11/2023.
//
import Foundation
import BreezSDK
func generateReceiveOnchainAddress(sdk: BlockingBreezServices) -> String? {
// ANCHOR: generate-receive-onchain-address
let swapInfo = try? sdk.receiveOnchain(req: ReceiveOnchainRequest())
// Send your funds to the bellow bitcoin address
let address = swapInfo?.bitcoinAddress
// ANCHOR_END: generate-receive-onchain-address
return address
}
func getSwapInProgress(sdk: BlockingBreezServices) -> SwapInfo? {
// ANCHOR: in-progress-swap
let swapInfo = try? sdk.inProgressSwap()
// ANCHOR_END: in-progress-swap
return swapInfo
}
func listRefundables(sdk:BlockingBreezServices) -> [SwapInfo]? {
// ANCHOR: list-refundables
let refundables = try? sdk.listRefundables()
// ANCHOR_END: list-refundables
return refundables
}
func executeRefund(sdk: BlockingBreezServices, refundables: SwapInfo,satPerVbyte: UInt32) -> RefundResponse? {
// ANCHOR: execute-refund
let destinationAddress = "..."
let response = try? sdk.refund(req: RefundRequest(swapAddress: refundables.bitcoinAddress, toAddress: destinationAddress, satPerVbyte: satPerVbyte))
// ANCHOR_END: execute-refund
return response
}
func getChannelOpeningFees(sdk: BlockingBreezServices, amountMsat: UInt64) -> OpenChannelFeeResponse? {
// ANCHOR: get-channel-opening-fees
let response = try? sdk.openChannelFee(req: OpenChannelFeeRequest(amountMsat: amountMsat))
// ANCHOR_END: get-channel-opening-fees
return response
}

View File

@@ -0,0 +1,18 @@
//
// ReceivePayment.swift
//
//
// Created by ruben on 13/11/2023.
//
import BreezSDK
func receivePayment(sdk: BlockingBreezServices) -> ReceivePaymentResponse? {
// ANCHOR: receive-payment
let repsonse = try? sdk.receivePayment(
req: ReceivePaymentRequest(
amountMsat: 3_000_000,
description: "Invoice for 3 000 000 sats"))
// ANCHOR_END: receive-payment
return repsonse
}

View File

@@ -0,0 +1,46 @@
//
// SendOnchain.swift
//
//
// Created by ruben on 14/11/2023.
//
import Foundation
import BreezSDK
func GetCurrentFees(sdk: BlockingBreezServices) -> ReverseSwapPairInfo? {
// ANCHOR: estimate-current-reverse-swap-total-fees
let sendAmountSat:UInt64 = 50_000
let currentFees = try? sdk.fetchReverseSwapFees(req: ReverseSwapFeesRequest(sendAmountSat: sendAmountSat))
print("Total estimated fees for reverse swap: \(String(describing: currentFees?.totalEstimatedFees))")
// ANCHOR_END: estimate-current-reverse-swap-total-fees
return currentFees
}
func ListCurrentFees(currentFees: ReverseSwapPairInfo) {
// ANCHOR: get-current-reverse-swap-min-max
print("Minimum amount, in sats: \(currentFees.min)")
print("Maximum amount, in sats: \(currentFees.max)")
// ANCHOR_END: get-current-reverse-swap-min-max
}
func StartReverseSwap(sdk: BlockingBreezServices, currentFees: ReverseSwapPairInfo) -> SendOnchainResponse? {
// ANCHOR: start-reverse-swap
let destinationAddress = "bc1.."
let amountSat = currentFees.min
let satPerVbyte: UInt32 = 5
let response = try? sdk.sendOnchain(req: SendOnchainRequest(amountSat: amountSat, onchainRecipientAddress: destinationAddress, pairHash: currentFees.feesHash, satPerVbyte: satPerVbyte))
// ANCHOR_END: start-reverse-swap
return response
}
func checkReverseSwap(sdk: BlockingBreezServices) {
// ANCHOR: check-reverse-swaps-status
if let inProgressReverseSwaps = try? sdk.inProgressReverseSwaps() {
for rs in inProgressReverseSwaps {
print("Reverse swap \(rs.id) in progress, status is \(rs.status)")
}
}
// ANCHOR_END: check-reverse-swaps-status
}

View File

@@ -0,0 +1,20 @@
//
// SendPayment.swift
//
//
// Created by ruben on 13/11/2023.
//
import BreezSDK
func sendPayment(sdk: BlockingBreezServices) -> SendPaymentResponse? {
// ANCHOR: send-payment
// 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'.
let req = SendPaymentRequest(bolt11: "...", amountMsat: 3_000_000)
let response = try? sdk.sendPayment(req: req)
// ANCHOR_END: send-payment
return response
}

View File

@@ -0,0 +1,21 @@
//
// SendSpontaneous.swift
//
//
// Created by ruben on 14/11/2023.
//
import Foundation
import BreezSDK
func sendSpontaneousPayment(sdk: BlockingBreezServices) -> SendPaymentResponse? {
// ANCHOR: send-spontaneous-payment
let response = try? sdk.sendSpontaneousPayment(
req: SendSpontaneousPaymentRequest(
nodeId: "...",
amountMsat: 3_000_000))
// ANCHOR_END: send-spontaneous-payment
return response
}

View File

@@ -0,0 +1,16 @@
//
// StaticChannelBackup.swift
// BreezSDKDocs
//
// Created by ruben on 14/11/2023.
//
import Foundation
import BreezSDK
func retrieveBackupFiles() -> StaticBackupResponse? {
// ANCHOR: static-channel-backup
let backupData = try? staticBackup(req:StaticBackupRequest(workingDir: "<working directory>"))
// ANCHOR_END: static-channel-backup
return backupData
}

View File

@@ -0,0 +1,13 @@
// The Swift Programming Language
// https://docs.swift.org/swift-book
print("Hello, tester!")
if let sdk = try gettingStarted(){
if let fiarRates = getFiatCurrencyAndRates(sdk: sdk) {
for fiat in fiarRates {
print("rate \(fiat)\n")
print("------------------------")
}
}
}

8
snippets/swift/README.md Normal file
View File

@@ -0,0 +1,8 @@
# How to run
```
cd BreezSDKExamples
swift build
swift run
```

View File

@@ -20,12 +20,7 @@ Once the buy is completed, the provider will transfer the Bitcoin to the generat
<section> <section>
```swift,ignore ```swift,ignore
do { {{#include ../../snippets/swift/BreezSDKExamples/Sources/BuyBtc.swift:buy-btc}}
let buyBitcoinResponse = try sdk.buyBitcoin(
req: BuyBitcoinRequest(provider: .moonpay))
} catch {
// handle error
}
``` ```
</section> </section>

View File

@@ -15,12 +15,7 @@ Based on the API key provided to the Breez SDK, a default LSP is selected for yo
<section> <section>
```swift,ignore ```swift,ignore
do { {{#include ../../snippets/swift/BreezSDKExamples/Sources/ConnectingLsp.swift:get-lsp-info}}
let lspId = try sdk.lspId()
let lspInfo = try sdk.lspInfo()
} catch {
// Handle error
}
``` ```
</section> </section>
@@ -97,11 +92,7 @@ When you have selected an LSP you may then connect to it.
<section> <section>
```swift,ignore ```swift,ignore
do { {{#include ../../snippets/swift/BreezSDKExamples/Sources/ConnectingLsp.swift:connect-lsp}}
try sdk.connectLsp(lspId: lspId!)
} catch {
// Handle error
}
``` ```
</section> </section>

View File

@@ -11,6 +11,14 @@ In order to list the available fiat currencies:
``` ```
</section> </section>
<div slot="title">Swift</div>
<section>
```swift,ignore
{{#include ../../snippets/swift/BreezSDKExamples/Sources/FiatCurrencies.swift:list-fiat-currencies}}
```
</section>
<div slot="title">Kotlin</div> <div slot="title">Kotlin</div>
<section> <section>
@@ -75,6 +83,14 @@ To get the current BTC rate for the currencies:
``` ```
</section> </section>
<div slot="title">Swift</div>
<section>
```swift,ignore
{{#include ../../snippets/swift/BreezSDKExamples/Sources/FiatCurrencies.swift:fetch-fiat-rates}}
```
</section>
<div slot="title">Kotlin</div> <div slot="title">Kotlin</div>
<section> <section>
@@ -143,6 +159,14 @@ At the example project you can see these methods combined:
``` ```
</section> </section>
<div slot="title">Swift</div>
<section>
```swift,ignore
{{#include ../../snippets/swift/BreezSDKExamples/Sources/FiatCurrencies.swift:get-fiat-currencies-and-rates}}
```
</section>
<div slot="title">Kotlin</div> <div slot="title">Kotlin</div>
<section> <section>

View File

@@ -51,30 +51,7 @@ Now you are ready to interact with the SDK.
<section> <section>
```swift,ignore ```swift,ignore
// SDK events listener {{#include ../../snippets/swift/BreezSDKExamples/Sources/GettingStarted.swift:init-sdk}}
class SDKListener: EventListener {
func onEvent(e: BreezEvent) {
print("received event ", e)
}
}
// Create the default config
let seed = try mnemonicToSeed(phrase: "<mnemonic words>")
let inviteCode = "<invite code>"
let apiKey = "<api key>"
let config = breez_sdk.defaultConfig(envType: EnvironmentType.production, apiKey: apiKey,
nodeConfig: NodeConfig.greenlight(
config: GreenlightNodeConfig(partnerCredentials: nil, inviteCode: inviteCode)));
// Customize the config object according to your needs
config.workingDir = "path to an existing directory"
do {
// Connect to the Breez SDK make it ready for use
let sdk = try connect(config: config, seed: seed, listener: SDKListener());
} catch{
// handle error
}
``` ```
</section> </section>
@@ -170,13 +147,7 @@ At any point we can fetch our balance from the Greenlight node:
<section> <section>
```swift,ignore ```swift,ignore
do { {{#include ../../snippets/swift/BreezSDKExamples/Sources/GettingStarted.swift:fetch-balance}}
let nodeInfo = try sdk.nodeInfo()
let lnBalance = nodeInfo?.channelsBalanceMsat
let onchainBalance = nodeInfo?.onchainBalanceMsat
} catch {
// handle error
}
``` ```
</section> </section>

View File

@@ -15,11 +15,7 @@ To view your payment history you can list and filter all the sent and received p
<section> <section>
```swift,ignore ```swift,ignore
do { {{#include ../../snippets/swift/BreezSDKExamples/Sources/ListPayments.swift:list-payments}}
let payments = try sdk.listPayments(req: ListPaymentsRequest(filter: PaymentTypeFilter.all))
} catch {
// handle error
}
``` ```
</section> </section>
@@ -91,17 +87,7 @@ You can optionally filter payments by timestamp and include failed payments.
<section> <section>
```swift,ignore ```swift,ignore
do { {{#include ../../snippets/swift/BreezSDKExamples/Sources/ListPayments.swift:list-payments-filtered}}
let payments = try sdk.listPayments(
req: ListPaymentsRequest(
filter: PaymentTypeFilter.sent,
fromTimestamp: 1696880000,
includeFailures: true,
)
)
} catch {
// handle error
}
``` ```
</section> </section>

View File

@@ -14,24 +14,7 @@
<section> <section>
```swift,ignore ```swift,ignore
// Endpoint can also be of the form: {{#include ../../snippets/swift/BreezSDKExamples/Sources/LnurlAuth.swift:lnurl-withdraw}}
// keyauth://domain.com/auth?key=val
let lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"
do {
let inputType = try parseInput(s: lnurlAuthUrl)
if case .lnUrlAuth(let data) = inputType {
let result = try sdk.lnurlAuth(reqData: data)
switch result {
case .ok:
print("Successfully authenticated")
case .errorStatus(let data):
print("Failed to authenticate")
}
}
} catch {
// handle error
}
``` ```
</section> </section>

View File

@@ -15,22 +15,7 @@
<section> <section>
```swift,ignore ```swift,ignore
// Endpoint can also be of the form: {{#include ../../snippets/swift/BreezSDKExamples/Sources/LnurlPay.swift:lnurl-pay}}
// lnurlp://domain.com/lnurl-pay?key=val
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
let lnurlPayUrl = "lightning@address.com";
do {
let inputType = try parseInput(s: lnurlPayUrl)
if case .lnUrlPay(let data) = inputType {
let amountMsat = data.minSendable;
try sdk.payLnurl(req: LnUrlPayRequest(
data: data,
amountMsat: amountMsat,
comment: "comment"))
}
} catch {
// handle error
}
``` ```
</section> </section>

View File

@@ -16,24 +16,7 @@
<section> <section>
```swift,ignore ```swift,ignore
// Endpoint can also be of the form: {{#include ../../snippets/swift/BreezSDKExamples/Sources/LnurlWithdraw.swift:lnurl-withdraw}}
// lnurlw://domain.com/lnurl-withdraw?key=val
let lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"
do {
let inputType = try parseInput(s: lnurlWithdrawUrl)
if case .lnUrlWithdraw(let data) = inputType {
let amountMsat = data.minWithdrawable
let description = "Test withdraw"
req: ListPaymentsRequest(filter: PaymentTypeFilter.all)
try sdk.withdrawLnurl(req: LnUrlWithdrawRequest(
data: data,
amountMsat: amountMsat,
description: "comment"))
}
} catch {
// handle error
}
``` ```
</section> </section>

View File

@@ -18,14 +18,7 @@ In order to receive funds you first have to be connected to an [LSP](connecting_
<section> <section>
```swift,ignore ```swift,ignore
do { {{#include ../../snippets/swift/BreezSDKExamples/Sources/ReceiveOnchain.swift:generate-receive-onchain-address}}
let swapInfo = try sdk.receiveOnchain(req: ReceiveOnchainRequest())
// Send your funds to the bellow bitcoin address
let address = swapInfo.bitcoinAddress;
} catch {
// handle error
}
``` ```
</section> </section>
@@ -99,11 +92,7 @@ Once you've sent the funds to the above address, the SDK will monitor this addre
<section> <section>
```swift,ignore ```swift,ignore
do { {{#include ../../snippets/swift/BreezSDKExamples/Sources/ReceiveOnchain.swift:in-progress-swap}}
let swapInfo = try sdk.inProgressSwap()
} catch {
// handle error
}
``` ```
</section> </section>
@@ -181,11 +170,7 @@ In order to execute a refund, you need to supply an on-chain address to where th
<section> <section>
```swift,ignore ```swift,ignore
do { {{#include ../../snippets/swift/BreezSDKExamples/Sources/ReceiveOnchain.swift:list-refundables}}
let refundables = try sdk.listRefundables()
} catch {
// handle error
}
``` ```
</section> </section>
@@ -257,17 +242,7 @@ Once you have a refundable swap in hand, use the following code to execute a ref
<section> <section>
```swift,ignore ```swift,ignore
let destinationAddress = "..." {{#include ../../snippets/swift/BreezSDKExamples/Sources/ReceiveOnchain.swift:execute-refund}}
let satPerVbyte = <refund tx fee rate>
do {
try sdk.refund(
swapAddress: refundable?.bitcoinAddress,
toAddress: "...",
satPerVbyte: satPerVbyte)
} catch {
// handle error
}
``` ```
</section> </section>
@@ -346,13 +321,7 @@ To calculate the fees for a channel being opened by the LSP:
<section> <section>
```swift,ignore ```swift,ignore
let amountMsat = <amount msat> {{#include ../../snippets/swift/BreezSDKExamples/Sources/ReceiveOnchain.swift:get-channel-opening-fees}}
do {
let channelFees = try sdk.openChannelFee(
req: OpenChannelFeeRequest(amountMsat: amountMsat))
} catch {
// Handle error
}
``` ```
</section> </section>

View File

@@ -16,14 +16,7 @@ The Breez SDK automatically connects your node to the LSP peer and you can now r
<section> <section>
```swift,ignore ```swift,ignore
do { {{#include ../../snippets/swift/BreezSDKExamples/Sources/ReceivePayment.swift:receive-payment}}
let invoice = try sdk.receivePayment(
req: ReceivePaymentRequest(
amountMsat: 3_000_000,
description: "Invoice for 3000 sats"))
} catch {
// handle error
}
``` ```
</section> </section>

View File

@@ -17,14 +17,7 @@ First, fetch the current reverse swap fees:
<section> <section>
```swift,ignore ```swift,ignore
let sendAmountSat:UInt64? = 50000 {{#include ../../snippets/swift/BreezSDKExamples/Sources/SendOnchain.swift:estimate-current-reverse-swap-total-fees}}
try {
let currentFees = try sdk.fetchReverseSwapFees(
req: ReverseSwapFeesRequest(sendAmountSat: sendAmountSat))
print("Total estimated fees for reverse swap: \(currentFees.totalEstimatedFees)")
} catch {
// handle error
}
``` ```
</section> </section>
@@ -101,8 +94,7 @@ Fetching the fees also tells you what is the range of amounts you can send:
<section> <section>
```swift,ignore ```swift,ignore
println("Minimum amount, in sats: \(current_fees.min)") {{#include ../../snippets/swift/BreezSDKExamples/Sources/SendOnchain.swift:get-current-reverse-swap-min-max}}
println("Maximum amount, in sats: \(current_fees.max)")
``` ```
</section> </section>
@@ -171,18 +163,7 @@ Once you checked the fees are acceptable, you can start the reverse swap:
<section> <section>
```swift,ignore ```swift,ignore
let destinationAddress = "bc1.." {{#include ../../snippets/swift/BreezSDKExamples/Sources/SendOnchain.swift:start-reverse-swap}}
let amountSat = currentFees.min
let satPerVbyte = <fee rate>
try {
try sdk.sendOnchain(
amountSat: amountSat,
onchainRecipientAddress: destinationAddress,
pairHash: currentFees.feesHash,
satPerVbyte: satPerVbyte)
} catch {
// handle error
}
``` ```
</section> </section>
@@ -261,9 +242,7 @@ You can check its status with:
<section> <section>
```swift,ignore ```swift,ignore
for rs in sdk.inProgressReverseSwaps() { {{#include ../../snippets/swift/BreezSDKExamples/Sources/SendOnchain.swift:check-reverse-swaps-status}}
println("Reverse swap \(rs.id) in progress, status is \(rs.status)")
}
``` ```
</section> </section>

View File

@@ -15,14 +15,7 @@ Once you have outbound liquidity you can start sending payments too.
<section> <section>
```swift,ignore ```swift,ignore
do { {{#include ../../snippets/swift/BreezSDKExamples/Sources/SendPayment.swift:send-payment}}
// 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'.
let req = SendPaymentRequest(bolt11: "...", amountMsat: 3000000)
let response = try sdk.sendPayment(req: req)
} catch {
// handle error
}
``` ```
</section> </section>

View File

@@ -15,15 +15,7 @@ They can even be spontaneous payments to a node without a bolt11 invoice.
<section> <section>
```swift,ignore ```swift,ignore
let nodeId = "..."; {{#include ../../snippets/swift/BreezSDKExamples/Sources/SendSpontaneous.swift:send-spontaneous-payment}}
do {
let response = try sdk.sendSpontaneousPayment(
req: SendSpontaneousPaymentRequest(
nodeId: "...",
amountMsat: 3000000))
} catch {
// handle error
}
``` ```
</section> </section>

View File

@@ -21,11 +21,7 @@ In order to use the recoverchannel method, the user needs to provide the static
<section> <section>
```swift,ignore ```swift,ignore
do { {{#include ../../snippets/swift/BreezSDKExamples/Sources/StaticChannelBackup.swift:static-channel-backup}}
let backupData = breez_sdk.staticBackup(request: StaticBackupRequest(workingDir: "<working directory>"));
} catch{
// handle error
}
``` ```
</section> </section>