Skip to content

Commit

Permalink
Merge pull request #46 from LtbLightning/update-bdk-v0.26
Browse files Browse the repository at this point in the history
Updates for bdk-ffi v0.26
  • Loading branch information
BitcoinZavior authored Jan 30, 2023
2 parents 280b789 + ddc2de5 commit c1452b8
Show file tree
Hide file tree
Showing 46 changed files with 11,447 additions and 4,310 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
.atom/
.buildlog/
.history
_DelSyncFiles
.svn/
migrate_working_dir/
.vscode/settings.json
Expand Down
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,55 @@
## [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
- newBip44 constructor returns a Descriptor with structure pkh(key/44'/{0,1}'/0'/{0,1}/*)
- newBip44Public constructor returns a Descriptor with structure pkh(key/{0,1}/*)
- newBip49 constructor returns a Descriptor with structure sh(wpkh(key/49'/{0,1}'/0'/{0,1}/*))
- newBip49Public constructor returns a Descriptor with structure sh(wpkh(key/{0,1}/*))
- newBip84 constructor returns a Descriptor with structure wpkh(key/84'/{0,1}'/0'/{0,1}/*)
- newBip84Public constructor returns a Descriptor with structure wpkh(key/{0,1}/*)
- 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
44 changes: 30 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,43 @@ To use the `bdk_flutter` package in your project, add it as a dependency in your

```dart
dependencies:
bdk_flutter: ^0.2.3
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 externalDescriptor = "wpkh([b8b575c2/84'/1'/0'/0]tprv8icWtRzy9CWgFxpGMLSdAeE4wWyz39XGc6SwykeTo13tYm14JkVVQAf7jz8DDarCgNJrG3aEPJEqchDWeJdiaWpS3FwbLB9SzsN57V7qxB/*)"
final internalDescriptor = "wpkh([b8b575c2/84'/1'/0'/1]tprv8icWtRzy9CWgFxpGMLSdAeE4wWyz39XGc6SwykeTo13tYm14JkVVQAf7jz8DDarCgNJrG3aEPJEqchDWeJdiaWpS3FwbLB9SzsN57V7qxB/*)"
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( externalDescriptor, internalDescriptor, Network.TESTNET, databaseConfig: const DatabaseConfig.memory());
final addressInfo = await wallet.getAddress(addressIndex: AddressIndex.New);
await wallet.sync(blockchain);
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(
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 );
```

### API Documentation
Expand Down
5 changes: 3 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
include: package:lints/recommended.yaml
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

analyzer:
exclude:
- lib/src/generated/bindings.dart
- lib/src/generated/bindings.freezed.dart

- lib/src/generated/bridge_definitions.dart
- lib/src/generated/bridge_definitions.freezed.dart
Binary file modified android/src/main/jniLibs/arm64-v8a/librust.so
Binary file not shown.
Binary file modified android/src/main/jniLibs/armeabi-v7a/librust.so
Binary file not shown.
Binary file modified android/src/main/jniLibs/x86/librust.so
Binary file not shown.
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.1.4):
- bdk_flutter (0.2.3):
- Flutter
- Flutter (1.0.0)

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

SPEC CHECKSUMS:
bdk_flutter: c6950c633e8208ba7d61cb1de14b215d62270b76
bdk_flutter: e78411cd1fb06a522180fac6276ebc1989ba480a
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854

PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3
Expand Down
79 changes: 44 additions & 35 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class MyApp extends StatefulWidget {

class _MyAppState extends State<MyApp> {
late Wallet aliceWallet;

late Blockchain blockchain;
Descriptor? aliceDescriptor;
late Descriptor aliceChangeDescriptor;
Blockchain? blockchain;

@override
void initState() {
restoreWallet();
createDescriptorSecret();
super.initState();
}

Expand All @@ -33,9 +33,9 @@ class _MyAppState extends State<MyApp> {
}

restoreWallet() async {
await createDescriptorSecret();
aliceWallet = await Wallet.create(
descriptor:
"wpkh(tprv8ZgxMBicQKsPczV7D2zfMr7oUzHDhNPEuBUgrwRoWM3ijLRvhG87xYiqh9JFLPqojuhmqwMdo1oJzbe5GUpxCbDHnqyGhQa5Jg1Wt6rc9di/84'/1'/0'/1/*)",
descriptor: aliceDescriptor!,
network: Network.Testnet,
databaseConfig: const DatabaseConfig.memory());
if (kDebugMode) {
Expand All @@ -50,39 +50,48 @@ class _MyAppState extends State<MyApp> {
network: Network.Testnet,
mnemonic: mnemonic,
);
final descriptor = await Descriptor.newBip44(
descriptorSecretKey: descriptorSecretKey,
network: Network.Testnet,
keyChainKind: KeychainKind.External);

final path = await DerivationPath.create(path: "m/84'/1'/0'");
final xprv = await descriptorSecretKey.asString();
final sec = await descriptorSecretKey.secretBytes();
final xpub = await descriptorSecretKey.asPublic();
final xpubString = xpub.asString();
final derivedXprv = await descriptorSecretKey.extend(path);
final derivedXpub = await xpub.extend(path);
final derivedXprvStr = await derivedXprv.asString();
final derivedXpubStr = derivedXpub.asString();
if (kDebugMode) {
print("sec: $sec");
print("xpub: $xpubString");
print("xprv: $xprv");
print("derivedXpub: $derivedXpubStr");
print("derivedXprv: $derivedXprvStr");
setState(() {
aliceDescriptor = descriptor;
});
}

initElectrumBlockchain(bool isElectrum) async {
if (blockchain == null) {
if (!isElectrum) {
blockchain = await Blockchain.create(
config: BlockchainConfig.rpc(
config: RpcConfig(
url: 'http://127.0.0.1:18446',
authUserPass:
UserPass(username: 'polaruser', password: 'polarpass'),
network: Network.Regtest,
walletName: 'default')));
} else {
blockchain = await Blockchain.create(
config: BlockchainConfig.electrum(
config: ElectrumConfig(
stopGap: 10,
timeout: 5,
retry: 5,
url: "ssl://electrum.blockstream.info:60002",
validateDomain: true)));
}
}
}

sync() async {
blockchain = await Blockchain.create(
config: BlockchainConfig.electrum(
config: ElectrumConfig(
stopGap: 10,
timeout: 5,
retry: 5,
url: "ssl://electrum.blockstream.info:60002")));
aliceWallet.sync(blockchain);
await initElectrumBlockchain(true);
aliceWallet.sync(blockchain!);
}

getNewAddress() async {
final alice =
await aliceWallet.getAddress(addressIndex: AddressIndex.LastUnused);
await aliceWallet.getAddress(addressIndex: AddressIndex.New);
if (kDebugMode) {
print(alice.address);
print(alice.index);
Expand Down Expand Up @@ -146,7 +155,7 @@ class _MyAppState extends State<MyApp> {
}

Future<int> getBlockHeight() async {
final res = await blockchain.getHeight();
final res = await blockchain!.getHeight();
if (kDebugMode) {
print(res);
}
Expand All @@ -155,23 +164,23 @@ class _MyAppState extends State<MyApp> {

getBlockHash() async {
final height = await getBlockHeight();
final blockHash = await blockchain.getBlockHash(height);
final blockHash = await blockchain!.getBlockHash(height);
if (kDebugMode) {
print(blockHash);
}
}

sendBit() async {
final txBuilder = TxBuilder();
final address = await Address.create(
address: "tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt");
final address =
await Address.create(address: "mv4rnyY3Su5gjcDNzbMLKBQkBicCtHUtFB");
final script = await address.scriptPubKey();
final psbt = await txBuilder
.addRecipient(script, 1000)
.addRecipient(script, 700)
.feeRate(1.1)
.finish(aliceWallet);
final res = await aliceWallet.sign(psbt);
await blockchain.broadcast(res);
await blockchain!.broadcast(res);
sync();
}

Expand Down
4 changes: 2 additions & 2 deletions 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.2.3"
version: "0.3.0"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -201,7 +201,7 @@ packages:
name: flutter_rust_bridge
url: "https://pub.dartlang.org"
source: hosted
version: "1.54.0"
version: "1.60.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down
Loading

0 comments on commit c1452b8

Please sign in to comment.