mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-17 13:54:20 +01:00
Merge branch 'main' into ok300-bump-sdk-dependency-version
# Conflicts: # snippets/dart_snippets/lib/send_spontaneous_payment.dart
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
// Created by ruben on 14/11/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import BreezSDK
|
||||
import Foundation
|
||||
|
||||
func buy(sdk: BlockingBreezServices) -> BuyBitcoinResponse? {
|
||||
// ANCHOR: buy-btc
|
||||
|
||||
27
snippets/swift/BreezSDKExamples/Sources/ClosedChannel.swift
Normal file
27
snippets/swift/BreezSDKExamples/Sources/ClosedChannel.swift
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// ClosedChannel.swift
|
||||
//
|
||||
//
|
||||
// Created by ruben on 12/12/2023.
|
||||
//
|
||||
import Foundation
|
||||
|
||||
import BreezSDK
|
||||
|
||||
func prepareRedeemOnchainFunds(sdk: BlockingBreezServices, feeRate: UInt32) -> PrepareRedeemOnchainFundsResponse? {
|
||||
// ANCHOR: prepare-redeem-onchain-funds
|
||||
let satPerVbyte = feeRate
|
||||
let req = PrepareRedeemOnchainFundsRequest(toAddress: "bc1..", satPerVbyte: satPerVbyte)
|
||||
let prepareRedeemOnchainFundsResponse = try? sdk.prepareRedeemOnchainFunds(req: req)
|
||||
// ANCHOR_END: prepare-redeem-onchain-funds
|
||||
return prepareRedeemOnchainFundsResponse
|
||||
}
|
||||
|
||||
func redeemOnchainFunds(sdk: BlockingBreezServices, toAddress _: String, feeRate: UInt32) -> RedeemOnchainFundsResponse? {
|
||||
// ANCHOR: redeem-onchain-funds
|
||||
let satPerVbyte = feeRate
|
||||
let req = RedeemOnchainFundsRequest(toAddress: "bc1..", satPerVbyte: satPerVbyte)
|
||||
let redeemOnchainFundsResponse = try? sdk.redeemOnchainFunds(req: req)
|
||||
// ANCHOR_END: redeem-onchain-funds
|
||||
return redeemOnchainFundsResponse
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
//
|
||||
// ConnectingLsp.swift
|
||||
//
|
||||
//
|
||||
//
|
||||
// Created by ruben on 14/11/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import BreezSDK
|
||||
import Foundation
|
||||
|
||||
func getLspInfo(sdk: BlockingBreezServices) -> LspInformation?{
|
||||
func getLspInfo(sdk: BlockingBreezServices) -> LspInformation? {
|
||||
// ANCHOR: get-lsp-info
|
||||
let lspId = try? sdk.lspId()
|
||||
let lspInfo = try? sdk.lspInfo()
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
// Created by ruben on 14/11/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import BreezSDK
|
||||
import Foundation
|
||||
|
||||
func listSupportedFiatCurrencies(sdk: BlockingBreezServices) -> [FiatCurrency]? {
|
||||
// ANCHOR: list-fiat-currencies
|
||||
@@ -15,7 +15,7 @@ func listSupportedFiatCurrencies(sdk: BlockingBreezServices) -> [FiatCurrency]?
|
||||
return supportedFiatCurrencies
|
||||
}
|
||||
|
||||
func getCurrentRates(sdk:BlockingBreezServices) -> [Rate]? {
|
||||
func getCurrentRates(sdk: BlockingBreezServices) -> [Rate]? {
|
||||
// ANCHOR: fetch-fiat-rates
|
||||
let fiatRates = try? sdk.fetchFiatRates()
|
||||
// ANCHOR_END: fetch-fiat-rates
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// GettingStarted.swift
|
||||
//
|
||||
//
|
||||
//
|
||||
// Created by ruben on 13/11/2023.
|
||||
//
|
||||
@@ -10,33 +10,33 @@ import BreezSDK
|
||||
// ANCHOR: init-sdk
|
||||
// SDK events listener
|
||||
class SDKListener: EventListener {
|
||||
func onEvent(e: BreezEvent) {
|
||||
print("received event ", e)
|
||||
}
|
||||
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)))
|
||||
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
|
||||
@@ -48,5 +48,3 @@ func gettingStartedNodeInfo(sdk: BlockingBreezServices) {
|
||||
}
|
||||
// ANCHOR_END: fetch-balance
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
// Created by ruben on 13/11/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import BreezSDK
|
||||
import Foundation
|
||||
|
||||
func ListPayments(sdk: BlockingBreezServices) -> [Payment]? {
|
||||
// ANCHOR: list-payments
|
||||
@@ -20,8 +20,9 @@ func ListPaymentsFiltered(sdk: BlockingBreezServices) -> [Payment]? {
|
||||
let payments = try? sdk.listPayments(
|
||||
req: ListPaymentsRequest(
|
||||
filters: [.sent],
|
||||
fromTimestamp: 1696880000,
|
||||
includeFailures: true))
|
||||
fromTimestamp: 1_696_880_000,
|
||||
includeFailures: true
|
||||
))
|
||||
// ANCHOR_END: list-payments-filtered
|
||||
return payments
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
//
|
||||
// LnurlAuth.swift
|
||||
//
|
||||
//
|
||||
//
|
||||
// Created by ruben on 14/11/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import BreezSDK
|
||||
import Foundation
|
||||
|
||||
func auth(sdk: BlockingBreezServices) {
|
||||
// ANCHOR: lnurl-withdraw
|
||||
@@ -14,14 +14,13 @@ func auth(sdk: BlockingBreezServices) {
|
||||
// keyauth://domain.com/auth?key=val
|
||||
let lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"
|
||||
|
||||
|
||||
if let inputType = try? parseInput(s: lnurlAuthUrl) {
|
||||
if case .lnUrlAuth(let `data`) = inputType {
|
||||
if case let .lnUrlAuth(data) = inputType {
|
||||
let result = try? sdk.lnurlAuth(reqData: data)
|
||||
switch result {
|
||||
case .ok:
|
||||
print("Successfully authenticated")
|
||||
case .errorStatus(let error):
|
||||
case let .errorStatus(error):
|
||||
print("Failed to authenticate: \(error)")
|
||||
case .none:
|
||||
print("Failed to authenticate")
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
// Created by ruben on 14/11/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import BreezSDK
|
||||
import Foundation
|
||||
|
||||
func pay(sdk: BlockingBreezServices) -> LnUrlPayResult? {
|
||||
// ANCHOR: lnurl-pay
|
||||
@@ -16,7 +16,7 @@ func pay(sdk: BlockingBreezServices) -> LnUrlPayResult? {
|
||||
var response: LnUrlPayResult?
|
||||
let lnurlPayUrl = "lightning@address.com"
|
||||
if let inputType = try? parseInput(s: lnurlPayUrl) {
|
||||
if case.lnUrlPay(let `data`) = inputType {
|
||||
if case let .lnUrlPay(data) = inputType {
|
||||
let amountMSat = data.minSendable
|
||||
response = try? sdk.payLnurl(req: LnUrlPayRequest(data: data, amountMsat: amountMSat, comment: "comment"))
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
// Created by ruben on 14/11/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import BreezSDK
|
||||
import Foundation
|
||||
|
||||
func withdraw(sdk: BlockingBreezServices) -> LnUrlWithdrawResult? {
|
||||
// ANCHOR: lnurl-withdraw
|
||||
@@ -15,8 +15,8 @@ func withdraw(sdk: BlockingBreezServices) -> LnUrlWithdrawResult? {
|
||||
var response: LnUrlWithdrawResult?
|
||||
let lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"
|
||||
|
||||
if let inputType = try? parseInput(s: lnurlWithdrawUrl){
|
||||
if case.lnUrlWithdraw(let `data`) = inputType {
|
||||
if let inputType = try? parseInput(s: lnurlWithdrawUrl) {
|
||||
if case let .lnUrlWithdraw(data) = inputType {
|
||||
let amountMsat = data.maxWithdrawable
|
||||
let description = "Test withdraw"
|
||||
response = try? sdk.withdrawLnurl(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// Production.swift
|
||||
//
|
||||
//
|
||||
//
|
||||
// Created by dangeross on 29/11/2023.
|
||||
//
|
||||
@@ -15,7 +15,7 @@ func productionNodeConfig() -> NodeConfig {
|
||||
let greenlightCredentials = GreenlightCredentials(deviceKey: deviceKey, deviceCert: deviceCert)
|
||||
|
||||
let nodeConfig = NodeConfig.greenlight(
|
||||
config: GreenlightNodeConfig(partnerCredentials: greenlightCredentials, inviteCode: nil))
|
||||
config: GreenlightNodeConfig(partnerCredentials: greenlightCredentials, inviteCode: nil))
|
||||
// ANCHOR_END: moving-to-production
|
||||
return nodeConfig
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
// Created by ruben on 14/11/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import BreezSDK
|
||||
import Foundation
|
||||
|
||||
func generateReceiveOnchainAddress(sdk: BlockingBreezServices) -> String? {
|
||||
// ANCHOR: generate-receive-onchain-address
|
||||
@@ -17,7 +17,7 @@ func generateReceiveOnchainAddress(sdk: BlockingBreezServices) -> String? {
|
||||
print("Minimum amount allowed to deposit in sats: \(swapInfo!.minAllowedDeposit)")
|
||||
print("Maximum amount allowed to deposit in sats: \(swapInfo!.maxAllowedDeposit)")
|
||||
// ANCHOR_END: generate-receive-onchain-address
|
||||
|
||||
|
||||
return address
|
||||
}
|
||||
|
||||
@@ -28,13 +28,14 @@ func getSwapInProgress(sdk: BlockingBreezServices) -> SwapInfo? {
|
||||
return swapInfo
|
||||
}
|
||||
|
||||
func listRefundables(sdk:BlockingBreezServices) -> [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? {
|
||||
|
||||
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))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// ReceivePayment.swift
|
||||
//
|
||||
//
|
||||
//
|
||||
// Created by ruben on 13/11/2023.
|
||||
//
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
// Created by ruben on 14/11/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import BreezSDK
|
||||
import Foundation
|
||||
|
||||
func GetCurrentFees(sdk: BlockingBreezServices) -> ReverseSwapPairInfo? {
|
||||
// ANCHOR: estimate-current-reverse-swap-total-fees
|
||||
let sendAmountSat:UInt64 = 50_000
|
||||
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
|
||||
@@ -25,7 +25,7 @@ func ListCurrentFees(currentFees: ReverseSwapPairInfo) {
|
||||
}
|
||||
|
||||
func maxReverseSwapAmount(sdk: BlockingBreezServices) -> MaxReverseSwapAmountResponse? {
|
||||
// ANCHOR: max-reverse-swap-amount
|
||||
// ANCHOR: max-reverse-swap-amount
|
||||
let maxAmount = try? sdk.maxReverseSwapAmount()
|
||||
print("Max reverse swap amount: \(String(describing: maxAmount?.totalSat))")
|
||||
// ANCHOR_END: max-reverse-swap-amount
|
||||
@@ -37,7 +37,7 @@ func StartReverseSwap(sdk: BlockingBreezServices, currentFees: ReverseSwapPairIn
|
||||
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
|
||||
|
||||
@@ -15,6 +15,4 @@ func sendPayment(sdk: BlockingBreezServices) -> SendPaymentResponse? {
|
||||
let response = try? sdk.sendPayment(req: req)
|
||||
// ANCHOR_END: send-payment
|
||||
return response
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
// Created by ruben on 14/11/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import BreezSDK
|
||||
|
||||
import Foundation
|
||||
|
||||
func sendSpontaneousPayment(sdk: BlockingBreezServices) -> SendPaymentResponse? {
|
||||
// ANCHOR: send-spontaneous-payment
|
||||
let response = try? sdk.sendSpontaneousPayment(
|
||||
req: SendSpontaneousPaymentRequest(
|
||||
nodeId: "...",
|
||||
amountMsat: 3_000_000))
|
||||
amountMsat: 3_000_000
|
||||
))
|
||||
// ANCHOR_END: send-spontaneous-payment
|
||||
return response
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
//
|
||||
// ServiceStatus.swift
|
||||
//
|
||||
//
|
||||
//
|
||||
// Created by dangeross on 27/11/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import BreezSDK
|
||||
import Foundation
|
||||
|
||||
func getServiceStatus(sdk: BlockingBreezServices) {
|
||||
// ANCHOR: health-check-status
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
// Created by ruben on 14/11/2023.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import BreezSDK
|
||||
import Foundation
|
||||
|
||||
func retrieveBackupFiles() -> StaticBackupResponse? {
|
||||
// ANCHOR: static-channel-backup
|
||||
let backupData = try? staticBackup(req:StaticBackupRequest(workingDir: "<working directory>"))
|
||||
let backupData = try? staticBackup(req: StaticBackupRequest(workingDir: "<working directory>"))
|
||||
// ANCHOR_END: static-channel-backup
|
||||
return backupData
|
||||
}
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
// https://docs.swift.org/swift-book
|
||||
|
||||
print("Hello, tester!")
|
||||
if let sdk = try gettingStarted(){
|
||||
if let fiatRates = getCurrentRates(sdk: sdk) {
|
||||
if let sdk = try gettingStarted() {
|
||||
if let fiatRates = getCurrentRates(sdk: sdk) {
|
||||
for rate in fiatRates {
|
||||
print("rate \(rate)\n")
|
||||
print("------------------------")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user