From 77924c8028a85fea3b84ee9a4edc6847e0fa1186 Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Sun, 2 Jul 2023 01:50:22 +0300 Subject: [PATCH] fix examples --- src/guide/getting_started.md | 38 ++++++++++++++++++++---------------- src/guide/lnurl_auth.md | 12 ++++++------ src/guide/lnurl_pay.md | 12 ++++++------ src/guide/lnurl_withdraw.md | 10 +++++----- src/guide/payments.md | 12 ++++++------ src/guide/recieve_onchain.md | 21 ++++++++++---------- 6 files changed, 55 insertions(+), 50 deletions(-) diff --git a/src/guide/getting_started.md b/src/guide/getting_started.md index b2fb59e..b82a30c 100644 --- a/src/guide/getting_started.md +++ b/src/guide/getting_started.md @@ -76,20 +76,24 @@ The first step is to register a new node ```swift do { let seed = try mnemonicToSeed(phrase: ""); - let invite_code = ; + let inviteCode = ""; - // register_node takes either greenlight credentials (certifate & key) or invite code. + // register_node takes either greenlight credentials (certifate & key) or invite code. // At this example we are using the invite code option. - let credentials = try registerNode(network: Network.bitcoin, seed: seed, inviteCode: inviteCode); -} catch SdkError.Error(let message) { - print(message) + let credentials = try registerNode(network: Network.bitcoin, seed: seed, registerCredentials: nil, inviteCode: inviteCode); +} catch { + // handle error } ``` ## Recovering an existing node ```swift +do { let seed = try mnemonicToSeed(phrase: ""); let credentials = try recoverNode(network: Network.bitcoin, seed: seed); +} catch { + // handle error +} ``` Once the credentials are retrieved they should be saved in a secured storage. @@ -106,29 +110,29 @@ class SDKListener: EventListener { } // Create the default config -let config = breez_sdk.defaultConfig(envType: EnvironmentType.production) +var config = defaultConfig(envType: EnvironmentType.production) // Customize the config object according to your needs config.apiKey = "your API key"; config.workingDir = "path to an existing directory"; -do { - let sdkServices = try initServices(config: config, seed: seed, creds: credentials, listener: SDKListener()); - try sdkServices.start(); -} catch SdkError.Error(let message) { - print(message) +do { + let sdk = try initServices(config: config, seed: seed, creds: credentials, listener: SDKListener()); + try sdk.start(); +} catch{ + // handle error } ``` At any point we can fetch our balance from the Greenlight node: ```swift -do { - let nodeInfo = try sdkServices.nodeInfo(); - let lnBalance = nodeInfo.channelsBalanceMsat; - let onchainBalance = nodeInfo.onchainBalanceMsat; -} catch SdkError.Error(let message) { - print(message) + do { + let nodeInfo = try sdk.nodeInfo(); + let lnBalance = nodeInfo?.channelsBalanceMsat; + let onchainBalance = nodeInfo?.onchainBalanceMsat; +} catch { + // handle error } ``` diff --git a/src/guide/lnurl_auth.md b/src/guide/lnurl_auth.md index 7c94489..7c6adbc 100644 --- a/src/guide/lnurl_auth.md +++ b/src/guide/lnurl_auth.md @@ -35,17 +35,17 @@ let lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0 do { let inputType = try parseInput(s: lnurlAuthUrl) - if case .lnUrlAuth(data) = inputType { - let result = try sdk.lnurlAuth(data) + if case .lnUrlAuth(let data) = inputType { + let result = try sdk.lnurlAuth(reqData: data) switch result { case .ok: print("Successfully authenticated") - case .errorStatus(data): + case .errorStatus(let data): print("Failed to authenticate") - } + } } -} catch SdkError.Error(let message) { - print(message) +} catch { + // handle error } ``` diff --git a/src/guide/lnurl_pay.md b/src/guide/lnurl_pay.md index 732dd1d..1f40f75 100644 --- a/src/guide/lnurl_pay.md +++ b/src/guide/lnurl_pay.md @@ -31,13 +31,13 @@ if let Ok(LnUrlPay{data: pd}) = parse(lnurl_pay_url).await { // lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf let lnurlPayUrl = "lightning@address.com"; do { - let inputType = try parseInput(s: input) - if case .lnUrlPay(data) = inputType { - let amountSats = inputType.minSendable; - try sdk.payLnurl(amountSats: amountSats, "comment", reqData: data) + let inputType = try parseInput(s: lnurlPayUrl) + if case .lnUrlPay(let data) = inputType { + let amountSats = data.minSendable; + try sdk.payLnurl(reqData: data, amountSats: amountSats, comment: "comment") } -} catch SdkError.Error(let message) { - print(message) +} catch { + // handle error } ``` diff --git a/src/guide/lnurl_withdraw.md b/src/guide/lnurl_withdraw.md index 1677f0c..cdb473f 100644 --- a/src/guide/lnurl_withdraw.md +++ b/src/guide/lnurl_withdraw.md @@ -30,14 +30,14 @@ if let Ok(LnUrlWithdraw{data: wd}) = parse(lnurl_withdraw_url).await { let lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"; do { - let inputType = try parseInput(s: input) - if case .lnUrlWithdraw(data) = inputType { + let inputType = try parseInput(s: lnurlWithdrawUrl) + if case .lnUrlWithdraw(let data) = inputType { let amountSat = data.minWithdrawable; let description = "Test withdraw" - try sdk.withdrawLnurl(amountSats: amountSat, description: "comment", reqData: data) + try sdk.withdrawLnurl(reqData: data, amountSats: amountSat, description: "comment") } -} catch SdkError.Error(let message) { - print(message) +} catch { + // handle error } ``` diff --git a/src/guide/payments.md b/src/guide/payments.md index 303848b..cd40456 100644 --- a/src/guide/payments.md +++ b/src/guide/payments.md @@ -33,8 +33,8 @@ Breez SDK automatically connects your node to the LSP peer and you can now recei ```swift do { let invoice = try sdk.receivePayment(amountSats: 3000, description: "Invoice for 3000 sats") -} catch SdkError.Error(let message) { - print(message) +} catch { + // handle error } ``` @@ -43,8 +43,8 @@ do { let bolt11 = "..."; do { let payment = try sdk.sendPayment(bolt11: bolt11, amountSats: 3000) -} catch SdkError.Error(let message) { - print(message) +} catch { + // handle error } ``` @@ -53,8 +53,8 @@ do { let nodeId = "..."; do { let payment = try sdk.sendSpontaneousPayment(nodeId: nodeId, amountSats: 3000) -} catch SdkError.Error(let message) { - print(message) +} catch { + // handle error } ``` diff --git a/src/guide/recieve_onchain.md b/src/guide/recieve_onchain.md index 1d6cd84..ebe420b 100644 --- a/src/guide/recieve_onchain.md +++ b/src/guide/recieve_onchain.md @@ -46,8 +46,8 @@ do { // Send your funds to the bellow bitcoin address let address = swapInfo.bitcoinAddress; -} catch SdkError.Error(let message) { - print(message) +} catch { + // handle error } ``` @@ -56,8 +56,8 @@ Once you've sent the funds to the above address, the SDK will monitor this addre ```swift do { let swapInfo = try sdk.inProgressSwap() -} catch SdkError.Error(let message) { - print(message) +} catch { + // handle error } ``` @@ -71,8 +71,8 @@ In order to execute a refund, you need to supply an on-chain address to where th ```swift do { let refundables = try sdk.listRefundables() -} catch SdkError.Error(let message) { - print(message) +} catch { + // handle error } ``` @@ -81,13 +81,14 @@ Once you have a refundable swap in hand, use the follwing code to execute a refu ```swift let destinationAddress = "..." let satPerVbyte = + do { try sdk.refund( - swapAddress: refundable.bitcoinAddress, - toAddress: destinationAddress, + swapAddress: "", + toAddress: destinationAddress, satPerVbyte: satPerVbyte) -} catch SdkError.Error(let message) { - print(message) +} catch { + // handle error } ```