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.
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(),
),
);
}
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 --version 2.0.0
cargo install cargo-ndk
cargo install cargo-lipo
For ios builds, make sure you have xcode and cocoapods installed.
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 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.
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"
Once we have all our structs and functions in dart, we can organize them into classes to improve the UX of the library.
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.