Skip to content

Commit

Permalink
Merge pull request #49 from LtbLightning/descriptor-type-mismatch
Browse files Browse the repository at this point in the history
Descriptor type mismatch
  • Loading branch information
BitcoinZavior authored Jan 31, 2023
2 parents c1452b8 + 7911c80 commit 89d124c
Show file tree
Hide file tree
Showing 13 changed files with 1,140 additions and 641 deletions.
86 changes: 44 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,98 +1,100 @@
### Bdk Flutter
A Flutter library for the [Bitcoin Development Kit](https://bitcoindevkit.org/).

A Flutter library for the [Bitcoin Development Kit](https://bitcoindevkit.org/).
The bdk library aims to be the core building block for Bitcoin Applications of any kind.

### Requirements
- Flutter : 3.0 or higher

- Flutter : 3.0 or higher
- Android minSdkVersion. : API 23 or higher.
- Deployment target : iOS 12.0 or greater.

### How to Use

To use the `bdk_flutter` package in your project, add it as a dependency in your project's pubspec.yaml:

```dart
dependencies:
bdk_flutter: ^0.3.0
```

`bdk-flutter` can then be imported and used in your Flutter code. For example:

```dart
import 'package:bdk_flutter/bdk_flutter.dart';
// ....
final mnemonic = await Mnemonic.create(WordCount.Words12);
final mnemonic = await Mnemonic.create(WordCount.Words12);
final descriptorSecretKey = await DescriptorSecretKey.create( network: Network.Testnet,
mnemonic: mnemonic );
final externalDescriptor = await Descriptor.newBip44( descriptorSecretKey: descriptorSecretKey,
network: Network.Testnet,
keyChainKind: KeyChainKind.External );
final internalDescriptor = await Descriptor.newBip44( descriptorSecretKey: descriptorSecretKey,
network: Network.Testnet,
keyChainKind: KeyChainKind.Internal );
final blockchain = await Blockchain.create( config: BlockchainConfig.electrum(
final externalDescriptor = await Descriptor.newBip44( descriptorSecretKey: descriptorSecretKey,
network: Network.Testnet,
keychain: KeyChainKind.External );
final internalDescriptor = await Descriptor.newBip44( descriptorSecretKey: descriptorSecretKey,
network: Network.Testnet,
keychain: KeyChainKind.Internal );
final blockchain = await Blockchain.create( config: BlockchainConfig.electrum(
config: ElectrumConfig(
stopGap: 10,
timeout: 5,
retry: 5,
url: "ssl://electrum.blockstream.info:60002")));
final wallet = await Wallet.create( descriptor: externalDescriptor,
changeDescriptor: internalDescriptor,
network: Network.TESTNET,
databaseConfig: const DatabaseConfig.memory());
final addressInfo = await wallet.getAddress( addressIndex: AddressIndex.New );
await wallet.sync( blockchain );
url: "ssl://electrum.blockstream.info:60002" )));
final wallet = await Wallet.create( descriptor: externalDescriptor,
changeDescriptor: internalDescriptor,
network: Network.TESTNET,
databaseConfig: const DatabaseConfig.memory() );
final addressInfo = await wallet.getAddress( addressIndex: AddressIndex.New );
await wallet.sync( blockchain );
```

### API Documentation

The latest API documentation is available [here](https://pub.dev/documentation/bdk_flutter/latest/bdk_flutter/bdk_flutter-library.html)

### Example Projects
- ***BDK Flutter Demo App:** The [BDK Flutter Demo App](https://github.com/LtbLightning/bdk-flutter-app)
is a simple bitcoin app built in flutter to serve as a reference app to demonstrate `bdk-flutter` api usage.

### How to build

_Note that Flutter version `3.0` or later is required to build the plugin._

1. Install `Rust` and `Cargo`
The easiest way to get Cargo is to install the current stable release of Rust by using [rustup](https://doc.rust-lang.org/cargo/getting-started/installation.html). Installing Rust using rustup will also install cargo.
1. Install `Rust` and `Cargo`
The easiest way to get Cargo is to install the current stable release of Rust by using [rustup](https://doc.rust-lang.org/cargo/getting-started/installation.html). Installing Rust using rustup will also install cargo.

2. Clone this repository
```shell
git clone https://github.com/LtbLightning/bdk-flutter.git
```

3. Activate dart `ffigen`
```shell
dart pub global activate ffigen
```

4. Android Setup
- The [Android NDK](https://developer.android.com/ndk), or Native Development Kit, enables code written in other languages to be run on the JVM via the Java Native Interface, or JNI for short.
After following the instructions above, the NDK should be installed in your $ANDROID_SDK_HOME/ndk folder, where ANDROID_SDK_HOME usually is:
<br/> Windows: %APPDATA%\Local\Android\sdk
<br/> MacOS: ~/Library/Android/sdk
```shell
dart pub global activate ffigen
```

4. Android Setup

- The [Android NDK](https://developer.android.com/ndk), or Native Development Kit, enables code written in other languages to be run on the JVM via the Java Native Interface, or JNI for short.
After following the instructions above, the NDK should be installed in your $ANDROID_SDK_HOME/ndk folder, where ANDROID_SDK_HOME usually is:
<br/> Windows: %APPDATA%\Local\Android\sdk
<br/> MacOS: ~/Library/Android/sdk

An [issue](https://github.com/rust-lang/rust/pull/85806) regarding building Rust's core library against the latest NDK means that as of writing only NDK versions 22 and older can be used.
You can alternatively use the latest version of the Android NDK which is greater than 22. However, this requires a hack to prevent the [`unable to find library -lgcc error`](https://github.com/rust-lang/rust/pull/85806#issuecomment-1096266946).
5. Build flutter bindings
Navigate to `rust` directory, and run the following commands
```shell
cargo build
make all
```
Navigate to `rust` directory, and run the following commands
```shell
cargo build
make all
```
### _Generating Docs Manually (Optional)_
### _Generating Docs Manually (Optional)_
Please use the [Dart documentation generator](https://pub.dev/packages/dartdoc) to generate the API documentation.
Please use the [Dart documentation generator](https://pub.dev/packages/dartdoc) to generate the API documentation.
_Note: Caution this is pre-Alpha at this stage
Please consider reviewing, experimenting, and contributing ⚡️_
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- bdk_flutter (0.2.3):
- bdk_flutter (0.3.0):
- Flutter
- Flutter (1.0.0)

Expand All @@ -14,7 +14,7 @@ EXTERNAL SOURCES:
:path: Flutter

SPEC CHECKSUMS:
bdk_flutter: e78411cd1fb06a522180fac6276ebc1989ba480a
bdk_flutter: e07886d29c53a9c7deba3bec3b20418ce5bd9787
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854

PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3
Expand Down
7 changes: 3 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class _MyAppState extends State<MyApp> {
mnemonic: mnemonic,
);
final descriptor = await Descriptor.newBip44(
descriptorSecretKey: descriptorSecretKey,
secretKey: descriptorSecretKey,
network: Network.Testnet,
keyChainKind: KeychainKind.External);
keychain: KeychainKind.External);

setState(() {
aliceDescriptor = descriptor;
Expand Down Expand Up @@ -90,8 +90,7 @@ class _MyAppState extends State<MyApp> {
}

getNewAddress() async {
final alice =
await aliceWallet.getAddress(addressIndex: AddressIndex.New);
final alice = await aliceWallet.getAddress(addressIndex: AddressIndex.New);
if (kDebugMode) {
print(alice.address);
print(alice.index);
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.3.0"
version: "0.3.1"
boolean_selector:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion ios/bdk_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'bdk_flutter'
s.version = '0.3.0'
s.version = '0.3.1'
s.summary = 'A Flutter library for the Bitcoin Development Kit (https://bitcoindevkit.org/)'
s.description = <<-DESC
A new Flutter project.
Expand Down
Loading

0 comments on commit 89d124c

Please sign in to comment.