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

switch to use amountMsat for upcomming sdk release. #688

Merged
merged 1 commit into from
Oct 23, 2023
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
6 changes: 4 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/background/payment_hash_poller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Payment> paymentList = await breezLib.listPayments(request: request);
final List<Payment> paymentList = await breezLib.listPayments(req: req);
for (var payment in paymentList) {
final detailsData = payment.details.data;
final isPaymentReceived = payment.status == PaymentStatus.Complete &&
Expand Down
61 changes: 26 additions & 35 deletions lib/bloc/account/account_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,35 +131,19 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {
}

Future<sdk.LnUrlWithdrawResult> 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<sdk.LnUrlPayResult> lnurlPay({
required int amount,
required sdk.LnUrlPayRequestData reqData,
String? comment,
}) async {
_log.info("lnurlPay amount: $amount, comment: '$comment', reqData: $reqData");
Future<sdk.LnUrlPayResult> 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;
Expand All @@ -181,7 +165,11 @@ class AccountBloc extends Cubit<AccountState> 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);
Expand All @@ -193,18 +181,19 @@ class AccountBloc extends Cubit<AccountState> 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);
Expand Down Expand Up @@ -274,15 +263,17 @@ class AccountBloc extends Cubit<AccountState> with HydratedMixin {

Future<sdk.ReceivePaymentResponse> 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
Expand Down
3 changes: 2 additions & 1 deletion lib/bloc/account/credentials_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions lib/bloc/buy_bitcoin/moonpay/moonpay_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class MoonPayBloc extends Cubit<MoonPayState> {
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));
Expand Down
8 changes: 5 additions & 3 deletions lib/bloc/refund/refund_bloc.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -34,13 +35,14 @@ class RefundBloc extends Cubit<RefundState> {
}) 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;
Expand Down
4 changes: 3 additions & 1 deletion lib/bloc/reverse_swap/reverse_swap_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ class ReverseSwapBloc extends Cubit<ReverseSwapState> {
"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}",
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/swap_in_progress/swap_in_progress_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SwapInProgressBloc extends Cubit<SwapInProgressState> {
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));
Expand Down
7 changes: 5 additions & 2 deletions lib/bloc/sweep/sweep_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ class SweepBloc extends Cubit<SweepState> {
}) 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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/create_invoice/create_invoice_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class CreateInvoicePageState extends State<CreateInvoicePage> {

Future<ReceivePaymentResponse> 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(
Expand Down
6 changes: 3 additions & 3 deletions lib/routes/lnurl/auth/lnurl_auth_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ final _log = Logger("HandleLNURLAuthRequest");

Future<LNURLPageResult?> 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();
final navigator = Navigator.of(context);
final loaderRoute = createLoaderRoute(context);
navigator.push(loaderRoute);
try {
final resp = await context.read<AccountBloc>().lnurlAuth(reqData: requestData);
final resp = await context.read<AccountBloc>().lnurlAuth(reqData: reqData);
if (resp is LnUrlCallbackStatus_Ok) {
_log.info("LNURL auth success");
return const LNURLPageResult(protocol: LnUrlProtocol.Auth);
Expand Down
18 changes: 9 additions & 9 deletions lib/routes/lnurl/payment/lnurl_payment_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -40,7 +40,7 @@ class LNURLPaymentDialogState extends State<LNURLPaymentDialog> {
final texts = context.texts();
final currencyState = context.read<CurrencyBloc>().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;
Expand All @@ -53,7 +53,7 @@ class LNURLPaymentDialogState extends State<LNURLPaymentDialog> {

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,
),
Expand Down Expand Up @@ -84,9 +84,9 @@ class LNURLPaymentDialogState extends State<LNURLPaymentDialog> {
),
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,
),
Expand Down Expand Up @@ -146,10 +146,10 @@ class LNURLPaymentDialogState extends State<LNURLPaymentDialog> {
}),
),
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(
Expand Down
24 changes: 14 additions & 10 deletions lib/routes/lnurl/payment/lnurl_payment_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ final _log = Logger("HandleLNURLPayRequest");
Future<LNURLPageResult?> 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<LNURLPaymentInfo>(
useRootNavigator: false,
context: context,
barrierDismissible: false,
builder: (_) => LNURLPaymentDialog(requestData: requestData),
builder: (_) => LNURLPaymentDialog(data: data),
);
} else {
paymentInfo = await Navigator.of(context).push<LNURLPaymentInfo>(
FadeInRoute(
builder: (_) => LNURLPaymentPage(requestData: requestData),
builder: (_) => LNURLPaymentPage(data: data),
),
);
}
Expand All @@ -47,11 +47,15 @@ Future<LNURLPageResult?> handlePayRequest(
builder: (_) => ProcessingPaymentDialog(
isLnurlPayment: true,
firstPaymentItemKey: firstPaymentItemKey,
paymentFunc: () => context.read<AccountBloc>().lnurlPay(
amount: paymentInfo!.amount,
comment: paymentInfo.comment,
reqData: requestData,
),
paymentFunc: () {
final accBloc = context.read<AccountBloc>();
final req = LnUrlPayRequest(
amountMsat: paymentInfo!.amount * 1000,
comment: paymentInfo.comment,
data: data,
);
return accBloc.lnurlPay(req: req);
},
),
).then((result) {
if (result is LnUrlPayResult) {
Expand Down
Loading
Loading