Coder Social home page Coder Social logo

satoshiportal / boltz-dart Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 2.0 17.93 MB

Dart boltz client

License: Other

Just 0.06% Dart 59.73% Rust 28.62% Dockerfile 0.19% Shell 0.76% Makefile 0.22% Kotlin 0.02% Swift 0.26% Objective-C 0.01% C 8.87% CMake 0.25% Ruby 1.02%

boltz-dart's Introduction

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

Docker is required for linux builds.

cargo install flutter_rust_bridge_codegen
cargo install cargo-expand
cargo install cargo-ndk
@if [ $$(uname) == "Darwin" ] ; then cargo install cargo-lipo ; fi

For ios builds, make sure you have xcode 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.

NOTE

The reverse swap test can be run without any updates to local variables.

The submarine swap test requires using a new invoice for every test. You can generate test invoices here:

https://starblocks.acinq.co

Order half a ton of coffee, since minimum swap output is 50,000 sats

These invoices will work for ruidentary tests, but the entire swap flow will not complete as boltz does not have a route to pay this channel since we last checked.

When we reach testing the complete flow we will have to use our own local node and ensure we are directly connected to boltz's testnet node.

For Invoices < 1m sats: (recommended for testing)

https://1ml.com/testnet/node/029040945df331e634fba152ce6a21e3dfca87b68d275e078caeee4753f43e9acb

Invoices > 1m sats:

https://1ml.com/testnet/node/03f060953bef5b777dc77e44afa3859d022fc1a77c55138deb232ad7255e869c00

project status

This project is in extreme alpha and undergoing active development. Any support will be greatly appreciated.

Each swap flow is abstracted into a class with similar methods:

Constructors:

  • newSubmarine
  • newReverse

Info:

  • paymentDetails
  • status

Transaction(Sweep):

  • claim
  • refund

The main classes and their methods are:

  • BtcLnV1Swap
    • newSubmarine
    • newReverse
    • claim
    • refund
  • LbtcLnV1Swap
    • newSubmarine
    • newReverse
    • claim
    • refund
  • BtcLbtcSwap
  • BoltzApi

Dependencies

To stay in sync with boltz-rust following updates, use:

cargo update

Resources:

boltz-dart's People

Contributors

i5hi avatar mocodesmo avatar psyberfly avatar saiy2k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

psyberfly 22388o

boltz-dart's Issues

Cannot open example app on iOS. iOS support broken / not clear

Running pod install...
CocoaPods' output:
↳
      Preparing

    Analyzing dependencies

    Inspecting targets to integrate
      Using `ARCHS` setting to build architectures of target `Pods-Runner`: (``)
      Using `ARCHS` setting to build architectures of target `Pods-RunnerTests`: (``)

    Finding Podfile changes
      - Flutter
      - boltz_dart

    Fetching external sources
    -> Fetching podspec for `Flutter` from `Flutter`
    -> Fetching podspec for `boltz_dart` from `.symlinks/plugins/boltz_dart/ios`
    [!] The `boltz_dart` pod failed to validate due to 1 error:
        - ERROR | attributes: Missing required attribute `source`.
        - WARN  | license: Missing license type.
        - WARN  | description: The description is shorter than the summary.

Adding referral id parameter

As per boltz documentation there is an option to partner up with them for smaller developers to monetize their applications.

It would be a great addition to add referral id string param (optional) to the dart bindings

This would implicate from my investigation adding in boltz-rust somewhere here

pub struct CreateSwapRequest {
    pub from: String,
    pub to: String,
    pub invoice: String,
    pub refund_public_key: PublicKey,
    ***
    pub referral_id: String
}

and

pub struct CreateReverseReq {
    pub invoice_amount: u32,
    pub from: String,
    pub to: String,
    pub preimage_hash: sha256::Hash,
    pub claim_public_key: PublicKey,
   ***
    pub referral_id: String
}

and then this would be used in the post for

/swap/reverse
and
/swap/submarine

We then need to bring this up to the bolt-dart library as a param to for example

static Future<BtcLnBoltzSwap> newReverse(
     {required String mnemonic,
     required int index,
     required int outAmount,
     required bridge.Chain network,
     required String electrumUrl,
     required String boltzUrl,
     ******
     String? referralId
     ******
     required String pairHash, .....
```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.