SatoshiPortal / boltz-dart

Dart boltz client
MIT License
6 stars 6 forks source link

boltz-dart

The top level directory of this project is a dart/flutter pub library.

The rust folder containers the core code which uses the boltz-rust crate internally to expose an abstracted API to manage boltz swaps.

Usage

Init the library in your apps main()

Eg:


Future main({bool fromTest = false}) async {
  if (!fromTest) WidgetsFlutterBinding.ensureInitialized();

  await dotenv.load(isOptional: true);
  Bloc.observer = BBlocObserver();
  // await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);

  await setupLocator(fromTest: fromTest);
  final delegate = await Localise.getDelegate();
  LwkCore.init();
  BoltzCore.init();
  runApp(
    LocalizedApp(
      delegate,
      const BullBitcoinWalletApp(),
    ),
  );
}

Dependencies

Currently we do not use precompiled binaries with cargokit. So as the end user, you will require cargo and platform specific toolchains to compile the binaries locally.

# install rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# install tools
cargo install flutter_rust_bridge_codegen
cargo install cargo-ndk
cargo install cargo-lipo

For ios builds, make sure you have xcode and cocoapods installed.

Update & Build process

Add new types to types.rs and static functions to api.rs

api.rs contains an Api struct that holds all the static functions.

types.rs structures and enums are also re-exported via api.rs

# in the project root directory

./compile.native.sh # build for your native platform (linux/macos). adds binary to dart test folder.

MacOS as host

macos as the host machine can build binaries for all platforms using:

# requires dockerd running
./compile.all.sh

Compile will first build native binaries of the rust code and move them to the dart test folder.

It will then run flutter_rust_bridge_codegen and generate ffi code in rust and dart.

Non-debian linux users

On non-debian systems you will get some errors with the bridge_generated.dart files.

Error would be related to:

  void store_dart_post_cobject(
    int ptr,
  ) {
    return _store_dart_post_cobject(
      ptr,
    );
  }

You may need to set the path the clang in CPATH manually. Run the following:

export CPATH="$(clang -v 2>&1 | grep "Selected GCC installation" | rev | cut -d' ' -f1 | rev)/include"

dart classes

Once we have all our structs and functions in dart, we can organize them into classes to improve the UX of the library.

test

You can now use the test/boltz-test.dart file to test whether the expected logic is being exposed correctly over ffi.

Also try flutter run in the example directory.

Resources: