-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,011 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# https://dart.dev/guides/libraries/private-files | ||
# Created by `dart pub` | ||
.dart_tool/ | ||
packages/ | ||
.flutter-version | ||
.flutter-plugins | ||
.flutter-plugins-dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Steps to compile the snippets locally | ||
1. Build a flutter package | ||
- By running the publish-all-platforms CI in the breez-liquid-sdk repository (use dummy binaries) | ||
- or by cloning https://github.com/breez/breez-liquid-sdk-flutter | ||
2. Place the files in the folder `snippets/dart-snippets/packages/breez-liquid-sdk-flutter` | ||
3. Happy coding | ||
|
||
## Nix | ||
Use the command `nix develop` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: | ||
- packages/** | ||
|
||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import 'package:flutter_breez_liquid/breez_liquid.dart' as liquid_sdk; | ||
|
||
void main() async { | ||
// Initialize library | ||
await liquid_sdk.initialize(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
description = "Flutter flake"; | ||
inputs = { | ||
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
}; | ||
outputs = | ||
{ self | ||
, nixpkgs | ||
, flake-utils | ||
, | ||
}: | ||
flake-utils.lib.eachDefaultSystem (system: | ||
let | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
in | ||
{ | ||
devShells.default = pkgs.mkShell { | ||
buildInputs = with pkgs; [ | ||
flutter | ||
]; | ||
}; | ||
|
||
formatter = pkgs.nixpkgs-fmt; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:flutter_breez_liquid/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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:flutter_breez_liquid/breez_liquid.dart'; | ||
import 'package:flutter_breez_liquid/bridge_generated.dart'; | ||
|
||
Future<void> initializeSDK() async { | ||
// ANCHOR: init-sdk | ||
|
||
// 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("<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 | ||
ConnectRequest connectRequest = ConnectRequest(config: config, seed: seed); | ||
return await breezSDK.connect(req: connectRequest); | ||
// ANCHOR_END: init-sdk | ||
} | ||
|
||
Future<void> 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); | ||
// ANCHOR_END: init-sdk-restore-only | ||
} | ||
|
||
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 | ||
} | ||
|
||
// ANCHOR: logging | ||
void onLogEntry(log) { | ||
print("Received log ${log.level}]: ${log.line}"); | ||
} | ||
|
||
void logging(BreezSDK breezSDK) { | ||
breezSDK.logStream.listen(onLogEntry); | ||
} | ||
// ANCHOR_END: logging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:flutter_breez_liquid/breez_liquid.dart'; | ||
import 'package:flutter_breez_liquid/bridge_generated.dart'; | ||
|
||
Future<List<Payment>> listPayments() async { | ||
// ANCHOR: list-payments | ||
ListPaymentsRequest req = ListPaymentsRequest(); | ||
List<Payment> paymentsList = await breezSDK.listPayments(req: req); | ||
print(paymentsList); | ||
// ANCHOR_END: list-payments | ||
return paymentsList; | ||
} | ||
|
||
Future<List<Payment>> listPaymentsFiltered({ | ||
int? fromTimestamp, | ||
int? toTimestamp, | ||
bool? includeFailures, | ||
int? offset, | ||
int? limit, | ||
}) async { | ||
// ANCHOR: list-payments-filtered | ||
/// Get the desired epoch timestamp in seconds | ||
int fromTimestamp = DateTime.now().subtract(const Duration(minutes: 30)).millisecondsSinceEpoch ~/ 1000; | ||
|
||
ListPaymentsRequest req = ListPaymentsRequest( | ||
filters: [PaymentTypeFilter.Sent], | ||
fromTimestamp: fromTimestamp, | ||
toTimestamp: toTimestamp, | ||
includeFailures: includeFailures, | ||
offset: offset, | ||
limit: limit, | ||
); | ||
List<Payment> paymentsList = await breezSDK.listPayments(req: req); | ||
print(paymentsList); | ||
// ANCHOR_END: list-payments-filtered | ||
return paymentsList; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:flutter_breez_liquid/breez_liquid.dart'; | ||
import 'package:flutter_breez_liquid/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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:flutter_breez_liquid/breez_liquid.dart'; | ||
import 'package:flutter_breez_liquid/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 = "[email protected]"; | ||
|
||
InputType inputType = await breezSDK.parseInput(input: lnurlPayUrl); | ||
if (inputType is InputType_LnUrlPay) { | ||
int amountMsat = inputType.data.minSendable; | ||
String optionalComment = "<comment>"; | ||
String optionalPaymentLabel = "<label>"; | ||
LnUrlPayRequest req = LnUrlPayRequest( | ||
data: inputType.data, | ||
amountMsat: amountMsat, | ||
comment: optionalComment, | ||
paymentLabel: optionalPaymentLabel, | ||
); | ||
LnUrlPayResult result = await breezSDK.lnurlPay(req: req); | ||
print(result.data); | ||
} | ||
// ANCHOR_END: lnurl-pay | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'package:flutter_breez_liquid/breez_liquid.dart'; | ||
import 'package:flutter_breez_liquid/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 | ||
} |
Oops, something went wrong.