diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index cc2c0a0cc..50a2094c4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -21,13 +21,15 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 with: - path: 'cbreez' + path: 'cbreez' - uses: actions/checkout@v3 with: - repository: 'breez/breez-sdk' + repository: 'breez/breez-sdk' + ref: 'bindings_request_response' ssh-key: ${{secrets.REPO_SSH_KEY}} path: 'breez-sdk' + # Setup the flutter environment. - uses: subosito/flutter-action@v2 diff --git a/lib/background/payment_hash_poller.dart b/lib/background/payment_hash_poller.dart index aca61bce7..6eab605df 100644 --- a/lib/background/payment_hash_poller.dart +++ b/lib/background/payment_hash_poller.dart @@ -34,11 +34,11 @@ class PaymentHashPoller { final injector = ServiceInjector(); final breezLib = injector.breezSDK; try { - final ListPaymentsRequest request = ListPaymentsRequest( + final ListPaymentsRequest req = ListPaymentsRequest( filter: PaymentTypeFilter.Received, fromTimestamp: DateTime.now().subtract(const Duration(minutes: 30)).millisecondsSinceEpoch, ); - final List paymentList = await breezLib.listPayments(request: request); + final List paymentList = await breezLib.listPayments(req: req); for (var payment in paymentList) { final detailsData = payment.details.data; final isPaymentReceived = payment.status == PaymentStatus.Complete && diff --git a/lib/bloc/account/account_bloc.dart b/lib/bloc/account/account_bloc.dart index 66c140524..20d2cf111 100644 --- a/lib/bloc/account/account_bloc.dart +++ b/lib/bloc/account/account_bloc.dart @@ -131,35 +131,19 @@ class AccountBloc extends Cubit with HydratedMixin { } Future lnurlWithdraw({ - required int amountSats, - required sdk.LnUrlWithdrawRequestData reqData, - String? description, + required sdk.LnUrlWithdrawRequest req, }) async { - _log.info("lnurlWithdraw amount: $amountSats, description: '$description', reqData: $reqData"); try { - return await _breezLib.lnurlWithdraw( - amountSats: amountSats, - reqData: reqData, - description: description, - ); + return await _breezLib.lnurlWithdraw(req: req); } catch (e) { _log.severe("lnurlWithdraw error", e); rethrow; } } - Future lnurlPay({ - required int amount, - required sdk.LnUrlPayRequestData reqData, - String? comment, - }) async { - _log.info("lnurlPay amount: $amount, comment: '$comment', reqData: $reqData"); + Future lnurlPay({required req}) async { try { - return await _breezLib.lnurlPay( - userAmountSat: amount, - reqData: reqData, - comment: comment, - ); + return await _breezLib.lnurlPay(req: req); } catch (e) { _log.severe("lnurlPay error", e); rethrow; @@ -181,7 +165,11 @@ class AccountBloc extends Cubit with HydratedMixin { Future sendPayment(String bolt11, int? amountMsat) async { _log.info("sendPayment: $bolt11, $amountMsat"); try { - await _breezLib.sendPayment(bolt11: bolt11, amountMsat: amountMsat); + final req = sdk.SendPaymentRequest( + bolt11: bolt11, + amountMsat: amountMsat, + ); + await _breezLib.sendPayment(req: req); } catch (e) { _log.severe("sendPayment error", e); return Future.error(e); @@ -193,18 +181,19 @@ class AccountBloc extends Cubit with HydratedMixin { throw Exception("not implemented"); } - Future sendSpontaneousPayment( - String nodeId, - String description, - int amountSats, - ) async { - _log.info("sendSpontaneousPayment: $nodeId, $description, $amountSats"); + Future sendSpontaneousPayment({ + required String nodeId, + String? description, + required int amountMsat, + }) async { + _log.info("sendSpontaneousPayment: $nodeId, $description, $amountMsat"); _log.info("description field is not being used by the SDK yet"); try { - await _breezLib.sendSpontaneousPayment( + final req = sdk.SendSpontaneousPaymentRequest( nodeId: nodeId, - amountSats: amountSats, + amountMsat: amountMsat, ); + await _breezLib.sendSpontaneousPayment(req: req); } catch (e) { _log.severe("sendSpontaneousPayment error", e); return Future.error(e); @@ -274,15 +263,17 @@ class AccountBloc extends Cubit with HydratedMixin { Future addInvoice({ String description = "", - required int amountSats, + required int amountMsat, required sdk.OpeningFeeParams? chosenFeeParams, }) async { - _log.info("addInvoice: $description, $amountSats"); + _log.info("addInvoice: $description, $amountMsat"); - final requestData = sdk.ReceivePaymentRequest( - amountSats: amountSats, description: description, openingFeeParams: chosenFeeParams); - final responseData = await _breezLib.receivePayment(reqData: requestData); - return responseData; + final req = sdk.ReceivePaymentRequest( + amountMsat: amountMsat, + description: description, + openingFeeParams: chosenFeeParams, + ); + return await _breezLib.receivePayment(req: req); } @override diff --git a/lib/bloc/account/credentials_manager.dart b/lib/bloc/account/credentials_manager.dart index 898785e80..17626e78b 100644 --- a/lib/bloc/account/credentials_manager.dart +++ b/lib/bloc/account/credentials_manager.dart @@ -58,6 +58,7 @@ class CredentialsManager { final breezLib = ServiceInjector().breezSDK; Config config = await Config.instance(); String workingDir = config.sdkConfig.workingDir; - return await breezLib.staticBackup(request: sdk.StaticBackupRequest(workingDir: workingDir)); + final req = sdk.StaticBackupRequest(workingDir: workingDir); + return await breezLib.staticBackup(req: req); } } diff --git a/lib/bloc/buy_bitcoin/moonpay/moonpay_bloc.dart b/lib/bloc/buy_bitcoin/moonpay/moonpay_bloc.dart index 4ca940098..76afffe9c 100644 --- a/lib/bloc/buy_bitcoin/moonpay/moonpay_bloc.dart +++ b/lib/bloc/buy_bitcoin/moonpay/moonpay_bloc.dart @@ -32,8 +32,8 @@ class MoonPayBloc extends Cubit { return; } - sdk.BuyBitcoinRequest reqData = const sdk.BuyBitcoinRequest(provider: sdk.BuyBitcoinProvider.Moonpay); - final buyBitcoinResponse = await _breezLib.buyBitcoin(reqData: reqData); + sdk.BuyBitcoinRequest req = const sdk.BuyBitcoinRequest(provider: sdk.BuyBitcoinProvider.Moonpay); + final buyBitcoinResponse = await _breezLib.buyBitcoin(req: req); _log.info("fetchMoonpayUrl url: ${buyBitcoinResponse.url}"); if (buyBitcoinResponse.openingFeeParams != null) { emit(MoonPayState.urlReady(buyBitcoinResponse)); diff --git a/lib/bloc/refund/refund_bloc.dart b/lib/bloc/refund/refund_bloc.dart index e0b2eeb15..dcbf30139 100644 --- a/lib/bloc/refund/refund_bloc.dart +++ b/lib/bloc/refund/refund_bloc.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:breez_sdk/breez_sdk.dart'; +import 'package:breez_sdk/bridge_generated.dart'; import 'package:c_breez/bloc/refund/refund_state.dart'; import 'package:logging/logging.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -34,13 +35,14 @@ class RefundBloc extends Cubit { }) async { _log.info("Refunding swap $swapAddress to $toAddress with fee $satPerVbyte"); try { - final txId = await _breezLib.refund( + final req = RefundRequest( swapAddress: swapAddress, toAddress: toAddress, satPerVbyte: satPerVbyte, ); - _log.info("Refund txId: $txId"); - return txId; + final refundResponse = await _breezLib.refund(req: req); + _log.info("Refund txId: ${refundResponse.refundTxId}"); + return refundResponse.refundTxId; } catch (e) { _log.severe("Failed to refund swap", e); rethrow; diff --git a/lib/bloc/reverse_swap/reverse_swap_bloc.dart b/lib/bloc/reverse_swap/reverse_swap_bloc.dart index 1176a50dd..8dcae73e8 100644 --- a/lib/bloc/reverse_swap/reverse_swap_bloc.dart +++ b/lib/bloc/reverse_swap/reverse_swap_bloc.dart @@ -26,12 +26,14 @@ class ReverseSwapBloc extends Cubit { "Reverse Swap of $amountSat sats to address $onchainRecipientAddress using $satPerVbyte sats/vByte as" " fee rate w/ pairHash: $pairHash", ); - final reverseSwapInfo = await _breezLib.sendOnchain( + final req = SendOnchainRequest( amountSat: amountSat, onchainRecipientAddress: onchainRecipientAddress, pairHash: pairHash, satPerVbyte: satPerVbyte, ); + final reverseSwapReponse = await _breezLib.sendOnchain(req: req); + final reverseSwapInfo = reverseSwapReponse.reverseSwapInfo; _log.info( "Reverse Swap Info for id: ${reverseSwapInfo.id}, ${reverseSwapInfo.onchainAmountSat} sats to address" " ${reverseSwapInfo.claimPubkey} w/ status: ${reverseSwapInfo.status}", diff --git a/lib/bloc/swap_in_progress/swap_in_progress_bloc.dart b/lib/bloc/swap_in_progress/swap_in_progress_bloc.dart index 880847185..773387cf4 100644 --- a/lib/bloc/swap_in_progress/swap_in_progress_bloc.dart +++ b/lib/bloc/swap_in_progress/swap_in_progress_bloc.dart @@ -35,7 +35,7 @@ class SwapInProgressBloc extends Cubit { if (swapInProgress != null) { swapUnused = null; } else { - swapUnused = (await _breezLib.receiveOnchain(reqData: const ReceiveOnchainRequest())); + swapUnused = (await _breezLib.receiveOnchain(req: const ReceiveOnchainRequest())); } _log.info("swapInProgress: $swapInProgress, swapUnused: $swapUnused"); emit(SwapInProgressState(swapInProgress, swapUnused)); diff --git a/lib/bloc/sweep/sweep_bloc.dart b/lib/bloc/sweep/sweep_bloc.dart index 8b5565839..999946f21 100644 --- a/lib/bloc/sweep/sweep_bloc.dart +++ b/lib/bloc/sweep/sweep_bloc.dart @@ -21,8 +21,11 @@ class SweepBloc extends Cubit { }) async { try { _log.info("Sweep to address $toAddress using $feeRateSatsPerVbyte fee vByte"); - final request = SweepRequest(toAddress: toAddress, feeRateSatsPerVbyte: feeRateSatsPerVbyte); - final sweepRes = await _breezLib.sweep(request: request); + final req = SweepRequest( + toAddress: toAddress, + feeRateSatsPerVbyte: feeRateSatsPerVbyte, + ); + final sweepRes = await _breezLib.sweep(req: req); emit(SweepState(sweepTxId: sweepRes.txid)); return sweepRes; } catch (e) { diff --git a/lib/routes/create_invoice/create_invoice_page.dart b/lib/routes/create_invoice/create_invoice_page.dart index 9a8ca6f12..f19422697 100644 --- a/lib/routes/create_invoice/create_invoice_page.dart +++ b/lib/routes/create_invoice/create_invoice_page.dart @@ -203,7 +203,7 @@ class CreateInvoicePageState extends State { Future receivePaymentResponse = accountBloc.addInvoice( description: _descriptionController.text, - amountSats: currencyBloc.state.bitcoinCurrency.parse(_amountController.text), + amountMsat: currencyBloc.state.bitcoinCurrency.parse(_amountController.text) * 1000, chosenFeeParams: cheapestFeeParams); navigator.pop(); Widget dialog = FutureBuilder( diff --git a/lib/routes/lnurl/auth/lnurl_auth_handler.dart b/lib/routes/lnurl/auth/lnurl_auth_handler.dart index c8e6dbb18..8fe78033e 100644 --- a/lib/routes/lnurl/auth/lnurl_auth_handler.dart +++ b/lib/routes/lnurl/auth/lnurl_auth_handler.dart @@ -13,9 +13,9 @@ final _log = Logger("HandleLNURLAuthRequest"); Future handleAuthRequest( BuildContext context, - LnUrlAuthRequestData requestData, + LnUrlAuthRequestData reqData, ) async { - return promptAreYouSure(context, null, LoginText(domain: requestData.domain)).then( + return promptAreYouSure(context, null, LoginText(domain: reqData.domain)).then( (permitted) async { if (permitted == true) { final texts = context.texts(); @@ -23,7 +23,7 @@ Future handleAuthRequest( final loaderRoute = createLoaderRoute(context); navigator.push(loaderRoute); try { - final resp = await context.read().lnurlAuth(reqData: requestData); + final resp = await context.read().lnurlAuth(reqData: reqData); if (resp is LnUrlCallbackStatus_Ok) { _log.info("LNURL auth success"); return const LNURLPageResult(protocol: LnUrlProtocol.Auth); diff --git a/lib/routes/lnurl/payment/lnurl_payment_dialog.dart b/lib/routes/lnurl/payment/lnurl_payment_dialog.dart index 854f3ffda..5ded2c96b 100644 --- a/lib/routes/lnurl/payment/lnurl_payment_dialog.dart +++ b/lib/routes/lnurl/payment/lnurl_payment_dialog.dart @@ -13,10 +13,10 @@ import 'package:flutter_bloc/flutter_bloc.dart'; final _log = Logger("LNURLPaymentDialog"); class LNURLPaymentDialog extends StatefulWidget { - final sdk.LnUrlPayRequestData requestData; + final sdk.LnUrlPayRequestData data; const LNURLPaymentDialog({ - required this.requestData, + required this.data, Key? key, }) : super(key: key); @@ -40,7 +40,7 @@ class LNURLPaymentDialogState extends State { final texts = context.texts(); final currencyState = context.read().state; final metadataMap = { - for (var v in json.decode(widget.requestData.metadataStr)) v[0] as String: v[1], + for (var v in json.decode(widget.data.metadataStr)) v[0] as String: v[1], }; final description = metadataMap['text/long-desc'] ?? metadataMap['text/plain']; FiatConversion? fiatConversion; @@ -53,7 +53,7 @@ class LNURLPaymentDialogState extends State { return AlertDialog( title: Text( - Uri.parse(widget.requestData.callback).host, + Uri.parse(widget.data.callback).host, style: themeData.primaryTextTheme.headlineMedium!.copyWith(fontSize: 16), textAlign: TextAlign.center, ), @@ -84,9 +84,9 @@ class LNURLPaymentDialogState extends State { ), child: Text( _showFiatCurrency && fiatConversion != null - ? fiatConversion.format(widget.requestData.maxSendable ~/ 1000) + ? fiatConversion.format(widget.data.maxSendable ~/ 1000) : BitcoinCurrency.fromTickerSymbol(currencyState.bitcoinTicker) - .format(widget.requestData.maxSendable ~/ 1000), + .format(widget.data.maxSendable ~/ 1000), style: themeData.primaryTextTheme.headlineSmall, textAlign: TextAlign.center, ), @@ -146,10 +146,10 @@ class LNURLPaymentDialogState extends State { }), ), onPressed: () { - final amount = widget.requestData.maxSendable ~/ 1000; + final amount = widget.data.maxSendable ~/ 1000; _log.info("LNURL payment of $amount sats where " - "min is ${widget.requestData.minSendable} msats " - "and max is ${widget.requestData.maxSendable} msats."); + "min is ${widget.data.minSendable} msats " + "and max is ${widget.data.maxSendable} msats."); Navigator.pop(context, LNURLPaymentInfo(amount: amount)); }, child: Text( diff --git a/lib/routes/lnurl/payment/lnurl_payment_handler.dart b/lib/routes/lnurl/payment/lnurl_payment_handler.dart index 0f50d0215..574e8e905 100644 --- a/lib/routes/lnurl/payment/lnurl_payment_handler.dart +++ b/lib/routes/lnurl/payment/lnurl_payment_handler.dart @@ -16,22 +16,22 @@ final _log = Logger("HandleLNURLPayRequest"); Future handlePayRequest( BuildContext context, GlobalKey firstPaymentItemKey, - LnUrlPayRequestData requestData, + LnUrlPayRequestData data, ) async { LNURLPaymentInfo? paymentInfo; - bool fixedAmount = requestData.minSendable == requestData.maxSendable; - if (fixedAmount && !(requestData.commentAllowed > 0)) { + bool fixedAmount = data.minSendable == data.maxSendable; + if (fixedAmount && !(data.commentAllowed > 0)) { // Show dialog if payment is of fixed amount with no payer comment allowed paymentInfo = await showDialog( useRootNavigator: false, context: context, barrierDismissible: false, - builder: (_) => LNURLPaymentDialog(requestData: requestData), + builder: (_) => LNURLPaymentDialog(data: data), ); } else { paymentInfo = await Navigator.of(context).push( FadeInRoute( - builder: (_) => LNURLPaymentPage(requestData: requestData), + builder: (_) => LNURLPaymentPage(data: data), ), ); } @@ -47,11 +47,15 @@ Future handlePayRequest( builder: (_) => ProcessingPaymentDialog( isLnurlPayment: true, firstPaymentItemKey: firstPaymentItemKey, - paymentFunc: () => context.read().lnurlPay( - amount: paymentInfo!.amount, - comment: paymentInfo.comment, - reqData: requestData, - ), + paymentFunc: () { + final accBloc = context.read(); + final req = LnUrlPayRequest( + amountMsat: paymentInfo!.amount * 1000, + comment: paymentInfo.comment, + data: data, + ); + return accBloc.lnurlPay(req: req); + }, ), ).then((result) { if (result is LnUrlPayResult) { diff --git a/lib/routes/lnurl/payment/lnurl_payment_page.dart b/lib/routes/lnurl/payment/lnurl_payment_page.dart index d6459c3ac..ec7f02d46 100644 --- a/lib/routes/lnurl/payment/lnurl_payment_page.dart +++ b/lib/routes/lnurl/payment/lnurl_payment_page.dart @@ -21,7 +21,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; final _log = Logger("LNURLPaymentPage"); class LNURLPaymentPage extends StatefulWidget { - final sdk.LnUrlPayRequestData requestData; + final sdk.LnUrlPayRequestData data; /*TODO: Add domain information to parse results #118(https://github.com/breez/breez-sdk/issues/118) final String domain; TODO: Add support for LUD-18: Payer identity in payRequest protocol(https://github.com/breez/breez-sdk/issues/117) @@ -32,7 +32,7 @@ class LNURLPaymentPage extends StatefulWidget { */ const LNURLPaymentPage({ - required this.requestData, + required this.data, /* required this.domain, this.name, @@ -66,9 +66,9 @@ class LNURLPaymentPageState extends State { @override void initState() { super.initState(); - fixedAmount = widget.requestData.minSendable == widget.requestData.maxSendable; + fixedAmount = widget.data.minSendable == widget.data.maxSendable; if (fixedAmount) { - _amountController.text = (widget.requestData.maxSendable ~/ 1000).toString(); + _amountController.text = (widget.data.maxSendable ~/ 1000).toString(); } } @@ -77,7 +77,7 @@ class LNURLPaymentPageState extends State { final texts = context.texts(); final currencyState = context.read().state; final metadataMap = { - for (var v in json.decode(widget.requestData.metadataStr)) v[0] as String: v[1], + for (var v in json.decode(widget.data.metadataStr)) v[0] as String: v[1], }; String? base64String = metadataMap['image/png;base64'] ?? metadataMap['image/jpeg;base64']; @@ -86,7 +86,7 @@ class LNURLPaymentPageState extends State { appBar: AppBar( leading: const back_button.BackButton(), // Todo: Use domain from request data - title: Text(texts.lnurl_fetch_invoice_pay_to_payee(Uri.parse(widget.requestData.callback).host)), + title: Text(texts.lnurl_fetch_invoice_pay_to_payee(Uri.parse(widget.data.callback).host)), ), body: Form( key: _formKey, @@ -96,13 +96,13 @@ class LNURLPaymentPageState extends State { mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (widget.requestData.commentAllowed > 0) ...[ + if (widget.data.commentAllowed > 0) ...[ TextFormField( controller: _commentController, keyboardType: TextInputType.multiline, textInputAction: TextInputAction.done, maxLines: null, - maxLength: widget.requestData.commentAllowed.toInt(), + maxLength: widget.data.commentAllowed.toInt(), maxLengthEnforcement: MaxLengthEnforcement.enforced, decoration: InputDecoration( labelText: texts.lnurl_payment_page_comment, @@ -125,8 +125,8 @@ class LNURLPaymentPageState extends State { ), child: Text( texts.lnurl_fetch_invoice_limit( - currencyState.bitcoinCurrency.format((widget.requestData.minSendable ~/ 1000)), - currencyState.bitcoinCurrency.format((widget.requestData.maxSendable ~/ 1000)), + currencyState.bitcoinCurrency.format((widget.data.minSendable ~/ 1000)), + currencyState.bitcoinCurrency.format((widget.data.maxSendable ~/ 1000)), ), textAlign: TextAlign.left, style: theme.FieldTextStyle.labelStyle, @@ -194,8 +194,8 @@ class LNURLPaymentPageState extends State { final amount = currencyBloc.state.bitcoinCurrency.parse(_amountController.text); final comment = _commentController.text; _log.info("LNURL payment of $amount sats where " - "min is ${widget.requestData.minSendable} msats " - "and max is ${widget.requestData.maxSendable} msats." + "min is ${widget.data.minSendable} msats " + "and max is ${widget.data.maxSendable} msats." "with comment $comment"); Navigator.pop(context, LNURLPaymentInfo(amount: amount, comment: comment)); } @@ -210,12 +210,12 @@ class LNURLPaymentPageState extends State { final lspState = context.read().state; final currencyState = context.read().state; - final maxSendable = widget.requestData.maxSendable ~/ 1000; + final maxSendable = widget.data.maxSendable ~/ 1000; if (amount > maxSendable) { return texts.lnurl_payment_page_error_exceeds_limit(maxSendable); } - final minSendable = widget.requestData.minSendable ~/ 1000; + final minSendable = widget.data.minSendable ~/ 1000; if (amount < minSendable) { return texts.lnurl_payment_page_error_below_limit(minSendable); } diff --git a/lib/routes/lnurl/withdraw/lnurl_withdraw_dialog.dart b/lib/routes/lnurl/withdraw/lnurl_withdraw_dialog.dart index dc37cb796..6b107a345 100644 --- a/lib/routes/lnurl/withdraw/lnurl_withdraw_dialog.dart +++ b/lib/routes/lnurl/withdraw/lnurl_withdraw_dialog.dart @@ -143,11 +143,12 @@ class _LNURLWithdrawDialogState extends State with SingleTi _log.info("LNURL withdraw of ${widget.amountSats} sats where " "min is ${widget.requestData.minWithdrawable} msats " "and max is ${widget.requestData.maxWithdrawable} msats."); - final resp = await accountBloc.lnurlWithdraw( - reqData: widget.requestData, - amountSats: widget.amountSats, + final req = sdk.LnUrlWithdrawRequest( + amountMsat: widget.amountSats * 1000, + data: widget.requestData, description: description, ); + final resp = await accountBloc.lnurlWithdraw(req: req); if (resp is sdk.LnUrlWithdrawResult_Ok) { final paymentHash = resp.data.invoice.paymentHash; _log.info("LNURL withdraw success for $paymentHash"); diff --git a/lib/routes/spontaneous_payment/spontaneous_payment_page.dart b/lib/routes/spontaneous_payment/spontaneous_payment_page.dart index e72ab4392..43a34522b 100644 --- a/lib/routes/spontaneous_payment/spontaneous_payment_page.dart +++ b/lib/routes/spontaneous_payment/spontaneous_payment_page.dart @@ -212,9 +212,9 @@ class SpontaneousPaymentPageState extends State { const Duration(seconds: 1), () { sendFuture = accBloc.sendSpontaneousPayment( - widget.nodeID!, - tipMessage, - amount, + nodeId: widget.nodeID!, + description: tipMessage, + amountMsat: amount * 1000, ); return sendFuture; },