Create Dart snippets and reference them

Co-Authored-By: ok300 <106775972+ok300@users.noreply.github.com>
This commit is contained in:
Erdem Yerebasmaz
2023-10-24 21:25:46 +03:00
parent c29cad2bd2
commit ec4955c488
35 changed files with 1039 additions and 272 deletions

3
snippets/dart_snippets/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

View File

@@ -0,0 +1,3 @@
## 1.0.0
- Initial version.

View File

@@ -0,0 +1,2 @@
A sample command-line application with an entrypoint in `bin/`, library code
in `lib/`, and example unit test in `test/`.

View File

@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.
include: package:lints/recommended.yaml
# Uncomment the following section to specify additional rules.
# linter:
# rules:
# - camel_case_types
# analyzer:
# exclude:
# - path/to/excluded/files/**
# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints
# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options

View File

@@ -0,0 +1,5 @@
import 'package:breez_sdk/breez_sdk.dart';
void main(List<String> arguments) {
BreezSDK().initialize();
}

View File

@@ -0,0 +1,10 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
Future<BuyBitcoinResponse> buyBitcoin() async {
// ANCHOR: buy-btc
BuyBitcoinRequest req = const BuyBitcoinRequest(provider: BuyBitcoinProvider.Moonpay);
BuyBitcoinResponse resp = await BreezSDK().buyBitcoin(req: req);
// ANCHOR_END: buy-btc
return resp;
}

View File

@@ -0,0 +1,17 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
Future<void> getLspInfo() async {
// ANCHOR: get-lsp-info
String? lspId = await BreezSDK().lspId();
LspInformation? lspInfo = await BreezSDK().lspInfo();
print(lspId);
print(lspInfo);
// ANCHOR_END: get-lsp-info
}
Future<void> connectLsp(String lspId) async {
// ANCHOR: connect-lsp
return await BreezSDK().connectLSP(lspId);
// ANCHOR_END: connect-lsp
}

View File

@@ -0,0 +1,40 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
Future<List<FiatCurrency>> listFiatCurrencies() async {
// ANCHOR: list-fiat-currencies
List<FiatCurrency> fiatCurrencyList = await BreezSDK().listFiatCurrencies();
// ANCHOR_END: list-fiat-currencies
return fiatCurrencyList;
}
Future<Map<String, Rate>> fetchFiatRates(String lspId) async {
// ANCHOR: fetch-fiat-rates
Map<String, Rate> fiatRatesMap = await BreezSDK().fetchFiatRates();
// print your desired rate
print(fiatRatesMap["USD"]?.value);
// ANCHOR_END: fetch-fiat-rates
return fiatRatesMap;
}
Future<Map<FiatCurrency, Rate>> fiatCurrenciesAndRate() async {
// ANCHOR: get-fiat-currencies-and-rates
List<FiatCurrency> fiatCurrencies = await BreezSDK().listFiatCurrencies();
Map<String, Rate> fiatRates = await BreezSDK().fetchFiatRates();
var sorted = fiatCurrencies.toList();
sorted.sort((f1, f2) {
return f1.id.compareTo(f2.id);
});
Map<FiatCurrency, Rate> result = {};
for (var currency in sorted) {
var rate = fiatRates[currency.id];
if (rate != null) {
result[currency] = rate;
}
}
return result;
// ANCHOR_END: get-fiat-currencies-and-rates
}

View File

@@ -0,0 +1,46 @@
import 'dart:typed_data';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
Future<void> initializeSDK() async {
// ANCHOR: init-sdk
// Initialize SDK logs listener
BreezSDK().initialize();
// Create the default config
Uint8List seed = await BreezSDK().mnemonicToSeed("<mnemonic words>");
String inviteCode = "<invite code>";
String apiKey = "<api key>";
NodeConfig nodeConfig = NodeConfig.greenlight(
config: GreenlightNodeConfig(
partnerCredentials: null,
inviteCode: inviteCode,
),
);
Config config = await BreezSDK().defaultConfig(
envType: EnvironmentType.Production,
apiKey: apiKey,
nodeConfig: nodeConfig,
);
// Customize the config object according to your needs
config = config.copyWith(workingDir: "path to an existing directory");
// Connect to the Breez SDK make it ready for use
return await BreezSDK().connect(config: config, seed: seed);
// ANCHOR_END: init-sdk
}
Future<void> fetchBalance(String lspId) async {
// ANCHOR: fetch-balance
NodeState? nodeInfo = await BreezSDK().nodeInfo();
if (nodeInfo != null) {
int lnBalance = nodeInfo.channelsBalanceMsat;
int onchainBalance = nodeInfo.onchainBalanceMsat;
print(lnBalance);
print(onchainBalance);
}
// ANCHOR_END: fetch-balance
}

View File

@@ -0,0 +1,33 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
Future<List<Payment>> listPayments() async {
// ANCHOR: list-payments
ListPaymentsRequest req = ListPaymentsRequest(filter: PaymentTypeFilter.All);
List<Payment> paymentsList = await BreezSDK().listPayments(req: req);
print(paymentsList);
// ANCHOR_END: list-payments
return paymentsList;
}
Future<List<Payment>> listPaymentsFiltered({
DateTime? startDate,
DateTime? endDate,
bool? includeFailures,
int? offset,
int? limit,
}) async {
// ANCHOR: list-payments-filtered
ListPaymentsRequest req = ListPaymentsRequest(
filter: PaymentTypeFilter.Sent,
fromTimestamp: startDate?.millisecondsSinceEpoch,
toTimestamp: endDate?.millisecondsSinceEpoch,
includeFailures: includeFailures,
offset: offset,
limit: limit,
);
List<Payment> paymentsList = await BreezSDK().listPayments(req: req);
print(paymentsList);
// ANCHOR_END: list-payments-filtered
return paymentsList;
}

View File

@@ -0,0 +1,21 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
Future<void> lnurlAuth() async {
// ANCHOR: lnurl-auth
/// Endpoint can also be of the form:
/// keyauth://domain.com/auth?key=val
String lnurlAuthUrl =
"lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu";
InputType inputType = await BreezSDK().parseInput(input: lnurlAuthUrl);
if (inputType is InputType_LnUrlAuth) {
LnUrlCallbackStatus result = await BreezSDK().lnurlAuth(reqData: inputType.data);
if (result is LnUrlCallbackStatus_Ok) {
print("Successfully authenticated");
} else {
print("Failed to authenticate");
}
}
// ANCHOR_END: lnurl-auth
}

View File

@@ -0,0 +1,23 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
Future<void> lnurlPay() async {
// ANCHOR: lnurl-pay
/// Endpoint can also be of the form:
/// lnurlp://domain.com/lnurl-pay?key=val
/// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
String lnurlPayUrl = "lightning@address.com";
InputType inputType = await BreezSDK().parseInput(input: lnurlPayUrl);
if (inputType is InputType_LnUrlPay) {
int amountMsat = inputType.data.minSendable;
LnUrlPayRequest req = LnUrlPayRequest(
data: inputType.data,
amountMsat: amountMsat,
comment: "<comment>",
);
LnUrlPayResult result = await BreezSDK().lnurlPay(req: req);
print(result.data);
}
// ANCHOR_END: lnurl-pay
}

View File

@@ -0,0 +1,23 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
Future<void> lnurlWithdraw() async {
// ANCHOR: lnurl-withdraw
/// Endpoint can also be of the form:
/// lnurlw://domain.com/lnurl-withdraw?key=val
String lnurlWithdrawUrl =
"lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk";
InputType inputType = await BreezSDK().parseInput(input: lnurlWithdrawUrl);
if (inputType is InputType_LnUrlWithdraw) {
int amountMsat = inputType.data.minWithdrawable;
LnUrlWithdrawRequest req = LnUrlWithdrawRequest(
data: inputType.data,
amountMsat: amountMsat,
description: "<description>",
);
LnUrlWithdrawResult result = await BreezSDK().lnurlWithdraw(req: req);
print(result.data);
}
// ANCHOR_END: lnurl-withdraw
}

View File

@@ -0,0 +1,61 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
Future<SwapInfo> generateReceiveOnchainAddress() async {
// ANCHOR: generate-receive-onchain-address
ReceiveOnchainRequest req = const ReceiveOnchainRequest();
SwapInfo swapInfo = await BreezSDK().receiveOnchain(req: req);
// Send your funds to the below bitcoin address
final address = swapInfo.bitcoinAddress;
print(address);
return swapInfo;
// ANCHOR_END: generate-receive-onchain-address
}
Future<SwapInfo?> getInProgressSwap() async {
// ANCHOR: in-progress-swap
SwapInfo? swapInfo = await BreezSDK().inProgressSwap();
print(swapInfo);
// ANCHOR_END: in-progress-swap
return swapInfo;
}
Future<List<SwapInfo>> listRefundables() async {
// ANCHOR: list-refundables
List<SwapInfo> refundables = await BreezSDK().listRefundables();
for (var refundable in refundables) {
print(refundable.bitcoinAddress);
}
// ANCHOR_END: list-refundables
return refundables;
}
Future<RefundResponse> executeRefund({
required String swapAddress,
required String toAddress,
required int satPerVbyte,
}) async {
// ANCHOR: execute-refund
RefundRequest req = RefundRequest(
swapAddress: swapAddress,
toAddress: toAddress,
satPerVbyte: satPerVbyte,
);
RefundResponse resp = await BreezSDK().refund(req: req);
print(resp.refundTxId);
// ANCHOR_END: execute-refund
return resp;
}
Future<OpenChannelFeeResponse> getChannelOpeningFees({
required int amountMsat,
int? expiry,
}) async {
// ANCHOR: get-channel-opening-fees
OpenChannelFeeRequest req = OpenChannelFeeRequest(amountMsat: amountMsat, expiry: expiry);
OpenChannelFeeResponse resp = await BreezSDK().openChannelFee(req: req);
print(resp.feeMsat);
// ANCHOR_END: get-channel-opening-fees
return resp;
}

View File

@@ -0,0 +1,14 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
Future<ReceivePaymentResponse> receivePayment() async {
// ANCHOR: receive-payment
ReceivePaymentRequest req = const ReceivePaymentRequest(
amountMsat: 3000000,
description: "Invoice for 3000 sats",
);
ReceivePaymentResponse resp = await BreezSDK().receivePayment(req: req);
print(resp.lnInvoice);
// ANCHOR_END: receive-payment
return resp;
}

View File

@@ -0,0 +1,46 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
Future<ReverseSwapPairInfo> estimateCurrentFees() async {
// ANCHOR: estimate-current-reverse-swap-total-fees
ReverseSwapFeesRequest req = const ReverseSwapFeesRequest(sendAmountSat: 50000);
ReverseSwapPairInfo currentFees = await BreezSDK().fetchReverseSwapFees(req: req);
print("Total estimated fees for reverse swap: ${currentFees.totalEstimatedFees}");
// ANCHOR_END: estimate-current-reverse-swap-total-fees
return currentFees;
}
void listCurrentFees({required ReverseSwapPairInfo currentFees}) {
// 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
}
Future<SendOnchainResponse> startReverseSwap({
required int amountSat,
required String onchainRecipientAddress,
required String pairHash,
required int satPerVbyte,
}) async {
// ANCHOR: start-reverse-swap
SendOnchainRequest req = SendOnchainRequest(
amountSat: amountSat,
onchainRecipientAddress: onchainRecipientAddress,
pairHash: pairHash,
satPerVbyte: satPerVbyte,
);
SendOnchainResponse resp = await BreezSDK().sendOnchain(req: req);
// ANCHOR_END: start-reverse-swap
return resp;
}
Future<List<ReverseSwapInfo>> checkReverseSwapStatus() async {
// ANCHOR: check-reverse-swaps-status
List<ReverseSwapInfo> inProgRevSwapList = await BreezSDK().inProgressReverseSwaps();
for (var inProgRevSwap in inProgRevSwapList) {
print("Reverse swap ${inProgRevSwap.id} in progress, status is ${inProgRevSwap.status.name}");
}
// ANCHOR_END: check-reverse-swaps-status
return inProgRevSwapList;
}

View File

@@ -0,0 +1,10 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
Future<SendPaymentResponse> buyBitcoin({required String bolt11}) async {
// ANCHOR: send-payment
SendPaymentRequest req = SendPaymentRequest(bolt11: bolt11);
SendPaymentResponse resp = await BreezSDK().sendPayment(req: req);
// ANCHOR_END: send-payment
return resp;
}

View File

@@ -0,0 +1,15 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
Future<SendPaymentResponse> sendSpontaneousPayment({
required String nodeId,
}) async {
// ANCHOR: send-spontaneous-payment
SendSpontaneousPaymentRequest req = SendSpontaneousPaymentRequest(
amountMsat: 3000000,
nodeId: nodeId,
);
SendPaymentResponse resp = await BreezSDK().sendSpontaneousPayment(req: req);
// ANCHOR_END: send-spontaneous-payment
return resp;
}

View File

@@ -0,0 +1,10 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
Future<StaticBackupResponse> retrieveBackupFiles({required String workingDir}) async {
// ANCHOR: static-channel-backup
StaticBackupRequest req = StaticBackupRequest(workingDir: workingDir);
StaticBackupResponse resp = await BreezSDK().staticBackup(req: req);
// ANCHOR_END: static-channel-backup
return resp;
}

View File

@@ -0,0 +1,585 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
_fe_analyzer_shared:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: ae92f5d747aee634b87f89d9946000c2de774be1d6ac3e58268224348cd0101a
url: "https://pub.dev"
source: hosted
version: "61.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
sha256: ea3d8652bda62982addfd92fdc2d0214e5f82e43325104990d4f4c4a2a313562
url: "https://pub.dev"
source: hosted
version: "5.13.0"
archive:
dependency: transitive
description:
name: archive
sha256: "7e0d52067d05f2e0324268097ba723b71cb41ac8a6a2b24d1edf9c536b987b03"
url: "https://pub.dev"
source: hosted
version: "3.4.6"
args:
dependency: transitive
description:
name: args
sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596
url: "https://pub.dev"
source: hosted
version: "2.4.2"
async:
dependency: transitive
description:
name: async
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.dev"
source: hosted
version: "2.11.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
breez_sdk:
dependency: "direct main"
description:
path: "."
ref: HEAD
resolved-ref: "9629def110a9dd03413850a05e9709d3c9794b0d"
url: "https://github.com/breez/breez-sdk-flutter"
source: git
version: "0.2.7"
build:
dependency: transitive
description:
name: build
sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
build_cli_annotations:
dependency: transitive
description:
name: build_cli_annotations
sha256: b59d2769769efd6c9ff6d4c4cede0be115a566afc591705c2040b707534b1172
url: "https://pub.dev"
source: hosted
version: "2.1.0"
build_config:
dependency: transitive
description:
name: build_config
sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1
url: "https://pub.dev"
source: hosted
version: "1.1.1"
characters:
dependency: transitive
description:
name: characters
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
url: "https://pub.dev"
source: hosted
version: "1.2.1"
checked_yaml:
dependency: transitive
description:
name: checked_yaml
sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff
url: "https://pub.dev"
source: hosted
version: "2.0.3"
collection:
dependency: transitive
description:
name: collection
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
url: "https://pub.dev"
source: hosted
version: "1.17.0"
colorize:
dependency: transitive
description:
name: colorize
sha256: "584746cd6ba1cba0633b6720f494fe6f9601c4170f0666c1579d2aa2a61071ba"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
convert:
dependency: transitive
description:
name: convert
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
url: "https://pub.dev"
source: hosted
version: "3.1.1"
coverage:
dependency: transitive
description:
name: coverage
sha256: "595a29b55ce82d53398e1bcc2cba525d7bd7c59faeb2d2540e9d42c390cfeeeb"
url: "https://pub.dev"
source: hosted
version: "1.6.4"
crypto:
dependency: transitive
description:
name: crypto
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab
url: "https://pub.dev"
source: hosted
version: "3.0.3"
dart_style:
dependency: transitive
description:
name: dart_style
sha256: "1efa911ca7086affd35f463ca2fc1799584fb6aa89883cf0af8e3664d6a02d55"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
ffi:
dependency: transitive
description:
name: ffi
sha256: ed5337a5660c506388a9f012be0288fb38b49020ce2b45fe1f8b8323fe429f99
url: "https://pub.dev"
source: hosted
version: "2.0.2"
file:
dependency: transitive
description:
name: file
sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d"
url: "https://pub.dev"
source: hosted
version: "6.1.4"
flutter:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
flutter_rust_bridge:
dependency: transitive
description:
name: flutter_rust_bridge
sha256: "8dcfeff9dcf0db9c76578c8805a337c0e5e21b4d96887eb1007b6fe141e15ea9"
url: "https://pub.dev"
source: hosted
version: "1.75.2"
freezed:
dependency: transitive
description:
name: freezed
sha256: "2df89855fe181baae3b6d714dc3c4317acf4fccd495a6f36e5e00f24144c6c3b"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
freezed_annotation:
dependency: transitive
description:
name: freezed_annotation
sha256: c3fd9336eb55a38cc1bbd79ab17573113a8deccd0ecbbf926cca3c62803b5c2d
url: "https://pub.dev"
source: hosted
version: "2.4.1"
frontend_server_client:
dependency: transitive
description:
name: frontend_server_client
sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612"
url: "https://pub.dev"
source: hosted
version: "3.2.0"
glob:
dependency: transitive
description:
name: glob
sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
http:
dependency: transitive
description:
name: http
sha256: "5895291c13fa8a3bd82e76d5627f69e0d85ca6a30dcac95c4ea19a5d555879c2"
url: "https://pub.dev"
source: hosted
version: "0.13.6"
http_multi_server:
dependency: transitive
description:
name: http_multi_server
sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b"
url: "https://pub.dev"
source: hosted
version: "3.2.1"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
url: "https://pub.dev"
source: hosted
version: "4.0.2"
io:
dependency: transitive
description:
name: io
sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e"
url: "https://pub.dev"
source: hosted
version: "1.0.4"
js:
dependency: transitive
description:
name: js
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
url: "https://pub.dev"
source: hosted
version: "0.6.5"
json_annotation:
dependency: transitive
description:
name: json_annotation
sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467
url: "https://pub.dev"
source: hosted
version: "4.8.1"
lints:
dependency: "direct dev"
description:
name: lints
sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
logging:
dependency: transitive
description:
name: logging
sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
matcher:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
url: "https://pub.dev"
source: hosted
version: "0.2.0"
meta:
dependency: transitive
description:
name: meta
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
url: "https://pub.dev"
source: hosted
version: "1.8.0"
mime:
dependency: transitive
description:
name: mime
sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e
url: "https://pub.dev"
source: hosted
version: "1.0.4"
node_preamble:
dependency: transitive
description:
name: node_preamble
sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db"
url: "https://pub.dev"
source: hosted
version: "2.0.2"
package_config:
dependency: transitive
description:
name: package_config
sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
path:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
petitparser:
dependency: transitive
description:
name: petitparser
sha256: "49392a45ced973e8d94a85fdb21293fbb40ba805fc49f2965101ae748a3683b4"
url: "https://pub.dev"
source: hosted
version: "5.1.0"
pointycastle:
dependency: transitive
description:
name: pointycastle
sha256: "7c1e5f0d23c9016c5bbd8b1473d0d3fb3fc851b876046039509e18e0c7485f2c"
url: "https://pub.dev"
source: hosted
version: "3.7.3"
pool:
dependency: transitive
description:
name: pool
sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a"
url: "https://pub.dev"
source: hosted
version: "1.5.1"
pub_semver:
dependency: transitive
description:
name: pub_semver
sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c"
url: "https://pub.dev"
source: hosted
version: "2.1.4"
pubspec_parse:
dependency: transitive
description:
name: pubspec_parse
sha256: c63b2876e58e194e4b0828fcb080ad0e06d051cb607a6be51a9e084f47cb9367
url: "https://pub.dev"
source: hosted
version: "1.2.3"
puppeteer:
dependency: transitive
description:
name: puppeteer
sha256: dd49117259867d0ce0de33ddd95628fb70cff94581a6432c08272447b8dd1d27
url: "https://pub.dev"
source: hosted
version: "2.24.0"
rxdart:
dependency: transitive
description:
name: rxdart
sha256: "0c7c0cedd93788d996e33041ffecda924cc54389199cde4e6a34b440f50044cb"
url: "https://pub.dev"
source: hosted
version: "0.27.7"
shelf:
dependency: transitive
description:
name: shelf
sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4
url: "https://pub.dev"
source: hosted
version: "1.4.1"
shelf_packages_handler:
dependency: transitive
description:
name: shelf_packages_handler
sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
shelf_static:
dependency: transitive
description:
name: shelf_static
sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e
url: "https://pub.dev"
source: hosted
version: "1.1.2"
shelf_web_socket:
dependency: transitive
description:
name: shelf_web_socket
sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1"
url: "https://pub.dev"
source: hosted
version: "1.0.4"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_gen:
dependency: transitive
description:
name: source_gen
sha256: "373f96cf5a8744bc9816c1ff41cf5391bbdbe3d7a96fe98c622b6738a8a7bd33"
url: "https://pub.dev"
source: hosted
version: "1.3.2"
source_map_stack_trace:
dependency: transitive
description:
name: source_map_stack_trace
sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
source_maps:
dependency: transitive
description:
name: source_maps
sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703"
url: "https://pub.dev"
source: hosted
version: "0.10.12"
source_span:
dependency: transitive
description:
name: source_span
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.2"
string_scanner:
dependency: transitive
description:
name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
url: "https://pub.dev"
source: hosted
version: "1.2.1"
test:
dependency: "direct dev"
description:
name: test
sha256: "13b41f318e2a5751c3169137103b60c584297353d4b1761b66029bae6411fe46"
url: "https://pub.dev"
source: hosted
version: "1.24.3"
test_api:
dependency: transitive
description:
name: test_api
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
url: "https://pub.dev"
source: hosted
version: "0.6.0"
test_core:
dependency: transitive
description:
name: test_core
sha256: "99806e9e6d95c7b059b7a0fc08f07fc53fabe54a829497f0d9676299f1e8637e"
url: "https://pub.dev"
source: hosted
version: "0.5.3"
tuple:
dependency: transitive
description:
name: tuple
sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151
url: "https://pub.dev"
source: hosted
version: "2.0.2"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
url: "https://pub.dev"
source: hosted
version: "1.3.2"
uuid:
dependency: transitive
description:
name: uuid
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
url: "https://pub.dev"
source: hosted
version: "3.0.7"
vector_math:
dependency: transitive
description:
name: vector_math
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.dev"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: c538be99af830f478718b51630ec1b6bee5e74e52c8a802d328d9e71d35d2583
url: "https://pub.dev"
source: hosted
version: "11.10.0"
watcher:
dependency: transitive
description:
name: watcher
sha256: "6a7f46926b01ce81bfc339da6a7f20afbe7733eff9846f6d6a5466aa4c6667c0"
url: "https://pub.dev"
source: hosted
version: "1.0.2"
web_socket_channel:
dependency: transitive
description:
name: web_socket_channel
sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b
url: "https://pub.dev"
source: hosted
version: "2.4.0"
webkit_inspection_protocol:
dependency: transitive
description:
name: webkit_inspection_protocol
sha256: "67d3a8b6c79e1987d19d848b0892e582dbb0c66c57cc1fef58a177dd2aa2823d"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
yaml:
dependency: transitive
description:
name: yaml
sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5"
url: "https://pub.dev"
source: hosted
version: "3.1.2"
sdks:
dart: ">=2.19.6 <3.0.0"
flutter: ">=3.7.12"

View File

@@ -0,0 +1,16 @@
name: dart_snippets
description: A sample command-line application.
version: 1.0.0
publish_to: 'none'
environment:
sdk: '>=2.19.6 <3.0.0'
dependencies:
breez_sdk:
git:
url: https://github.com/breez/breez-sdk-flutter
dev_dependencies:
lints: ^2.0.0
test: ^1.21.0

View File

@@ -58,15 +58,7 @@ try {
<section>
```dart
try {
BuyBitcoinResponse buyBitcoinResponse = buyBitcoin(
reqData: BuyBitcoinRequest(
provider: BuyBitcoinProvider.Moonpay,
),
);
} catch {
// Handle error
}
{{#include ../../snippets/dart_snippets/lib/buy_btc.dart:buy-btc}}
```
</section>

View File

@@ -53,12 +53,7 @@ try {
<section>
```dart
try {
List<LspInformation> lspList = await listLsps();
// Select your desired LSP
} catch (e) {
// Handle error
}
{{#include ../../snippets/dart_snippets/lib/connecting_lsp.dart:get-lsp-info}}
```
</section>
@@ -152,12 +147,7 @@ try {
<section>
```dart
try {
String lspId = await lspId();
await connectLSP(lspId);
} catch (e) {
// Handle error
}
{{#include ../../snippets/dart_snippets/lib/connecting_lsp.dart:connect-lsp}}
```
</section>

View File

@@ -35,11 +35,7 @@ try {
<section>
```dart
try {
List<FiatCurrency> fiatCurrencyList = await listFiatCurrencies();
} catch(e) {
// Handle error
}
{{#include ../../snippets/dart_snippets/lib/fiat_currencies.dart:list-fiat-currencies}}
```
</section>
@@ -116,13 +112,7 @@ try {
<section>
```dart
try {
Map<String, Rate> fiatRatesMap = await fetchFiatRates();
// print your desired rate
print(fiatRatesMap["USD"]?.value);
} catch(e) {
// Handle error
}
{{#include ../../snippets/dart_snippets/lib/fiat_currencies.dart:fetch-fiat-rates}}
```
</section>
@@ -217,31 +207,7 @@ fun fiatCurrenciesAndRate(): Map<FiatCurrency, Rate> = try {
<section>
```dart
Future<Map<FiatCurrency, Rate>> fiatCurrenciesAndRate() async {
try {
List<FiatCurrency> fiatCurrencies = await _breezLib.listFiatCurrencies();
Map<String, Rate> fiatRates = await _breezLib.fetchFiatRates();
var sorted = fiatCurrencies.toList();
sorted.sort((f1, f2) {
return f1.id.compareTo(f2.id);
});
Map<FiatCurrency, Rate> result = {};
for (var currency in sorted) {
var rate = fiatRates[currency.id];
if (rate != null) {
result[currency] = rate;
}
}
return result;
} catch (e) {
// Handle error
return {};
}
}
{{#include ../../snippets/dart_snippets/lib/fiat_currencies.dart:get-fiat-currencies-and-rates}}
```
</section>

View File

@@ -122,32 +122,7 @@ try {
<section>
```dart
// SDK events listener
breezEventsStream().listen((event) {
print("Received Breez event: $event");
}
// SDK logs listener
breezLogStream().listen((log) {
print("Received Breez log entry: $log");
}
// Create the default config
Uint8List seed = await mnemonicToSeed(phrase: "<mnemonic words>");
String inviteCode = "<invite code>";
String apiKey = "<api key>"
NodeConfg nodeConfig = NodeConfig.greenlight(config: GreenlightNodeConfig(partnerCredentials: null, inviteCode: inviteCode));
Config config = await defaultConfig(configType: EnvironmentType.Production, apiKey: apiKey, nodeConfig: 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
await connect(config: config, seed: seed);
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/getting_started.dart:init-sdk}}
```
</section>
@@ -315,13 +290,7 @@ try {
<section>
```dart
try {
NodeState? nodeInfo = await nodeInfo();
int lnBalance = nodeInfo?.channelsBalanceMsat;
int onchainBalance = nodeInfo?.onchainBalanceMsat;
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/getting_started.dart:fetch-balance}}
```
</section>

View File

@@ -47,13 +47,7 @@ try {
<section>
```dart
try {
List<Payment> payments = await listPayments(
filter: PaymentTypeFilter.All,
);
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/list_payments.dart:list-payments}}
```
</section>
@@ -147,15 +141,7 @@ try {
<section>
```dart
try {
List<Payment> payments = await listPayments(
filter: PaymentTypeFilter.Sent,
fromTimestamp: 1696880000,
includeFailures: true
);
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/list_payments.dart:list-payments-filtered}}
```
</section>

View File

@@ -69,23 +69,7 @@ try {
<section>
```dart
// Endpoint can also be of the form:
// keyauth://domain.com/auth?key=val
String lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu";
try {
InputType inputType = await parse(s: lnurlAuthUrl);
if (inputType is InputType_LnUrlAuth) {
LnUrlCallbackStatus result = await lnurlAuth(reqData: inputType.data);
if (result is LnUrlCallbackStatus_Ok) {
print("Successfully authenticated");
} else {
print("Failed to authenticate");
}
}
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/lnurl_auth.dart:lnurl-auth}}
```
</section>

View File

@@ -65,24 +65,7 @@ try {
<section>
```dart
// Endpoint can also be of the form:
// lnurlp://domain.com/lnurl-pay?key=val
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
String lnurlPayUrl = "lightning@address.com";
try {
InputType inputType = await parseInput(s: lnurlPayUrl);
if (inputType is InputType_LnUrlPay) {
int amountSats = inputType.data.minSendable;
LnUrlCallbackStatus result = await lnurlPay(
reqData: inputType.data,
userAmountSat: amountSats,
comment: "comment",
);
}
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/lnurl_pay.dart:lnurl-pay}}
```
</section>

View File

@@ -67,23 +67,7 @@ try {
<section>
```dart
// Endpoint can also be of the form:
// lnurlw://domain.com/lnurl-withdraw?key=val
String lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk";
try {
InputType inputType = await parseInput(s: lnurlWithdrawUrl);
if (inputType is InputType_LnUrlWithdraw) {
int amountSats = inputType.data.minWithdrawable;
LnUrlCallbackStatus result = await lnurlWithdraw(
reqData: inputType.data,
amountSats: amountSats,
description: "comment",
);
}
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/lnurl_withdraw.dart:lnurl-withdraw}}
```
</section>

View File

@@ -55,16 +55,7 @@ try {
<section>
```dart
try {
SwapInfo swapInfo = await receiveOnchain(
reqData: ReceiveOnchainRequest(),
);
// Send your funds to the below bitcoin address
String address = swapInfo.bitcoinAddress;
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/receive_onchain.dart:generate-receive-onchain-address}}
```
</section>
@@ -160,11 +151,7 @@ try {
<section>
```dart
try {
SwapInfo? swapInfo = await inProgressSwap();
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/receive_onchain.dart:in-progress-swap}}
```
</section>
@@ -257,11 +244,7 @@ try {
<section>
```dart
try {
List<SwapInfo> refundables = await listRefundables()
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/receive_onchain.dart:list-refundables}}
```
</section>
@@ -358,17 +341,7 @@ try {
<section>
```dart
String destinationAddress = "..."
int satPerVbyte = <refund tx fee rate>
try {
String result = await refund(
swapAddress: refundable.bitcoinAddress,
toAddress: destinationAddress,
satPerVbyte: satPerVbyte,
);
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/receive_onchain.dart:execute-refund}}
```
</section>
@@ -470,16 +443,7 @@ do {
<section>
```dart
int amountMsats = <amount msats>
try {
int channelFees = openChannelFee(
req: OpenChannelFeeRequest(
amountMsats: amountMsats,
),
);
} catch {
// Handle error
}
{{#include ../../snippets/dart_snippets/lib/receive_onchain.dart:get-channel-opening-fees}}
```
</section>

View File

@@ -54,16 +54,7 @@ try {
<section>
```dart
try {
ReceivePaymentResponse invoice = await receivePayment(
reqData: ReceivePaymentRequest(
amountSats: 3000,
description: "Invoice for 3000 sats",
),
);
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/receive_payment.dart:receive-payment}}
```
</section>

View File

@@ -53,17 +53,7 @@ try {
<section>
```dart
try {
ReverseSwapPairInfo currentFees = await fetchReverseSwapFees(
req: ReverseSwapFeesRequest(
sendAmountSat: 50000,
),
);
print("Total estimated fees for reverse swap: ${currentFees.totalEstimatedFees}");
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/send_onchain.dart:estimate-current-reverse-swap-total-fees}}
```
</section>
@@ -157,8 +147,7 @@ Log.v("Breez", "Maximum amount, in sats: ${fees.max}")
<section>
```dart
print("Minimum amount, in sats: ${currentFees.min}");
print("Maximum amount, in sats: ${currentFees.max}");
{{#include ../../snippets/dart_snippets/lib/send_onchain.dart:get-current-reverse-swap-min-max}}
```
</section>
@@ -247,20 +236,7 @@ try {
<section>
```dart
String destinationAddress = "bc1..";
int amountSat = <amount>;
int satPerVbyte = <fee rate>
ReverseSwapPairInfo currentFees = <current reverse swap fees>
try {
ReverseSwapInfo reverseSwapInfo = await sendOnchain(
amountSat: amountSat,
onchainRecipientAddress: destinationAddress,
pairHash: currentFees.feesHash,
satPerVbyte: satPerVbyte,
);
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/send_onchain.dart:start-reverse-swap}}
```
</section>
@@ -363,14 +339,7 @@ for (rs in sdk.inProgressReverseSwaps()) {
<section>
```dart
try {
List<ReverseSwapInfo> swaps = await inProgressReverseSwaps();
for (swap in swaps) {
print(`Reverse swap ${swap.id} in progress, status is ${swap.status}`);
}
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/send_onchain.dart:check-reverse-swaps-status}}
```
</section>

View File

@@ -51,15 +51,7 @@ try {
<section>
```dart
String bolt11 = "...";
try {
Payment payment = await sendPayment(
bolt11: bolt11,
amountSats: 3000,
);
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/send_payment.dart:send-payment}}
```
</section>

View File

@@ -49,15 +49,7 @@ try {
<section>
```dart
String nodeId = "...";
try {
Payment payment = await sendSpontaneousPayment(
nodeId: nodeId,
amountSats: 3000,
);
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/send_spontaneous_payment.dart:send-spontaneous-payment}}
```
</section>

View File

@@ -56,15 +56,7 @@ try {
<section>
```dart
try {
StaticBackupResponse backupData = await staticBackup(
request: StaticBackupRequest
workingDir: "<working directory>",
),
);
} catch (error) {
// handle error
}
{{#include ../../snippets/dart_snippets/lib/static_channel_backup.dart:static-channel-backup}}
```
</section>