Skip to content

Commit

Permalink
Merge pull request #75 from LtbLightning/upgrade-bdk-ffi-v0.28
Browse files Browse the repository at this point in the history
Upgrade to bdk v0.28
  • Loading branch information
BitcoinZavior authored May 16, 2023
2 parents 93dd086 + 95c4c1a commit a7d28a6
Show file tree
Hide file tree
Showing 41 changed files with 7,225 additions and 2,945 deletions.
32 changes: 32 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
printf "\e[33;1m%s\e[0m\n" 'Running flutter format'
dart format .
printf "\e[33;1m%s\e[0m\n" 'Running cargo fmt'
cd rust || exit
cargo fmt
cd ../
git add .
printf "\e[33;1m%s\e[0m\n" 'Finished formatting'

printf "\e[33;1m%s\e[0m\n" 'Running flutter analyze'
flutter analyze
if [ $? -ne 0 ] ; then
exit 1
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running flutter analyze'

printf "\e[33;1m%s\e[0m\n" 'Running flutter test'
flutter test ./test/bdk_flutter_test.dart
if [ $? -ne 0 ] ; then
printf "\e[31;1m%s\e[0m\n" 'Mock tests error'
exit 1
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running flutter test'

printf "\e[33;1m%s\e[0m\n" 'Running flutter publish --dry-run'
flutter pub publish --dry-run
if [ $? -ne 0 ] ; then
printf "\e[31;1m%s\e[0m\n" 'publish --dry-run error'
exit 1
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running flutter publish --dry-run'
18 changes: 9 additions & 9 deletions .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file should be version controlled.

version:
revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
channel: stable

project_type: plugin
Expand All @@ -13,17 +13,17 @@ project_type: plugin
migration:
platforms:
- platform: root
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
- platform: android
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
- platform: ios
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
- platform: macos
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf

# User provided section

Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
## [0.27.2]
## [0.28.0]
Updates for latest bdk-ffi version 0.28.0 and Flutter dependencies.

#### APIs added
- Expose `Address` class's `payload` and `network` functions
- Add `fromScript` constructor to `Address` class
- Add `SignOptions` to Wallet.sign() params.
- Add `jsonSerialize` function to `PartiallySignedTransaction`, to get the JSON serialized value of all PSBT fields.
- Expose `Transaction` class's `txid`, `weight`, `size`, `vsize`, `isCoinBase`, `isExplicitlyRbf`, `version`, `isLockTimeEnabled`, `lockTime`, `input` and `output` functions.

- ## [0.27.2]
### API changed
- txBuilder.finish() & bumpFeeTxBuilder.finish() returns a `TxBuilderResult` instead of a `PartiallySignedTransaction`.

Expand Down
89 changes: 65 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ To use the `bdk_flutter` package in your project, add it as a dependency in your

```dart
dependencies:
bdk_flutter: ^0.27.3
bdk_flutter: ^0.28.0
```

### Examples

### Create a Wallet & sync the balance of a predefined descriptor
### Create a Wallet & sync the balance of a descriptor

```dart
import 'package:bdk_flutter/bdk_flutter.dart';
Expand Down Expand Up @@ -65,46 +65,87 @@ final externalDescriptor = await Descriptor.newBip44( descriptorSecretKey: descr
final externalPublicDescriptorStr = await externalDescriptor.asString();
final externalPublicDescriptor = await Descriptor.( descriptor: externalPublicDescriptorStr,
network: Network.Testnet);
```

### Get the transaction details

```dart
import 'package:bdk_flutter/bdk_flutter.dart';
final bdkWallet = .....
// ....
final txBuilder = TxBuilder();
final address = await Address.create(address: "mv4rnyY3Su5gjcDNzbMLKBQkBicCtHUtFB");
final script = await address.scriptPubKey();
final feeRate = await estimateFeeRate(25);
final txBuilderResult = await txBuilder.feeRate( feeRate.asSatPerVb() )
.addRecipient( script, 2000 )
.finish( bdkWallet );
final serializedPsbt = await txBuilderResult.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;
debugPrint("=========Inputs=====");
for (var e in inputs) {
debugPrint("amount: ${e['value']}");
debugPrint("script_pubkey: ${e['script_pubkey']}");
}
debugPrint("=========Outputs=====");
for (var e in outputs) {
debugPrint("amount: ${e['value']}");
debugPrint("script_pubkey: ${e['script_pubkey']}");
}
```

### Create an `internal` and `extarnal` wallet descriptors from derivation path.

And get internal and external addresses.

```dart
import 'package:bdk_flutter/bdk_flutter.dart';
// ....
final mnemonic = await Mnemonic.create(WordCount.Words12);
final descriptorSecretKey = await DescriptorSecretKey.create( network: Network.Testnet,
mnemonic: mnemonic );
final descriptorSecretKey = await DescriptorSecretKey.create(
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 descriptorPrivateKey =
await descriptorSecretKey.derive(derivationPath);
final Descriptor descriptorPrivate = await Descriptor.create(
descriptor: "pkh(${descriptorPrivateKey.toString()})",
network: Network.Testnet,
);
descriptor: "pkh(${descriptorPrivateKey.toString()})",
network: Network.Testnet,
);
// create internal descriptor
final derivationPathInt = await DerivationPath.create(path: "m/44h/1h/0h/1");
final descriptorPrivateKeyInt = await descriptorSecretKey.derive(derivationPathInt);
final derivationPathInt =
await DerivationPath.create(path: "m/44h/1h/0h/1");
final descriptorPrivateKeyInt =
await descriptorSecretKey.derive(derivationPathInt);
final Descriptor descriptorPrivateInt = await Descriptor.create(
descriptor: "pkh(${descriptorPrivateKeyInt.toString()})",
network: Network.Testnet,
);
descriptor: "pkh(${descriptorPrivateKeyInt.toString()})",
network: Network.Testnet,
);
final bdkWallet = await Wallet.create(
descriptor: aliceDescriptor!,
changeDescriptor: aliceDescriptorChange!,
network: Network.Testnet,
databaseConfig: const DatabaseConfig.memory(),
);
final address = await bdkWallet.getAddress(addressIndex: const AddressIndex());
final internalAddress = await bdkWallet.getInternalAddress(addressIndex: const AddressIndex());
descriptor: descriptorPrivate,
changeDescriptor: descriptorPrivateInt,
network: Network.Testnet,
databaseConfig: const DatabaseConfig.memory(),
);
final address =
await bdkWallet.getAddress(addressIndex: const AddressIndex());
final internalAddress =
await bdkWallet.getInternalAddress(addressIndex: const AddressIndex());
```

### API Documentation
Expand Down
Binary file modified android/src/main/jniLibs/arm64-v8a/librust_bdk_ffi.so
Binary file not shown.
Binary file modified android/src/main/jniLibs/armeabi-v7a/librust_bdk_ffi.so
Binary file not shown.
Binary file modified android/src/main/jniLibs/x86/librust_bdk_ffi.so
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler

/** BdkPlugin */
/** BdkFlutterPlugin */

class BdkPlugin : FlutterPlugin, MethodCallHandler {
class BdkFlutterPlugin : FlutterPlugin, MethodCallHandler {
private lateinit var channel: MethodChannel

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
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.27.1):
- bdk_flutter (0.28.0):
- Flutter
- Flutter (1.0.0)

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

SPEC CHECKSUMS:
bdk_flutter: 45bcefee47c051c8c42e507d6a3a708bdd0aadea
bdk_flutter: 0ec3ddfad3120c34d6a4aa7c338906fbcf8e35c4
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854

PODFILE CHECKSUM: 6998435987a000fdec9b2e1b5b1eef6d54bdba77
Expand Down
Loading

0 comments on commit a7d28a6

Please sign in to comment.