Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Breez SDK dependency #29

Merged
merged 6 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ on:
required: false
type: string
default: 'main'
breez_sdk_ref:
description: 'Breez SDK commit/tag/branch reference'
required: false
type: string
default: 'flutter_rust_bridge_v2'
workflow_call:
inputs:
liquid_sdk_ref:
Expand All @@ -40,15 +35,6 @@ jobs:
with:
path: 'lbreez'

# TODO: Liquid - Revert once breez-sdk dependency is removed
- name: 🏗️ Setup breez-sdk repository
uses: actions/checkout@v4
with:
repository: 'breez/breez-sdk'
ssh-key: ${{secrets.REPO_SSH_KEY}}
path: 'breez-sdk'
ref: ${{ inputs.breez_sdk_ref || 'flutter_rust_bridge_v2' }}

- name: 🏗️ Setup breez-liquid-sdk repository
uses: actions/checkout@v4
with:
Expand Down
15 changes: 1 addition & 14 deletions .github/workflows/build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ on:
required: false
type: string
default: 'main'
breez_sdk_ref:
description: 'Breez SDK commit/tag/branch reference'
required: false
type: string
default: 'flutter_rust_bridge_v2'

jobs:
build-android:
Expand Down Expand Up @@ -73,15 +68,6 @@ jobs:
GOOGLE_SERVICES: ${{secrets.GOOGLE_SERVICES}}
run: echo "$GOOGLE_SERVICES" > android/app/google-services.json

# TODO: Liquid - Revert once breez-sdk dependency is removed
- name: 🏗️ Setup breez-sdk repository
uses: actions/checkout@v4
with:
repository: 'breez/breez-sdk'
ssh-key: ${{secrets.REPO_SSH_KEY}}
path: 'breez-sdk'
ref: ${{ inputs.breez_sdk_ref }}

- name: 🏗️ Setup breez-liquid-sdk repository
uses: actions/checkout@v4
with:
Expand All @@ -101,6 +87,7 @@ jobs:
run: |
just clean
just init
just init-sdk

- name: Install flutter_rust_bridge_codegen dependencies
working-directory: breez-liquid-sdk/lib/bindings/langs/flutter/
Expand Down
14 changes: 0 additions & 14 deletions .github/workflows/build-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ on:
required: false
type: string
default: 'main'
breez_sdk_ref:
description: 'Breez SDK commit/tag/branch reference'
required: false
type: string
default: 'flutter_rust_bridge_v2'

jobs:
build-ios:
Expand Down Expand Up @@ -79,15 +74,6 @@ jobs:
working-directory: lbreez
run: echo "$GOOGLE_SERVICES_IOS" > ios/Runner/GoogleService-Info.plist

# TODO: Liquid - Revert once breez-sdk dependency is removed
- name: 🏗️ Setup breez-sdk repository
uses: actions/checkout@v4
with:
repository: 'breez/breez-sdk'
ssh-key: ${{secrets.REPO_SSH_KEY}}
path: 'breez-sdk'
ref: ${{ inputs.breez_sdk_ref }}

- name: 🏗️ Setup breez-liquid-sdk repository
uses: actions/checkout@v4
with:
Expand Down
35 changes: 16 additions & 19 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
PODS:
- app_group_directory (1.0.0):
- Flutter
- breez_sdk (0.4.0):
- Flutter
- clipboard_watcher (0.0.1):
- Flutter
- connectivity_plus (0.0.1):
Expand Down Expand Up @@ -33,11 +31,11 @@ PODS:
- FirebaseCoreInternal (~> 10.0)
- GoogleUtilities/Environment (~> 7.12)
- GoogleUtilities/Logger (~> 7.12)
- FirebaseCoreInternal (10.27.0):
- FirebaseCoreInternal (10.28.0):
- "GoogleUtilities/NSData+zlib (~> 7.8)"
- FirebaseDynamicLinks (10.25.0):
- FirebaseCore (~> 10.0)
- FirebaseInstallations (10.27.0):
- FirebaseInstallations (10.28.0):
- FirebaseCore (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/UserDefaults (~> 7.8)
Expand Down Expand Up @@ -156,18 +154,21 @@ PODS:
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
- sqlite3 (3.46.0):
- sqlite3/common (= 3.46.0)
- sqlite3/common (3.46.0)
- sqlite3/fts5 (3.46.0):
- "sqlite3 (3.46.0+1)":
- "sqlite3/common (= 3.46.0+1)"
- "sqlite3/common (3.46.0+1)"
- "sqlite3/dbstatvtab (3.46.0+1)":
- sqlite3/common
- "sqlite3/fts5 (3.46.0+1)":
- sqlite3/common
- sqlite3/perf-threadsafe (3.46.0):
- "sqlite3/perf-threadsafe (3.46.0+1)":
- sqlite3/common
- sqlite3/rtree (3.46.0):
- "sqlite3/rtree (3.46.0+1)":
- sqlite3/common
- sqlite3_flutter_libs (0.0.1):
- Flutter
- sqlite3 (~> 3.46.0)
- "sqlite3 (~> 3.46.0+1)"
- sqlite3/dbstatvtab
- sqlite3/fts5
- sqlite3/perf-threadsafe
- sqlite3/rtree
Expand All @@ -179,7 +180,6 @@ PODS:

DEPENDENCIES:
- app_group_directory (from `.symlinks/plugins/app_group_directory/ios`)
- breez_sdk (from `.symlinks/plugins/breez_sdk/ios`)
- clipboard_watcher (from `.symlinks/plugins/clipboard_watcher/ios`)
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/darwin`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
Expand Down Expand Up @@ -233,8 +233,6 @@ SPEC REPOS:
EXTERNAL SOURCES:
app_group_directory:
:path: ".symlinks/plugins/app_group_directory/ios"
breez_sdk:
:path: ".symlinks/plugins/breez_sdk/ios"
clipboard_watcher:
:path: ".symlinks/plugins/clipboard_watcher/ios"
connectivity_plus:
Expand Down Expand Up @@ -288,7 +286,6 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
app_group_directory: 7bf9f8f9819ead554de29da7c25fb7a680d6a9a0
breez_sdk: 503ffaabe90dafa43852d1c2927f7e246194d404
clipboard_watcher: 86fb70421aca6f4944e0591a8292605da7784666
connectivity_plus: ddd7f30999e1faaef5967c23d5b6d503d10434db
device_info_plus: 97af1d7e84681a90d0693e63169a5d50e0839a0d
Expand All @@ -297,9 +294,9 @@ SPEC CHECKSUMS:
firebase_dynamic_links: 525e9c1b702d2ed2d9b0dbd342eee1e15a75e62d
firebase_messaging: 06391e8f35dc65a00c56580266285263d2861f10
FirebaseCore: 7ec4d0484817f12c3373955bc87762d96842d483
FirebaseCoreInternal: 4b297a2d56063dbea2c1d0d04222d44a8d058862
FirebaseCoreInternal: 58d07f1362fddeb0feb6a857d1d1d1c5e558e698
FirebaseDynamicLinks: 12c9f5b643943e0565ed28080373f89cbcb914a3
FirebaseInstallations: 766dabca09fd94aef922538aaf144cc4a6fb6869
FirebaseInstallations: 60c1d3bc1beef809fd1ad1189a8057a040c59f2e
FirebaseMessaging: 88950ba9485052891ebe26f6c43a52bb62248952
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_breez_liquid: 90494dd8df26d6258f0d2a90663204ee6257ede2
Expand Down Expand Up @@ -330,8 +327,8 @@ SPEC CHECKSUMS:
share_plus: 8875f4f2500512ea181eef553c3e27dba5135aad
shared_preference_app_group: 46aee3873e1da581d4904bece9876596d7f66725
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
sqlite3: 154b084339ede06960a5b3c8160066adc9176b7d
sqlite3_flutter_libs: 0d611efdf6d1c9297d5ab03dab21b75aeebdae31
sqlite3: 292c3e1bfe89f64e51ea7fc7dab9182a017c8630
sqlite3_flutter_libs: c00457ebd31e59fa6bb830380ddba24d44fbcd3b
TOCropViewController: edfd4f25713d56905ad1e0b9f5be3fbe0f59c863
uni_links: d97da20c7701486ba192624d99bffaaffcfc298a
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe
Expand Down
21 changes: 11 additions & 10 deletions lib/bloc/currency/currency_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import 'dart:async';

import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/sdk.dart';
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:l_breez/bloc/account/breez_liquid_sdk.dart';
import 'package:l_breez/bloc/currency/currency_state.dart';
import 'package:l_breez/services/injector.dart';

class CurrencyBloc extends Cubit<CurrencyState> with HydratedMixin {
final BreezSDK _breezSDK;
final BreezLiquidSDK liquidSdk;

CurrencyBloc(this._breezSDK) : super(CurrencyState.initial()) {
CurrencyBloc(this.liquidSdk) : super(CurrencyState.initial()) {
hydrate();
_initializeCurrencyBloc();
}

void _initializeCurrencyBloc() {
late final StreamSubscription streamSubscription;
// TODO: Liquid - Listen to Liquid SDK's invoice paid stream
final breezLiquidSdk = ServiceInjector().liquidSDK;
streamSubscription = breezLiquidSdk.walletInfoStream.listen(
streamSubscription = liquidSdk.walletInfoStream.listen(
(walletInfo) {
listFiatCurrencies();
fetchExchangeRates();
Expand All @@ -28,7 +25,7 @@ class CurrencyBloc extends Cubit<CurrencyState> with HydratedMixin {
}

void listFiatCurrencies() {
_breezSDK.listFiatCurrencies().then((fiatCurrencies) {
liquidSdk.wallet!.listFiatCurrencies().then((fiatCurrencies) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this isn't under review (sorry for throwing the 🔧). I think name wallet might become confusing for devs using the SDK, especially when listing fiat rates etc. They might assume its access to the underlying liquid wallet. Something like instance might be better (if it's not a reserved word) liquidSdk.instance!.listFiatCurrencies()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Let's open an issue for it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

emit(state.copyWith(
fiatCurrenciesData: _sortedFiatCurrenciesList(
fiatCurrencies,
Expand Down Expand Up @@ -59,7 +56,11 @@ class CurrencyBloc extends Cubit<CurrencyState> with HydratedMixin {
}

Future<Map<String, Rate>> fetchExchangeRates() async {
var exchangeRates = await _breezSDK.fetchFiatRates();
final List<Rate> rates = await liquidSdk.wallet!.fetchFiatRates();
final exchangeRates = rates.fold<Map<String, Rate>>({}, (map, rate) {
map[rate.coin] = rate;
return map;
});
emit(state.copyWith(exchangeRates: exchangeRates));
return exchangeRates;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/currency/currency_state.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:breez_sdk/sdk.dart';
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';
import 'package:l_breez/models/currency.dart';
import 'package:l_breez/utils/fiat_conversion.dart';

Expand Down
37 changes: 6 additions & 31 deletions lib/bloc/input/input_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'dart:async';

import 'package:breez_sdk/sdk.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart' as liquid_sdk;
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';
import 'package:l_breez/bloc/input/input_data.dart';
import 'package:l_breez/bloc/input/input_printer.dart';
import 'package:l_breez/bloc/input/input_source.dart';
Expand Down Expand Up @@ -71,28 +70,10 @@ class InputBloc extends Cubit<InputState> {
// Emit an empty InputState with isLoading to display a loader on UI layer
emit(const InputState.loading());
try {
/*
final parsedInput = await parseInput(input: input.data);
final parsedInput = await parse(input: input.data);
return await _handleParsedInput(parsedInput, input.source);
*/
final parsedInput = parseInvoice(input: input.data);
final req = liquid_sdk.PrepareSendRequest(invoice: parsedInput.bolt11);
final resp = await ServiceInjector().liquidSDK.wallet!.prepareSendPayment(req: req);
// TODO: Liquid/FRB - Address BigInt & Int changes
return InputState.invoice(
Invoice(
bolt11: resp.invoice,
paymentHash: parsedInput.paymentHash,
description: parsedInput.description ?? "",
amountMsat: parsedInput.amountMsat ?? BigInt.zero,
expiry: parsedInput.expiry,
lspFee: resp.feesSat.toInt(),
),
input.source,
);
} catch (e) {
// TODO: Liquid - Revert back to "Failed to parse input" once InputParser is fully integrated into Liquid SDK
_log.severe("Failed to prepare Send Payment", e);
_log.severe("Failed to parse input", e);
return const InputState.empty();
}
});
Expand All @@ -102,10 +83,6 @@ class InputBloc extends Cubit<InputState> {
_log.info("handlePaymentRequest: $inputData source: $source");
final LNInvoice lnInvoice = inputData.invoice;

/*NodeState? nodeState = await _breezSDK.nodeInfo();
if (nodeState == null || nodeState.id == lnInvoice.payeePubkey) {
return const InputState.empty();
}*/
final invoice = Invoice(
bolt11: lnInvoice.bolt11,
paymentHash: lnInvoice.paymentHash,
Expand All @@ -116,8 +93,6 @@ class InputBloc extends Cubit<InputState> {
return InputState.invoice(invoice, source);
}

// TODO: Liquid - Implement input parser to parse bolt11 invoice - https://github.com/breez/breez-liquid-sdk/issues/232
// ignore: unused_element
Future<InputState> _handleParsedInput(InputType parsedInput, InputSource source) async {
_log.info("handleParsedInput: $source => ${inputTypeToString(parsedInput)}");
InputState result;
Expand All @@ -144,8 +119,8 @@ class InputBloc extends Cubit<InputState> {
return result;
}

liquid_sdk.LNInvoice parseInvoice({required String input}) {
_log.info("parseInvoice: $input");
return liquid_sdk.parseInvoice(input: input);
Future<InputType> parseInput({required String input}) async {
_log.info("parseInput: $input");
return await parse(input: input);
}
}
2 changes: 1 addition & 1 deletion lib/bloc/input/input_printer.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:breez_sdk/sdk.dart';
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';

String inputTypeToString(InputType inputType) {
if (inputType is InputType_BitcoinAddress) {
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/input/input_state.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:breez_sdk/sdk.dart';
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';
import 'package:l_breez/bloc/input/input_printer.dart';
import 'package:l_breez/bloc/input/input_source.dart';
import 'package:l_breez/models/invoice.dart';
Expand Down
7 changes: 1 addition & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ void main() async {
//await Firebase.initializeApp();
final injector = ServiceInjector();
var breezLogger = injector.breezLogger;
// TODO: Liquid - Remove all BreezSDK logic - Requires FiatCurrency & InputParser to be extracted to a shared library among SDK's
final breezSDK = injector.breezSDK;
if (!await breezSDK.isInitialized()) {
breezSDK.initialize();
}

// Initialize Log Stream
if (injector.liquidSDK.wallet == null) {
Expand Down Expand Up @@ -83,7 +78,7 @@ void main() async {
create: (BuildContext context) => UserProfileBloc(),
),
BlocProvider<CurrencyBloc>(
create: (BuildContext context) => CurrencyBloc(breezSDK),
create: (BuildContext context) => CurrencyBloc(injector.liquidSDK),
),
BlocProvider<SecurityBloc>(
create: (BuildContext context) => SecurityBloc(),
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/fiat_currencies/fiat_currency_settings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:breez_sdk/sdk.dart';
import 'package:breez_translations/breez_translations_locales.dart';
import 'package:breez_translations/generated/breez_translations.dart';
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';
import 'package:l_breez/bloc/currency/currency_bloc.dart';
import 'package:l_breez/bloc/currency/currency_state.dart';
import 'package:l_breez/theme/theme_provider.dart' as theme;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,15 @@ class EnterPaymentInfoDialogState extends State<EnterPaymentInfoDialog> {
final texts = context.texts();
try {
_setValidatorErrorMessage("");
// TODO: Liquid - Previously parseInput, parseInvoice only parses LNInvoice's.
final inputType = context.read<InputBloc>().parseInvoice(input: input);
final inputType = context.read<InputBloc>().parseInput(input: input);
_log.info("Parsed input type: '${inputType.runtimeType.toString()}");
// Can't compare against a list of InputType as runtime type comparison is a bit tricky with binding generated enums
// TODO: Liquid - Add other supported InputType's once parse_invoice has evolved into parse_input.
// ignore: unnecessary_type_check
if (inputType is! LNInvoice) {
if (!(inputType is InputType_Bolt11 ||
inputType is InputType_LnUrlPay ||
inputType is InputType_LnUrlWithdraw ||
inputType is InputType_LnUrlAuth ||
inputType is InputType_LnUrlError ||
inputType is InputType_NodeId)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think NodeId would also not be supported

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. It'll be removed as part of #30

_setValidatorErrorMessage(texts.payment_info_dialog_error_unsupported_input);
}
} catch (e) {
Expand Down
Loading
Loading