Skip to content

Commit

Permalink
Merge pull request #126 from LtbLightning/v31-upgrade
Browse files Browse the repository at this point in the history
V31 upgrade
  • Loading branch information
BitcoinZavior authored Mar 28, 2024
2 parents 0746f77 + 6453058 commit 9ca16d9
Show file tree
Hide file tree
Showing 126 changed files with 70,075 additions and 36,724 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/precompile_binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
on:
push:
branches: [v0.31.0-dev, master, main]

name: Precompile Binaries

jobs:
Precompile:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
- macOS-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Configure Cargo.toml optimizations
run: |
mkdir -p .cargo
echo "[profile.release]" >> .cargo/config.toml
echo "opt-level = 'z'" >> .cargo/config.toml
echo "lto = true" >> .cargo/config.toml
echo "codegen-units = 1" >> .cargo/config.toml
echo "panic = 'abort'" >> .cargo/config.toml
- uses: dart-lang/setup-dart@v1
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
- name: Precompile (with iOS)
if: (matrix.os == 'macOS-latest')
run: dart run build_tool precompile-binaries -v --manifest-dir=../../rust --repository=LtbLightning/bdk-flutter
working-directory: cargokit/build_tool
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
PRIVATE_KEY: ${{ secrets.CARGOKIT_PRIVATE_KEY }}
- name: Precompile (with Android)
if: (matrix.os == 'ubuntu-20.04')
run: dart run build_tool precompile-binaries -v --manifest-dir=../../rust --repository=LtbLightning/bdk-flutter --android-sdk-location=/usr/local/lib/android/sdk --android-ndk-version=24.0.8215888 --android-min-sdk-version=23
working-directory: cargokit/build_tool
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
PRIVATE_KEY: ${{ secrets.CARGOKIT_PRIVATE_KEY }}
45 changes: 18 additions & 27 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
## [0.30.0]
## [0.31.0-dev]
Updated Rust and Flutter dependencies.
macOs support bug resolved
#### APIs added
- Add sealed class `Auth` in `RpcConfig`.
- Made `PartiallySignedTransaction` class mutable.

#### Changed
- Replace `AddressIndex`'s `new` with`increase`.
- Renamed `Address`'s create to `fromString`.
- `txBuilder.finish` returns a tuple.
- Added `cargokit` to handle rust binary build

#### Fixed
- Functions hang indefinitely on iOS devices.
- Thread `frb_workerpool` panicked.

## [0.30.0]
Updated Rust and Flutter dependencies.
MacOS support bug resolved
#### APIs added
- Add BIP-86 descriptor template


## [0.29.2]
Support macOs and unit testing.

Support MacOS and unit testing.
Updated flutter dependencies.

## [0.29.1]
Updated Rust and Flutter dependencies.

Exposed strongly-typed exceptions.

## [0.29.0]
Support Dart 3.

Updated Rust and Flutter dependencies.
#### APIs added
- Add `isMine` method to `Wallet`.
Expand All @@ -41,7 +52,6 @@ Updated Rust and Flutter dependencies.

## [0.28.0]
Updated Rust ( Bdk to latest version 0.28.0 ) and Flutter dependencies.

#### APIs added
- Expose `Address` class's `payload` and `network` functions
- Add `fromScript` constructor to `Address` class
Expand All @@ -55,13 +65,11 @@ Updated Rust ( Bdk to latest version 0.28.0 ) and Flutter dependencies.

## [0.27.1]
Updated Rust ( Bdk to latest version 0.27.1 ) and Flutter dependencies.

#### APIs added
- New `Transaction` class that can be created from or serialized to consensus encoded bytes.
- Add estimateFee(int Target) function for `Blockchain`
- Add getInternalAddress() function for `Wallet`
- Add AddressIndex.reset(int index) & AddressIndex.peek(int index)

#### APIs changed
- partiallySignedTransaction.extractTx() returns a `Transaction` instead of a the transaction bytes.
- blockchain.broadcast() takes a `Transaction` instead of a `PartiallySignedTransaction`
Expand All @@ -78,13 +86,9 @@ Updated Rust ( Bdk to latest version 0.27.1 ) and Flutter dependencies.

## [0.3.0]
Updated Rust ( Bdk to latest version 0.26.0 ) and Flutter dependencies.

#### APIs changed

- The descriptor and changeDescriptor arguments on the wallet constructor now take a `Descriptor` instead of a String.

#### APIs added

- Added RpcConfig, BlockchainConfig.rpc
- Added Descriptor type with the following named constructors:
- Default `create` constructor, that requires a descriptor in String format and a Network
Expand All @@ -97,37 +101,24 @@ Updated Rust ( Bdk to latest version 0.26.0 ) and Flutter dependencies.
- asString returns the public version of the output descriptor in String format
- asPrivateString returns the private version of the output descriptor if available, otherwise, return the public version

### Fixed

- Dependencies Upgraded

## [0.2.3]

### Fixed

- pub.dev analysis score

## [0.2.2]

### Fixed

- pub.dev analysis score

## [0.2.1]

### Fixed

- pub.dev static analysis warning
- removing internal helper functions from public api

## [0.2.0]

Updated API to match bdk-ffi

## [0.1.4]

#### Functionality Added

- Generate Mnemonic method
- Create Descriptors
- Create Extended Key
Expand Down
105 changes: 32 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ To use the `bdk_flutter` package in your project, add it as a dependency in your

```dart
dependencies:
bdk_flutter: ^0.30.0
bdk_flutter: ^0.31.0-dev
```

### Examples
Expand All @@ -51,15 +51,15 @@ import 'package:bdk_flutter/bdk_flutter.dart';
// ....
final mnemonic = await Mnemonic.create(WordCount.Words12);
final descriptorSecretKey = await DescriptorSecretKey.create( network: Network.Testnet,
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,
keychain: KeyChainKind.External );
final internalDescriptor = await Descriptor.newBip44( descriptorSecretKey: descriptorSecretKey,
network: Network.Testnet,
keychain: KeyChainKind.Internal );
final externalDescriptor = await Descriptor.newBip44( secretKey: descriptorSecretKey,
network: Network.testnet,
keychain: KeychainKind.externalChain );
final internalDescriptor = await Descriptor.newBip44( secretKey: descriptorSecretKey,
network: Network.testnet,
keychain: KeyChainKind.internalChain );
final blockchain = await Blockchain.create( config: BlockchainConfig.electrum(
config: ElectrumConfig(
stopGap: 10,
Expand All @@ -68,7 +68,7 @@ final blockchain = await Blockchain.create( config: BlockchainConfig.electrum(
url: "ssl://electrum.blockstream.info:60002" )));
final wallet = await Wallet.create( descriptor: externalDescriptor,
changeDescriptor: internalDescriptor,
network: Network.TESTNET,
network: Network.testnet,
databaseConfig: const DatabaseConfig.memory() );
final _ = await wallet.sync( blockchain );
```
Expand All @@ -80,15 +80,15 @@ import 'package:bdk_flutter/bdk_flutter.dart';
// ....
final mnemonic = await Mnemonic.create(WordCount.Words12);
final descriptorSecretKey = await DescriptorSecretKey.create( network: Network.Testnet,
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,
keychain: KeyChainKind.External );
final externalDescriptor = await Descriptor.newBip44( secretKey: descriptorSecretKey,
network: Network.testnet,
keychain: KeychainKind.externalChain );
final externalPublicDescriptorStr = await externalDescriptor.asString();
final externalPublicDescriptor = await Descriptor.( descriptor: externalPublicDescriptorStr,
network: Network.Testnet);
network: Network.testnet);
```

### Get the transaction details
Expand All @@ -101,16 +101,16 @@ final bdkWallet = .....
// ....
final txBuilder = TxBuilder();
final address = await Address.create(address: "mv4rnyY3Su5gjcDNzbMLKBQkBicCtHUtFB");
final address = await Address.fromString(s: "mv4rnyY3Su5gjcDNzbMLKBQkBicCtHUtFB", network: Network.testnet);
final script = await address.scriptPubKey();
final feeRate = await estimateFeeRate(25);
final script = await address.scriptPubkey();
final feeRate = await blockchain.estimateFee(target: 25);
final txBuilderResult = await txBuilder.feeRate( feeRate.asSatPerVb() )
final (psbt, transactionDetails) = await txBuilder.feeRate( feeRate.satPerVb )
.addRecipient( script, 2000 )
.finish( bdkWallet );
final serializedPsbt = await txBuilderResult.psbt.jsonSerialize();
final serializedPsbt = await psbt.jsonSerialize();
final jsonObject = json.decode(serializedPsbt);
final outputs = jsonObject['unsigned_tx']['output'] as List;
final inputs = jsonObject['inputs'][0]['non_witness_utxo']['output'] as List;
Expand All @@ -135,17 +135,17 @@ debugPrint("=========Outputs=====");
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);
network: Network.testnet, mnemonic: mnemonic);
// create external descriptor
final derivationPath = await DerivationPath.create(path: "m/44h/1h/0h/0");
final descriptorPrivateKey =
await descriptorSecretKey.derive(derivationPath);
final Descriptor descriptorPrivate = await Descriptor.create(
descriptor: "pkh(${descriptorPrivateKey.toString()})",
network: Network.Testnet,
network: Network.testnet,
);
// create internal descriptor
Expand All @@ -155,79 +155,38 @@ final descriptorPrivateKeyInt =
await descriptorSecretKey.derive(derivationPathInt);
final Descriptor descriptorPrivateInt = await Descriptor.create(
descriptor: "pkh(${descriptorPrivateKeyInt.toString()})",
network: Network.Testnet,
network: Network.testnet,
);
final bdkWallet = await Wallet.create(
descriptor: descriptorPrivate,
changeDescriptor: descriptorPrivateInt,
network: Network.Testnet,
network: Network.testnet,
databaseConfig: const DatabaseConfig.memory(),
);
final address =
await bdkWallet.getAddress(addressIndex: const AddressIndex());
await bdkWallet.getAddress(addressIndex: const AddressIndex.increase());
final internalAddress =
await bdkWallet.getInternalAddress(addressIndex: const AddressIndex());
await bdkWallet.getInternalAddress(addressIndex: const AddressIndex.increase());
```

### API Documentation

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

### Example Projects
### Example Projects

- **\*BDK Flutter Demo App:** The [BDK Flutter Demo App](https://github.com/LtbLightning/bdk-flutter-demo-app)
- **\*BDK Flutter Demo App:** The [BDK Flutter Demo App](https://github.com/LtbLightning/bdk-flutter-quickstart)
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.

2. Clone this repository

```shell
git clone https://github.com/LtbLightning/bdk-flutter
```

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

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
```

### _Generating Docs Manually (Optional)_

Please use the [Dart documentation generator](https://pub.dev/packages/dartdoc) to generate the API documentation.

### References:

- Setting up a local Esplora instance for testing:
https://bitcoin.stackexchange.com/questions/116937/how-do-i-setup-an-esplora-instance-for-local-testing/116938#116938

_Note: Caution this is Beta at this stage
Please consider reviewing, experimenting, and contributing ⚡️_
_Note: This Flutter plugin is currently in its development (dev) stage and has been released for community review and experimentation.
We warmly welcome feedback, bug reports, and contributions from developers and enthusiasts alike ⚡️_

Thanks for taking a look!
16 changes: 13 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ linter:

analyzer:
exclude:
- lib/src/generated/bindings.dart
- lib/src/generated/bridge_definitions.dart
- lib/src/generated/bridge_definitions.freezed.dart
- lib/src/generated/frb_generated.dart
- lib/src/generated/frb_generated.io.dart
- lib/src/generated/frb_generated.dart
- lib/src/generated/api/types.freezed.dart
- lib/src/generated/api/types.dart
- lib/src/generated/api/descriptor.dart
- lib/src/generated/api/error.freezed.dart
- lib/src/generated/api/error.dart
- lib/src/generated/api/key.dart
- lib/src/generated/api/psbt.dart
- lib/src/generated/api/wallet.dart
- lib/src/generated/api/blockchain.freezed.dart
- README.md
- cargokit/
Loading

0 comments on commit 9ca16d9

Please sign in to comment.