diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 11d0c06b..59815401 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,8 +25,8 @@ jobs: name: setup runs-on: ubuntu-latest outputs: - sdk-ref: ${{ inputs.sdk-ref || '0.4.0' }} - package-version: '0.4.0' + sdk-ref: ${{ inputs.sdk-ref || '83740c3595ac16b29896c76a2e8790fba0535ab3' }} + package-version: '0.5.0' steps: - run: echo "set pre-setup output variables" @@ -47,7 +47,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Set up Rust environment and run checks - name: Install rust @@ -66,7 +66,7 @@ jobs: workspaces: snippets/rust -> snippets/rust/target - name: temporarily get sdk - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: breez/breez-sdk ref: ${{ needs.setup.outputs.sdk-ref }} @@ -100,7 +100,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Set up the flutter environment and run checks - uses: subosito/flutter-action@v2 @@ -108,7 +108,7 @@ jobs: channel: 'stable' cache: true - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: breez-sdk-flutter-${{ needs.setup.outputs.package-version }} path: snippets/dart_snippets/packages/breez-sdk-flutter @@ -129,15 +129,15 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup dotnet - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: '7.0.x' - name: Download archived package - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: Breez.Sdk.${{ needs.setup.outputs.package-version }}.nupkg path: . @@ -165,15 +165,15 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set Node.js 20.x - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 20.x - name: Download archived package - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: react-native-${{ needs.setup.outputs.package-version }} path: snippets/react-native/packages @@ -198,14 +198,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version: '1.21' - name: Download archived package - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: breez-sdk-go-${{ needs.setup.outputs.package-version }} path: snippets/go/packages/breez-sdk-go @@ -243,12 +243,12 @@ jobs: - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.8' - name: Download archived package - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: python-wheel-3.8-manylinux_2_31_x86_64 path: snippets/python/packages @@ -293,10 +293,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Java 17 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: distribution: "temurin" java-version: 17 @@ -312,7 +312,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install rust run: | @@ -334,7 +334,7 @@ jobs: run: mdbook build - name: Archive book - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: book path: book diff --git a/snippets/csharp/Production.cs b/snippets/csharp/Production.cs index 853c6ef7..ab9b2c7e 100644 --- a/snippets/csharp/Production.cs +++ b/snippets/csharp/Production.cs @@ -6,9 +6,9 @@ public NodeConfig ProductionNodeConfig() { // ANCHOR: moving-to-production // Read in your Greenlight credentials from the file // system, environment variable or build config - var deviceKey = new List(); - var deviceCert = new List(); - var greenlightCredentials = new GreenlightCredentials(deviceKey, deviceCert); + var developerKey = new List(); + var developerCert = new List(); + var greenlightCredentials = new GreenlightCredentials(developerKey, developerCert); var nodeConfig = new NodeConfig.Greenlight( new GreenlightNodeConfig(greenlightCredentials, null) diff --git a/snippets/csharp/Webhook.cs b/snippets/csharp/Webhook.cs index 6c9b9e7a..32b95178 100644 --- a/snippets/csharp/Webhook.cs +++ b/snippets/csharp/Webhook.cs @@ -2,12 +2,12 @@ public class ServiceStatusSnippets { - public void Webhook(BlockingBreezServices sdk) + public void RegisterWebhook(BlockingBreezServices sdk) { // ANCHOR: register-webook try { - sdk.RegisterWebhook("https://yourapplication.com"); + sdk.RegisterWebhook("https://your-nds-service.com/notify?platform=ios&token="); } catch (Exception) { @@ -15,18 +15,18 @@ public void Webhook(BlockingBreezServices sdk) } // ANCHOR_END: register-webook } - - public void PaymentWebhook(BlockingBreezServices sdk) + + public void UnregisterWebhook(BlockingBreezServices sdk) { - // ANCHOR: register-payment-webook + // ANCHOR: unregister-webook try { - sdk.RegisterWebhook("https://your-nds-service.com/notify?platform=ios&token="); + sdk.UnregisterWebhook("https://your-nds-service.com/notify?platform=ios&token="); } catch (Exception) { // Handle error } - // ANCHOR_END: register-payment-webook + // ANCHOR_END: unregister-webook } } diff --git a/snippets/dart_snippets/bin/dart_snippets.dart b/snippets/dart_snippets/bin/dart_snippets.dart index 12976354..65f4dc74 100644 --- a/snippets/dart_snippets/bin/dart_snippets.dart +++ b/snippets/dart_snippets/bin/dart_snippets.dart @@ -1,5 +1,5 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; void main(List arguments) { - BreezSDK().initialize(); + breezSDK.initialize(); } diff --git a/snippets/dart_snippets/lib/buy_btc.dart b/snippets/dart_snippets/lib/buy_btc.dart index 17e67872..cb566397 100644 --- a/snippets/dart_snippets/lib/buy_btc.dart +++ b/snippets/dart_snippets/lib/buy_btc.dart @@ -1,10 +1,10 @@ -import 'package:breez_sdk/breez_sdk.dart'; import 'package:breez_sdk/bridge_generated.dart'; +import 'package:dart_snippets/sdk_instance.dart'; Future buyBitcoin() async { // ANCHOR: buy-btc BuyBitcoinRequest req = const BuyBitcoinRequest(provider: BuyBitcoinProvider.Moonpay); - BuyBitcoinResponse resp = await BreezSDK().buyBitcoin(req: req); + BuyBitcoinResponse resp = await breezSDK.buyBitcoin(req: req); // ANCHOR_END: buy-btc return resp; } diff --git a/snippets/dart_snippets/lib/closed_channel.dart b/snippets/dart_snippets/lib/closed_channel.dart index 89967b17..1a651390 100644 --- a/snippets/dart_snippets/lib/closed_channel.dart +++ b/snippets/dart_snippets/lib/closed_channel.dart @@ -1,4 +1,4 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future prepareRedeemOnchainFunds( @@ -8,7 +8,7 @@ Future prepareRedeemOnchainFunds( toAddress: "bc1..", satPerVbyte: satPerVbyte, ); - final resp = await BreezSDK().prepareRedeemOnchainFunds(req: req); + final resp = await breezSDK.prepareRedeemOnchainFunds(req: req); // ANCHOR_END: prepare-redeem-onchain-funds return resp; } @@ -20,7 +20,7 @@ Future redeemOnchainFunds( toAddress: "bc1..", satPerVbyte: satPerVbyte, ); - final resp = await BreezSDK().redeemOnchainFunds(req: req); + final resp = await breezSDK.redeemOnchainFunds(req: req); // ANCHOR_END: redeem-onchain-funds return resp; } diff --git a/snippets/dart_snippets/lib/communicating_fees.dart b/snippets/dart_snippets/lib/communicating_fees.dart index ebb2dbbc..c87fdccb 100644 --- a/snippets/dart_snippets/lib/communicating_fees.dart +++ b/snippets/dart_snippets/lib/communicating_fees.dart @@ -1,13 +1,13 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future getFeeInfoBeforeInvoiceCreated() async { // ANCHOR: get-fee-info-before-receiving-payment - NodeState? nodeInfo = await BreezSDK().nodeInfo(); + NodeState? nodeInfo = await breezSDK.nodeInfo(); if (nodeInfo != null) { int inboundLiquiditySat = nodeInfo.inboundLiquidityMsats ~/ 1000; - OpenChannelFeeResponse openingFeeResponse = await BreezSDK().openChannelFee(req: OpenChannelFeeRequest()); + OpenChannelFeeResponse openingFeeResponse = await breezSDK.openChannelFee(req: OpenChannelFeeRequest()); OpeningFeeParams openingFees = openingFeeResponse.feeParams; double feePercentage = (openingFees.proportional * 100) / 1000000; @@ -31,12 +31,12 @@ Future getFeeInfoAfterInvoiceCreated({required ReceivePaymentResponse rece Future getFeeInfoReceiveOnchain() async { // ANCHOR: get-fee-info-receive-onchain - SwapInfo swapInfo = await BreezSDK().receiveOnchain(req: ReceiveOnchainRequest()); + SwapInfo swapInfo = await breezSDK.receiveOnchain(req: ReceiveOnchainRequest()); int minDepositSat = swapInfo.minAllowedDeposit; int maxDepositSat = swapInfo.maxAllowedDeposit; - NodeState? nodeInfo = await BreezSDK().nodeInfo(); + NodeState? nodeInfo = await breezSDK.nodeInfo(); if (nodeInfo != null) { int inboundLiquiditySat = nodeInfo.inboundLiquidityMsats ~/ 1000; diff --git a/snippets/dart_snippets/lib/connecting_lsp.dart b/snippets/dart_snippets/lib/connecting_lsp.dart index 5a8b61c8..9136da2c 100644 --- a/snippets/dart_snippets/lib/connecting_lsp.dart +++ b/snippets/dart_snippets/lib/connecting_lsp.dart @@ -1,10 +1,10 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future getLspInfo() async { // ANCHOR: get-lsp-info - String? lspId = await BreezSDK().lspId(); - LspInformation? lspInfo = await BreezSDK().lspInfo(); + String? lspId = await breezSDK.lspId(); + LspInformation? lspInfo = await breezSDK.lspInfo(); print(lspId); print(lspInfo); // ANCHOR_END: get-lsp-info @@ -12,13 +12,13 @@ Future getLspInfo() async { Future> listLsps() async { // ANCHOR: list-lsps - List availableLsps = await BreezSDK().listLsps(); + List availableLsps = await breezSDK.listLsps(); // ANCHOR_END: list-lsps return availableLsps; } Future connectLsp(String lspId) async { // ANCHOR: connect-lsp - await BreezSDK().connectLSP(lspId); + await breezSDK.connectLSP(lspId); // ANCHOR_END: connect-lsp } \ No newline at end of file diff --git a/snippets/dart_snippets/lib/fiat_currencies.dart b/snippets/dart_snippets/lib/fiat_currencies.dart index 9de0f5c2..75c69fdc 100644 --- a/snippets/dart_snippets/lib/fiat_currencies.dart +++ b/snippets/dart_snippets/lib/fiat_currencies.dart @@ -1,16 +1,16 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future> listFiatCurrencies() async { // ANCHOR: list-fiat-currencies - List fiatCurrencyList = await BreezSDK().listFiatCurrencies(); + List fiatCurrencyList = await breezSDK.listFiatCurrencies(); // ANCHOR_END: list-fiat-currencies return fiatCurrencyList; } Future> fetchFiatRates(String lspId) async { // ANCHOR: fetch-fiat-rates - Map fiatRatesMap = await BreezSDK().fetchFiatRates(); + Map fiatRatesMap = await breezSDK.fetchFiatRates(); // print your desired rate print(fiatRatesMap["USD"]?.value); // ANCHOR_END: fetch-fiat-rates diff --git a/snippets/dart_snippets/lib/getting_started.dart b/snippets/dart_snippets/lib/getting_started.dart index cd331449..f98f0d8a 100644 --- a/snippets/dart_snippets/lib/getting_started.dart +++ b/snippets/dart_snippets/lib/getting_started.dart @@ -1,16 +1,27 @@ import 'dart:typed_data'; import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future initializeSDK() async { // ANCHOR: init-sdk - // Initialize SDK logs listener - BreezSDK().initialize(); + // It is recommended to use a single instance of BreezSDK across your Dart/Flutter app. + // + // All of the snippets assume a BreezSDK object is created on entrypoint of the app as such: + // + // BreezSDK breezSDK = BreezSDK(); + // + // and is accessible throughout the app. There are various approaches on how to achieve this; creating a Singleton class using factory constructor, using state management libraries such as 'provider', 'GetX', 'Riverpod' and 'Redux' to name a few. + + // Initializes SDK events & log streams. + // + // Call once on your Dart entrypoint file, e.g.; `lib/main.dart`. + breezSDK.initialize(); // Create the default config - Uint8List seed = await BreezSDK().mnemonicToSeed(""); + Uint8List seed = await breezSDK.mnemonicToSeed(""); String inviteCode = ""; String apiKey = ""; NodeConfig nodeConfig = NodeConfig.greenlight( @@ -19,7 +30,7 @@ Future initializeSDK() async { inviteCode: inviteCode, ), ); - Config config = await BreezSDK().defaultConfig( + Config config = await breezSDK.defaultConfig( envType: EnvironmentType.Production, apiKey: apiKey, nodeConfig: nodeConfig, @@ -30,20 +41,20 @@ Future initializeSDK() async { // Connect to the Breez SDK make it ready for use ConnectRequest connectRequest = ConnectRequest(config: config, seed: seed); - return await BreezSDK().connect(req: connectRequest); + return await breezSDK.connect(req: connectRequest); // ANCHOR_END: init-sdk } Future connectRestoreOnly(Config config, Uint8List seed) async { // ANCHOR: init-sdk-restore-only ConnectRequest connectRequest = ConnectRequest(config: config, seed: seed, restoreOnly: true); - return await BreezSDK().connect(req: connectRequest); + return await breezSDK.connect(req: connectRequest); // ANCHOR_END: init-sdk-restore-only } Future fetchBalance(String lspId) async { // ANCHOR: fetch-balance - NodeState? nodeInfo = await BreezSDK().nodeInfo(); + NodeState? nodeInfo = await breezSDK.nodeInfo(); if (nodeInfo != null) { int lnBalance = nodeInfo.channelsBalanceMsat; int onchainBalance = nodeInfo.onchainBalanceMsat; diff --git a/snippets/dart_snippets/lib/list_payments.dart b/snippets/dart_snippets/lib/list_payments.dart index c34ce2b4..a86116ce 100644 --- a/snippets/dart_snippets/lib/list_payments.dart +++ b/snippets/dart_snippets/lib/list_payments.dart @@ -1,10 +1,10 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future> listPayments() async { // ANCHOR: list-payments ListPaymentsRequest req = ListPaymentsRequest(); - List paymentsList = await BreezSDK().listPayments(req: req); + List paymentsList = await breezSDK.listPayments(req: req); print(paymentsList); // ANCHOR_END: list-payments return paymentsList; @@ -29,7 +29,7 @@ Future> listPaymentsFiltered({ offset: offset, limit: limit, ); - List paymentsList = await BreezSDK().listPayments(req: req); + List paymentsList = await breezSDK.listPayments(req: req); print(paymentsList); // ANCHOR_END: list-payments-filtered return paymentsList; diff --git a/snippets/dart_snippets/lib/lnurl_auth.dart b/snippets/dart_snippets/lib/lnurl_auth.dart index 876798ae..cab20d15 100644 --- a/snippets/dart_snippets/lib/lnurl_auth.dart +++ b/snippets/dart_snippets/lib/lnurl_auth.dart @@ -1,4 +1,4 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future lnurlAuth() async { @@ -8,9 +8,9 @@ Future lnurlAuth() async { String lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"; - InputType inputType = await BreezSDK().parseInput(input: lnurlAuthUrl); + InputType inputType = await breezSDK.parseInput(input: lnurlAuthUrl); if (inputType is InputType_LnUrlAuth) { - LnUrlCallbackStatus result = await BreezSDK().lnurlAuth(reqData: inputType.data); + LnUrlCallbackStatus result = await breezSDK.lnurlAuth(reqData: inputType.data); if (result is LnUrlCallbackStatus_Ok) { print("Successfully authenticated"); } else { diff --git a/snippets/dart_snippets/lib/lnurl_pay.dart b/snippets/dart_snippets/lib/lnurl_pay.dart index de04c71e..226c0522 100644 --- a/snippets/dart_snippets/lib/lnurl_pay.dart +++ b/snippets/dart_snippets/lib/lnurl_pay.dart @@ -1,4 +1,4 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future lnurlPay() async { @@ -8,7 +8,7 @@ Future lnurlPay() async { /// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf String lnurlPayUrl = "lightning@address.com"; - InputType inputType = await BreezSDK().parseInput(input: lnurlPayUrl); + InputType inputType = await breezSDK.parseInput(input: lnurlPayUrl); if (inputType is InputType_LnUrlPay) { int amountMsat = inputType.data.minSendable; String optionalComment = ""; @@ -19,7 +19,7 @@ Future lnurlPay() async { comment: optionalComment, paymentLabel: optionalPaymentLabel, ); - LnUrlPayResult result = await BreezSDK().lnurlPay(req: req); + LnUrlPayResult result = await breezSDK.lnurlPay(req: req); print(result.data); } // ANCHOR_END: lnurl-pay diff --git a/snippets/dart_snippets/lib/lnurl_withdraw.dart b/snippets/dart_snippets/lib/lnurl_withdraw.dart index 28d85646..cf46b28f 100644 --- a/snippets/dart_snippets/lib/lnurl_withdraw.dart +++ b/snippets/dart_snippets/lib/lnurl_withdraw.dart @@ -1,4 +1,4 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future lnurlWithdraw() async { @@ -8,7 +8,7 @@ Future lnurlWithdraw() async { String lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"; - InputType inputType = await BreezSDK().parseInput(input: lnurlWithdrawUrl); + InputType inputType = await breezSDK.parseInput(input: lnurlWithdrawUrl); if (inputType is InputType_LnUrlWithdraw) { int amountMsat = inputType.data.minWithdrawable; LnUrlWithdrawRequest req = LnUrlWithdrawRequest( @@ -16,7 +16,7 @@ Future lnurlWithdraw() async { amountMsat: amountMsat, description: "", ); - LnUrlWithdrawResult result = await BreezSDK().lnurlWithdraw(req: req); + LnUrlWithdrawResult result = await breezSDK.lnurlWithdraw(req: req); print(result.data); } // ANCHOR_END: lnurl-withdraw diff --git a/snippets/dart_snippets/lib/metadata.dart b/snippets/dart_snippets/lib/metadata.dart index dd54fe69..6554987b 100644 --- a/snippets/dart_snippets/lib/metadata.dart +++ b/snippets/dart_snippets/lib/metadata.dart @@ -1,9 +1,9 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future setPaymentMetadata({required String paymentHash, required String metadata}) async { // ANCHOR: set-payment-metadata - await BreezSDK().setPaymentMetadata(hash: "target-payment-hash", metadata: '{"myCustomValue":true}'); + await breezSDK.setPaymentMetadata(hash: "target-payment-hash", metadata: '{"myCustomValue":true}'); // ANCHOR_END: set-payment-metadata } @@ -16,7 +16,7 @@ Future filterPaymentMetadata() async { ), ]; - await BreezSDK().listPayments( + await breezSDK.listPayments( req: ListPaymentsRequest( metadataFilters: metadataFilters )); diff --git a/snippets/dart_snippets/lib/pay_onchain.dart b/snippets/dart_snippets/lib/pay_onchain.dart index b1c36ded..0a2d0d4a 100644 --- a/snippets/dart_snippets/lib/pay_onchain.dart +++ b/snippets/dart_snippets/lib/pay_onchain.dart @@ -1,9 +1,9 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future getCurrentLimits() async { // ANCHOR: get-current-reverse-swap-limits - OnchainPaymentLimitsResponse currentLimits = await BreezSDK().onchainPaymentLimits(); + OnchainPaymentLimitsResponse currentLimits = await breezSDK.onchainPaymentLimits(); print("Minimum amount, in sats: ${currentLimits.minSat}"); print("Maximum amount, in sats: ${currentLimits.maxSat}"); // ANCHOR_END: get-current-reverse-swap-limits @@ -20,7 +20,7 @@ Future preparePayOnchain({ amountType: SwapAmountType.Send, claimTxFeerate: satPerVbyte, ); - PrepareOnchainPaymentResponse prepareRes = await BreezSDK().prepareOnchainPayment(req: req); + PrepareOnchainPaymentResponse prepareRes = await breezSDK.prepareOnchainPayment(req: req); print("Sender amount: ${prepareRes.senderAmountSat} sats"); print("Recipient amount: ${prepareRes.recipientAmountSat} sats"); print("Total fees: ${prepareRes.totalFees} sats"); @@ -37,14 +37,14 @@ Future startReverseSwap({ recipientAddress: onchainRecipientAddress, prepareRes: prepareRes, ); - PayOnchainResponse res = await BreezSDK().payOnchain(req: req); + PayOnchainResponse res = await breezSDK.payOnchain(req: req); // ANCHOR_END: start-reverse-swap return res; } Future> checkReverseSwapStatus() async { // ANCHOR: check-reverse-swaps-status - List inProgOnchainPaymentList = await BreezSDK().inProgressOnchainPayments(); + List inProgOnchainPaymentList = await breezSDK.inProgressOnchainPayments(); for (var inProgOnchainPayment in inProgOnchainPaymentList) { print("Onchain payment ${inProgOnchainPayment.id} in progress, status is ${inProgOnchainPayment.status.name}"); } diff --git a/snippets/dart_snippets/lib/production.dart b/snippets/dart_snippets/lib/production.dart index 9e716ccc..52f16dd3 100644 --- a/snippets/dart_snippets/lib/production.dart +++ b/snippets/dart_snippets/lib/production.dart @@ -6,11 +6,11 @@ NodeConfig productionNodeConfig() { // ANCHOR: moving-to-production // Read in your Greenlight credentials from the file // system, environment variable or build config - Uint8List deviceKey = Uint8List(0); - Uint8List deviceCert = Uint8List(0); + Uint8List developerKey = Uint8List(0); + Uint8List developerCert = Uint8List(0); GreenlightCredentials greenlightCredentials = GreenlightCredentials( - deviceKey: deviceKey, - deviceCert: deviceCert, + developerKey: developerKey, + developerCert: developerCert, ); NodeConfig nodeConfig = NodeConfig.greenlight( diff --git a/snippets/dart_snippets/lib/receive_onchain.dart b/snippets/dart_snippets/lib/receive_onchain.dart index 143e2e87..7dad1cd4 100644 --- a/snippets/dart_snippets/lib/receive_onchain.dart +++ b/snippets/dart_snippets/lib/receive_onchain.dart @@ -1,10 +1,10 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future generateReceiveOnchainAddress() async { // ANCHOR: generate-receive-onchain-address ReceiveOnchainRequest req = const ReceiveOnchainRequest(); - SwapInfo swapInfo = await BreezSDK().receiveOnchain(req: req); + SwapInfo swapInfo = await breezSDK.receiveOnchain(req: req); // Send your funds to the below bitcoin address String address = swapInfo.bitcoinAddress; @@ -17,7 +17,7 @@ Future generateReceiveOnchainAddress() async { Future getInProgressSwap() async { // ANCHOR: in-progress-swap - SwapInfo? swapInfo = await BreezSDK().inProgressSwap(); + SwapInfo? swapInfo = await breezSDK.inProgressSwap(); print(swapInfo); // ANCHOR_END: in-progress-swap return swapInfo; @@ -25,7 +25,7 @@ Future getInProgressSwap() async { Future> listRefundables() async { // ANCHOR: list-refundables - List refundables = await BreezSDK().listRefundables(); + List refundables = await breezSDK.listRefundables(); for (var refundable in refundables) { print(refundable.bitcoinAddress); } @@ -44,7 +44,7 @@ Future executeRefund({ toAddress: toAddress, satPerVbyte: satPerVbyte, ); - RefundResponse resp = await BreezSDK().refund(req: req); + RefundResponse resp = await breezSDK.refund(req: req); print(resp.refundTxId); // ANCHOR_END: execute-refund return resp; @@ -56,7 +56,7 @@ Future getChannelOpeningFees({ }) async { // ANCHOR: get-channel-opening-fees OpenChannelFeeRequest req = OpenChannelFeeRequest(amountMsat: amountMsat, expiry: expiry); - OpenChannelFeeResponse resp = await BreezSDK().openChannelFee(req: req); + OpenChannelFeeResponse resp = await breezSDK.openChannelFee(req: req); print(resp.feeMsat); // ANCHOR_END: get-channel-opening-fees return resp; @@ -64,6 +64,6 @@ Future getChannelOpeningFees({ Future rescanSwaps() async { // ANCHOR: rescan-swaps - await BreezSDK().rescanSwaps(); + await breezSDK.rescanSwaps(); // ANCHOR_END: rescan-swaps } diff --git a/snippets/dart_snippets/lib/receive_payment.dart b/snippets/dart_snippets/lib/receive_payment.dart index da284605..aab6974c 100644 --- a/snippets/dart_snippets/lib/receive_payment.dart +++ b/snippets/dart_snippets/lib/receive_payment.dart @@ -1,4 +1,4 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future receivePayment() async { @@ -7,7 +7,7 @@ Future receivePayment() async { amountMsat: 3000000, description: "Invoice for 3000 sats", ); - ReceivePaymentResponse receivePaymentResponse = await BreezSDK().receivePayment(req: req); + ReceivePaymentResponse receivePaymentResponse = await breezSDK.receivePayment(req: req); print(receivePaymentResponse.lnInvoice); // ANCHOR_END: receive-payment diff --git a/snippets/dart_snippets/lib/sdk_instance.dart b/snippets/dart_snippets/lib/sdk_instance.dart new file mode 100644 index 00000000..e4d02c27 --- /dev/null +++ b/snippets/dart_snippets/lib/sdk_instance.dart @@ -0,0 +1,3 @@ +import 'package:breez_sdk/breez_sdk.dart'; + +BreezSDK breezSDK = BreezSDK(); diff --git a/snippets/dart_snippets/lib/send_payment.dart b/snippets/dart_snippets/lib/send_payment.dart index a16f993a..54f0de32 100644 --- a/snippets/dart_snippets/lib/send_payment.dart +++ b/snippets/dart_snippets/lib/send_payment.dart @@ -1,4 +1,4 @@ -import 'package:breez_sdk/breez_sdk.dart'; +import 'package:dart_snippets/sdk_instance.dart'; import 'package:breez_sdk/bridge_generated.dart'; Future sendPayment({required String bolt11}) async { @@ -8,7 +8,7 @@ Future sendPayment({required String bolt11}) async { int optionalAmountMsat = 3000000; String optionalLabel = "