fix dependency conflicts + start breez integration

This commit is contained in:
fosse 2024-02-06 13:53:38 -05:00
parent 8632842b6d
commit ee2d440465
10 changed files with 101 additions and 26 deletions

View file

@ -1,3 +1,5 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
import 'package:cw_bitcoin/bitcoin_mnemonic.dart'; import 'package:cw_bitcoin/bitcoin_mnemonic.dart';
import 'package:cw_core/crypto_currency.dart'; import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/unspent_coins_info.dart'; import 'package:cw_core/unspent_coins_info.dart';
@ -37,31 +39,51 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
initialBalance: initialBalance, initialBalance: initialBalance,
seedBytes: seedBytes, seedBytes: seedBytes,
currency: CryptoCurrency.btc) { currency: CryptoCurrency.btc) {
walletAddresses = BitcoinWalletAddresses( walletAddresses = BitcoinWalletAddresses(walletInfo,
walletInfo,
electrumClient: electrumClient, electrumClient: electrumClient,
initialAddresses: initialAddresses, initialAddresses: initialAddresses,
initialRegularAddressIndex: initialRegularAddressIndex, initialRegularAddressIndex: initialRegularAddressIndex,
initialChangeAddressIndex: initialChangeAddressIndex, initialChangeAddressIndex: initialChangeAddressIndex,
mainHd: hd, mainHd: hd,
sideHd: bitcoin.HDWallet.fromSeed(seedBytes, network: networkType) sideHd: bitcoin.HDWallet.fromSeed(seedBytes, network: networkType).derivePath("m/0'/1"),
.derivePath("m/0'/1"),
networkType: networkType); networkType: networkType);
// initialize breeze:
String inviteCode = "<invite code>";
String apiKey = "<api key>";
NodeConfig breezNodeConfig = NodeConfig.greenlight(
config: GreenlightNodeConfig(
partnerCredentials: null,
inviteCode: inviteCode,
),
);
BreezSDK()
.defaultConfig(
envType: EnvironmentType.Production,
apiKey: apiKey,
nodeConfig: breezNodeConfig,
)
.then((value) {
Config breezConfig = value;
// Customize the config object according to your needs
breezConfig = breezConfig.copyWith(workingDir: "/breez/${walletInfo.name}");
BreezSDK().connect(config: breezConfig, seed: seedBytes);
});
autorun((_) { autorun((_) {
this.walletAddresses.isEnabledAutoGenerateSubaddress = this.isEnabledAutoGenerateSubaddress; this.walletAddresses.isEnabledAutoGenerateSubaddress = this.isEnabledAutoGenerateSubaddress;
}); });
} }
static Future<BitcoinWallet> create({ static Future<BitcoinWallet> create(
required String mnemonic, {required String mnemonic,
required String password, required String password,
required WalletInfo walletInfo, required WalletInfo walletInfo,
required Box<UnspentCoinsInfo> unspentCoinsInfo, required Box<UnspentCoinsInfo> unspentCoinsInfo,
List<BitcoinAddressRecord>? initialAddresses, List<BitcoinAddressRecord>? initialAddresses,
ElectrumBalance? initialBalance, ElectrumBalance? initialBalance,
int initialRegularAddressIndex = 0, int initialRegularAddressIndex = 0,
int initialChangeAddressIndex = 0 int initialChangeAddressIndex = 0}) async {
}) async {
return BitcoinWallet( return BitcoinWallet(
mnemonic: mnemonic, mnemonic: mnemonic,
password: password, password: password,

View file

@ -11,6 +11,7 @@ import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_type.dart'; import 'package:cw_core/wallet_type.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:breez_sdk/breez_sdk.dart';
class BitcoinWalletService extends WalletService< class BitcoinWalletService extends WalletService<
BitcoinNewWalletCredentials, BitcoinNewWalletCredentials,
@ -44,6 +45,10 @@ class BitcoinWalletService extends WalletService<
Future<BitcoinWallet> openWallet(String name, String password) async { Future<BitcoinWallet> openWallet(String name, String password) async {
final walletInfo = walletInfoSource.values.firstWhereOrNull( final walletInfo = walletInfoSource.values.firstWhereOrNull(
(info) => info.id == WalletBase.idFor(name, getType()))!; (info) => info.id == WalletBase.idFor(name, getType()))!;
// Initialize SDK logs listener
BreezSDK().initialize();
final wallet = await BitcoinWalletBase.open( final wallet = await BitcoinWalletBase.open(
password: password, name: name, walletInfo: walletInfo, password: password, name: name, walletInfo: walletInfo,
unspentCoinsInfo: unspentCoinsInfoSource); unspentCoinsInfo: unspentCoinsInfoSource);

View file

@ -27,6 +27,9 @@ dependencies:
git: git:
url: https://github.com/cake-tech/bitbox-flutter.git url: https://github.com/cake-tech/bitbox-flutter.git
ref: master ref: master
breez_sdk:
git:
url: https://github.com/breez/breez-sdk-flutter.git
rxdart: ^0.27.5 rxdart: ^0.27.5
unorm_dart: ^0.2.0 unorm_dart: ^0.2.0
cryptography: ^2.0.5 cryptography: ^2.0.5
@ -37,7 +40,7 @@ dev_dependencies:
build_runner: ^2.1.11 build_runner: ^2.1.11
build_resolvers: ^2.0.9 build_resolvers: ^2.0.9
mobx_codegen: ^2.0.7 mobx_codegen: ^2.0.7
hive_generator: ^1.1.3 hive_generator: ^2.0.1
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec

View file

@ -38,7 +38,7 @@ dev_dependencies:
sdk: flutter sdk: flutter
build_runner: ^2.1.11 build_runner: ^2.1.11
mobx_codegen: ^2.0.7 mobx_codegen: ^2.0.7
hive_generator: ^1.1.3 hive_generator: ^2.0.1
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec

View file

@ -29,7 +29,7 @@ dev_dependencies:
sdk: flutter sdk: flutter
build_runner: ^2.1.11 build_runner: ^2.1.11
mobx_codegen: ^2.0.7 mobx_codegen: ^2.0.7
hive_generator: ^1.1.3 hive_generator: ^2.0.1
flutter_lints: ^2.0.0 flutter_lints: ^2.0.0
flutter: flutter:

View file

@ -27,7 +27,7 @@ dev_dependencies:
build_runner: ^2.1.11 build_runner: ^2.1.11
mobx_codegen: ^2.0.7 mobx_codegen: ^2.0.7
build_resolvers: ^2.0.9 build_resolvers: ^2.0.9
hive_generator: ^1.1.3 hive_generator: ^2.0.1
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec

View file

@ -29,7 +29,7 @@ dev_dependencies:
build_runner: ^2.1.11 build_runner: ^2.1.11
build_resolvers: ^2.0.9 build_resolvers: ^2.0.9
mobx_codegen: ^2.0.7 mobx_codegen: ^2.0.7
hive_generator: ^1.1.3 hive_generator: ^2.0.1
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec

View file

@ -34,7 +34,7 @@ dev_dependencies:
sdk: flutter sdk: flutter
build_runner: ^2.1.11 build_runner: ^2.1.11
mobx_codegen: ^2.0.7 mobx_codegen: ^2.0.7
hive_generator: ^1.1.3 hive_generator: ^2.0.1
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec

View file

@ -41,6 +41,8 @@ import 'package:uni_links/uni_links.dart';
import 'package:cw_core/unspent_coins_info.dart'; import 'package:cw_core/unspent_coins_info.dart';
import 'package:cake_wallet/monero/monero.dart'; import 'package:cake_wallet/monero/monero.dart';
import 'package:cw_core/cake_hive.dart'; import 'package:cw_core/cake_hive.dart';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
final navigatorKey = GlobalKey<NavigatorState>(); final navigatorKey = GlobalKey<NavigatorState>();
final rootKey = GlobalKey<RootState>(); final rootKey = GlobalKey<RootState>();
@ -64,6 +66,11 @@ Future<void> main() async {
await initializeAppConfigs(); await initializeAppConfigs();
// breez:
// BreezDateUtils.setupLocales();
// BreezLogger();
runApp(App()); runApp(App());
}, (error, stackTrace) async { }, (error, stackTrace) async {
ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stackTrace)); ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stackTrace));

View file

@ -1,3 +1,5 @@
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
import 'package:cake_wallet/src/screens/new_wallet/widgets/select_button.dart'; import 'package:cake_wallet/src/screens/new_wallet/widgets/select_button.dart';
import 'package:cake_wallet/themes/extensions/keyboard_theme.dart'; import 'package:cake_wallet/themes/extensions/keyboard_theme.dart';
import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/di.dart';
@ -158,6 +160,43 @@ class AddressPage extends BasePage {
isLight: dashboardViewModel.settingsStore.currentTheme.type == isLight: dashboardViewModel.settingsStore.currentTheme.type ==
ThemeType.light))), ThemeType.light))),
SizedBox(height: 16), SizedBox(height: 16),
IconButton(
padding: EdgeInsets.zero,
constraints: BoxConstraints(),
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
iconSize: 25,
onPressed: () async {
// ReceivePaymentRequest req = const ReceivePaymentRequest(
// amountMsat: 3000000,
// description: "Invoice for 3000 sats",
// );
// ReceivePaymentResponse receivePaymentResponse =
// await BreezSDK().receivePayment(req: req);
// print(receivePaymentResponse.lnInvoice);
ServiceHealthCheckResponse healthCheck = await BreezSDK().serviceHealthCheck();
print("Current service status is: ${healthCheck.status}");
ReceiveOnchainRequest req = const ReceiveOnchainRequest();
SwapInfo swapInfo = await BreezSDK().receiveOnchain(req: req);
// Send your funds to the below bitcoin address
String address = swapInfo.bitcoinAddress;
print(address);
print("Minimum amount allowed to deposit in sats: ${swapInfo.minAllowedDeposit}");
print("Maximum amount allowed to deposit in sats: ${swapInfo.maxAllowedDeposit}");
},
icon: Icon(
Icons.lightbulb_outline_rounded,
size: 48,
color: pageIconColor(context),
),
),
SizedBox(
height: 40,
),
Observer(builder: (_) { Observer(builder: (_) {
if (addressListViewModel.hasAddressList) { if (addressListViewModel.hasAddressList) {
return SelectButton( return SelectButton(
@ -166,8 +205,7 @@ class AddressPage extends BasePage {
(WalletType.monero == addressListViewModel.wallet.type || (WalletType.monero == addressListViewModel.wallet.type ||
WalletType.haven == addressListViewModel.wallet.type) WalletType.haven == addressListViewModel.wallet.type)
? await showPopUp<void>( ? await showPopUp<void>(
context: context, context: context, builder: (_) => getIt.get<MoneroAccountListPage>())
builder: (_) => getIt.get<MoneroAccountListPage>())
: Navigator.of(context).pushNamed(Routes.receive), : Navigator.of(context).pushNamed(Routes.receive),
textColor: Theme.of(context).extension<SyncIndicatorTheme>()!.textColor, textColor: Theme.of(context).extension<SyncIndicatorTheme>()!.textColor,
color: Theme.of(context).extension<SyncIndicatorTheme>()!.syncedBackgroundColor, color: Theme.of(context).extension<SyncIndicatorTheme>()!.syncedBackgroundColor,