Skip to content

Commit

Permalink
Integrate Send/Receive Chain Swap (#46, #47)
Browse files Browse the repository at this point in the history
* Update dependencies to latest
* Create ChainSwap Bloc
* Apply BigInt/int changes on payment errors
* Integrate Receive Chain Swap
* Integrate Send Chain Swap
  • Loading branch information
erdemyerebasmaz authored Jul 12, 2024
1 parent a79f575 commit 9e18303
Show file tree
Hide file tree
Showing 31 changed files with 1,530 additions and 68 deletions.
57 changes: 29 additions & 28 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@ PODS:
- FlutterMacOS
- device_info_plus (0.0.1):
- Flutter
- Firebase/CoreOnly (10.27.0):
- FirebaseCore (= 10.27.0)
- Firebase/DynamicLinks (10.27.0):
- Firebase/CoreOnly (10.28.0):
- FirebaseCore (= 10.28.0)
- Firebase/DynamicLinks (10.28.0):
- Firebase/CoreOnly
- FirebaseDynamicLinks (~> 10.27.0)
- Firebase/Messaging (10.27.0):
- FirebaseDynamicLinks (~> 10.28.0)
- Firebase/Messaging (10.28.0):
- Firebase/CoreOnly
- FirebaseMessaging (~> 10.27.0)
- firebase_core (3.1.1):
- Firebase/CoreOnly (= 10.27.0)
- FirebaseMessaging (~> 10.28.0)
- firebase_core (3.2.0):
- Firebase/CoreOnly (= 10.28.0)
- Flutter
- firebase_dynamic_links (6.0.2):
- Firebase/DynamicLinks (= 10.27.0)
- firebase_dynamic_links (6.0.3):
- Firebase/DynamicLinks (= 10.28.0)
- firebase_core
- Flutter
- firebase_messaging (15.0.2):
- Firebase/Messaging (= 10.27.0)
- firebase_messaging (15.0.3):
- Firebase/Messaging (= 10.28.0)
- firebase_core
- Flutter
- FirebaseCore (10.27.0):
- FirebaseCore (10.28.0):
- FirebaseCoreInternal (~> 10.0)
- GoogleUtilities/Environment (~> 7.12)
- GoogleUtilities/Logger (~> 7.12)
- FirebaseCoreInternal (10.28.0):
- FirebaseCoreInternal (10.29.0):
- "GoogleUtilities/NSData+zlib (~> 7.8)"
- FirebaseDynamicLinks (10.27.0):
- FirebaseDynamicLinks (10.28.0):
- FirebaseCore (~> 10.0)
- FirebaseInstallations (10.28.0):
- FirebaseInstallations (10.29.0):
- FirebaseCore (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/UserDefaults (~> 7.8)
- PromisesObjC (~> 2.1)
- FirebaseMessaging (10.27.0):
- FirebaseMessaging (10.28.0):
- FirebaseCore (~> 10.0)
- FirebaseInstallations (~> 10.0)
- GoogleDataTransport (~> 9.3)
Expand All @@ -50,7 +50,8 @@ PODS:
- GoogleUtilities/UserDefaults (~> 7.8)
- nanopb (< 2.30911.0, >= 2.30908.0)
- Flutter (1.0.0)
- flutter_breez_liquid (0.1.0)
- flutter_breez_liquid (0.1.0):
- Flutter
- flutter_fgbg (0.0.1):
- Flutter
- flutter_inappwebview_ios (0.0.1):
Expand Down Expand Up @@ -289,17 +290,17 @@ SPEC CHECKSUMS:
clipboard_watcher: 86fb70421aca6f4944e0591a8292605da7784666
connectivity_plus: ddd7f30999e1faaef5967c23d5b6d503d10434db
device_info_plus: 97af1d7e84681a90d0693e63169a5d50e0839a0d
Firebase: 26b040b20866a55f55eb3611b9fcf3ae64816b86
firebase_core: f8d0424c45e0f1e596811085fc12c638d628457c
firebase_dynamic_links: 8a142e279cd3d683bbb8d501d0ff5521d72a8616
firebase_messaging: 8b29edaf5adfd3b52b5bfa5af8128c44164670c6
FirebaseCore: a2b95ae4ce7c83ceecfbbbe3b6f1cddc7415a808
FirebaseCoreInternal: 58d07f1362fddeb0feb6a857d1d1d1c5e558e698
FirebaseDynamicLinks: 087bf18ffabe8b6abe0c80301fd16ba2225ce373
FirebaseInstallations: 60c1d3bc1beef809fd1ad1189a8057a040c59f2e
FirebaseMessaging: 585984d0a1df120617eb10b44cad8968b859815e
Firebase: 5121c624121af81cbc81df3bda414b3c28c4f3c3
firebase_core: a9d0180d5285527884d07a41eb4a9ec9ed12cdb6
firebase_dynamic_links: ef37ec989592ed84f0bbcf2d2f938d4407bee1c2
firebase_messaging: ccc82a143a74de75f440a4e413dbbb37ec3fddbc
FirebaseCore: 857dc1c6dd1255675047404d8466f7dfaac5d779
FirebaseCoreInternal: df84dd300b561c27d5571684f389bf60b0a5c934
FirebaseDynamicLinks: f6a65ece086df7d8366400b8bb99e50dd2659ad4
FirebaseInstallations: 913cf60d0400ebd5d6b63a28b290372ab44590dd
FirebaseMessaging: 087a7c7cadef7b9239f005bc4db823894844f323
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_breez_liquid: b61267976647a385b0446e628fe69421153513f7
flutter_breez_liquid: 707cf69d42f3efbe37836a6fc0d1e7ea7d400e4b
flutter_fgbg: 31c0d1140a131daea2d342121808f6aa0dcd879d
flutter_inappwebview_ios: 97215cf7d4677db55df76782dbd2930c5e1c1ea0
flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069
Expand Down
8 changes: 4 additions & 4 deletions lib/bloc/account/payment_error.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
class PaymentExceededLimitError implements Exception {
final int limitSat;
final BigInt limitSat;

const PaymentExceededLimitError(
this.limitSat,
);
}

class PaymentBelowLimitError implements Exception {
final int limitSat;
final BigInt limitSat;

const PaymentBelowLimitError(
this.limitSat,
Expand Down Expand Up @@ -35,15 +35,15 @@ class PaymentBelowSetupFeesError implements Exception {
}

class PaymentExceedLiquidityError implements Exception {
final int limitSat;
final BigInt limitSat;

const PaymentExceedLiquidityError(
this.limitSat,
);
}

class PaymentExcededLiqudityChannelCreationNotPossibleError implements Exception {
final int limitSat;
final BigInt limitSat;

const PaymentExcededLiqudityChannelCreationNotPossibleError(
this.limitSat,
Expand Down
63 changes: 63 additions & 0 deletions lib/bloc/chainswap/chainswap_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';
import 'package:l_breez/bloc/account/breez_sdk_liquid.dart';
import 'package:l_breez/bloc/account/payment_error.dart';
import 'package:l_breez/bloc/chainswap/chainswap_state.dart';

class ChainSwapBloc extends Cubit<ChainSwapState> {
final BreezSDKLiquid _liquidSdk;

ChainSwapBloc(this._liquidSdk) : super(ChainSwapState.initial());

Future<OnchainPaymentLimitsResponse> fetchOnchainLimits() async {
return await _liquidSdk.instance!.fetchOnchainLimits();
}

Future<PreparePayOnchainResponse> preparePayOnchain({
required PreparePayOnchainRequest req,
}) async {
return await _liquidSdk.instance!.preparePayOnchain(req: req);
}

Future<SendPaymentResponse> payOnchain({
required PayOnchainRequest req,
}) async {
return await _liquidSdk.instance!.payOnchain(req: req);
}

Future<PrepareReceiveOnchainResponse> prepareReceiveOnchain({
required PrepareReceiveOnchainRequest req,
}) async {
return await _liquidSdk.instance!.prepareReceiveOnchain(req: req);
}

Future<ReceiveOnchainResponse> receiveOnchain({
required PrepareReceiveOnchainResponse req,
}) async {
return await _liquidSdk.instance!.receiveOnchain(req: req);
}

Future<RefundResponse> refund({
required RefundRequest req,
}) async {
return await _liquidSdk.instance!.refund(req: req);
}

Future<void> rescanOnchainSwaps() async {
return await _liquidSdk.instance!.rescanOnchainSwaps();
}

void validateSwap(
BigInt amount,
bool outgoing,
OnchainPaymentLimitsResponse onchainLimits,
) {
var limits = outgoing ? onchainLimits.send : onchainLimits.receive;
if (amount > limits.maxSat) {
throw PaymentExceededLimitError(limits.maxSat);
}
if (amount < limits.minSat) {
throw PaymentBelowLimitError(limits.minSat);
}
}
}
5 changes: 5 additions & 0 deletions lib/bloc/chainswap/chainswap_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChainSwapState {
ChainSwapState();

ChainSwapState.initial() : this();
}
4 changes: 4 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:l_breez/bloc/account/account_bloc.dart';
import 'package:l_breez/bloc/account/credentials_manager.dart';
import 'package:l_breez/bloc/backup/backup_bloc.dart';
import 'package:l_breez/bloc/chainswap/chainswap_bloc.dart';
import 'package:l_breez/bloc/currency/currency_bloc.dart';
import 'package:l_breez/bloc/input/input_bloc.dart';
import 'package:l_breez/bloc/lnurl/lnurl_bloc.dart';
Expand Down Expand Up @@ -90,6 +91,9 @@ void main() async {
BlocProvider<LnUrlBloc>(
create: (BuildContext context) => LnUrlBloc(injector.liquidSDK),
),
BlocProvider<ChainSwapBloc>(
create: (BuildContext context) => ChainSwapBloc(injector.liquidSDK),
),
],
child: UserApp(),
),
Expand Down
Loading

0 comments on commit 9e18303

Please sign in to comment.