Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1 alpha #148

Merged
merged 87 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
4b7abb8
flutter pub publish issue resolved
BitcoinZavior Sep 2, 2024
d8ce141
Rebase
BitcoinZavior Sep 2, 2024
063feff
bdk::keys::bip39::Error implemented for BdkError
BitcoinZavior Sep 2, 2024
2f92e14
Merge pull request
BitcoinZavior Sep 3, 2024
983d45e
version updated to 1.0.0-alpha.11
BitcoinZavior Sep 5, 2024
a13d0b5
handle_mutex exposed to handle lock errors
BitcoinZavior Sep 5, 2024
dd1343f
removed all unhandled unwraps
BitcoinZavior Sep 6, 2024
48ba8b3
removed all unhandled unwraps
BitcoinZavior Sep 6, 2024
7dd8f5c
bdk::keys::bip39::Error implemented for BdkError
BitcoinZavior Sep 7, 2024
2627132
implemeted handle_mutex
BitcoinZavior Sep 7, 2024
b322a40
bindings updated
BitcoinZavior Sep 8, 2024
8762204
esplora url updated
BitcoinZavior Sep 8, 2024
79dec16
handle_mutex exposed to handle lock errors
BitcoinZavior Sep 10, 2024
112f7c7
removed all unhandled unwraps
BitcoinZavior Sep 10, 2024
5f2e566
Rebase
BitcoinZavior Sep 10, 2024
f6ad409
removed all unhandled unwraps
BitcoinZavior Sep 13, 2024
ab1d5d2
implemeted handle_mutex
BitcoinZavior Sep 14, 2024
84f080d
bindings updated
BitcoinZavior Sep 14, 2024
8b04407
esplora url updated
BitcoinZavior Sep 14, 2024
c8a0b99
removed blockchain class
BitcoinZavior Sep 17, 2024
46ba1b4
custom errors updated
BitcoinZavior Sep 17, 2024
cff9f58
replaced BdkError with custom errors
BitcoinZavior Sep 18, 2024
b6c4617
exposed FfiFullScanRequestBuilder & FfiFullScanRequestBuilder
BitcoinZavior Sep 18, 2024
7436ca1
exposed connection
BitcoinZavior Sep 19, 2024
81b5cd1
seperated bitcoin mod structs
BitcoinZavior Sep 20, 2024
57a2ae9
dependencies upgraded
BitcoinZavior Sep 22, 2024
d2f0b42
version descriptancy resolved
BitcoinZavior Sep 25, 2024
cb4e3c6
flutter_rust_bridge updated to 2.4.0
BitcoinZavior Sep 26, 2024
1dbf55c
code formatted
BitcoinZavior Sep 27, 2024
7663730
exposed generic error
BitcoinZavior Sep 27, 2024
c65d5c8
exposed LocalOutput & ChangeSpendPolicy
BitcoinZavior Sep 27, 2024
bfd1e3b
code cleanup
BitcoinZavior Sep 27, 2024
512ab4d
exposed electrum mod
BitcoinZavior Sep 28, 2024
4e4e29f
code formtted
BitcoinZavior Sep 30, 2024
1070e6c
exposed esplora
BitcoinZavior Oct 1, 2024
ee6b214
test cases added
BitcoinZavior Oct 1, 2024
0736914
exposed wallet & tx_builder
BitcoinZavior Oct 3, 2024
e630504
bindings updated
BitcoinZavior Oct 3, 2024
70c26d8
exposed sign & SignerError
BitcoinZavior Oct 4, 2024
77cfa7f
mapped all the exceptions
BitcoinZavior Oct 4, 2024
654c0ed
code cleanup
BitcoinZavior Oct 5, 2024
6a1ccca
code cleanup
BitcoinZavior Oct 5, 2024
f062d64
removed Blockchain & exposed SyncRequest & FullScanRequest builders
BitcoinZavior Oct 5, 2024
e0232e3
code clean up
BitcoinZavior Oct 6, 2024
5f1e4e5
code formatted
BitcoinZavior Oct 6, 2024
caf5383
exposed EsploraClient & ElectrumClient
BitcoinZavior Oct 6, 2024
d3c59b6
code cleanup
BitcoinZavior Oct 7, 2024
4e44e81
removed remove_partial_sigs
BitcoinZavior Oct 9, 2024
4474db3
dart keyword error resolved
BitcoinZavior Oct 9, 2024
1da4571
refactor(Transaction): made all the non-constructor functions synchro…
BitcoinZavior Oct 11, 2024
f18c7be
bindings updated
BitcoinZavior Oct 11, 2024
574234b
code cleanup
BitcoinZavior Oct 11, 2024
e339722
Exposed sync in Electrum & Esplora Client
BitcoinZavior Oct 11, 2024
73cca02
fix: Updated example code for new version compliance
BitcoinZavior Oct 12, 2024
35ccc79
added integration_test
BitcoinZavior Oct 12, 2024
8026a4c
changed fullScan to false
BitcoinZavior Oct 13, 2024
eceab0a
added integration_tests
BitcoinZavior Oct 15, 2024
eacd8e5
Merge pull request
BitcoinZavior Oct 15, 2024
9afecfb
exposed & mapped BumpfeeTx exception
BitcoinZavior Oct 15, 2024
f0b2f2e
mapped exceptions
BitcoinZavior Oct 17, 2024
b645d85
doc comments updated
BitcoinZavior Oct 17, 2024
98dc360
mock tests updated
BitcoinZavior Oct 21, 2024
2ed3002
feat(FfiSyncRequestBuilder): updated progress to SyncProgress
BitcoinZavior Oct 22, 2024
66232b7
updated stop_on_error to true
BitcoinZavior Oct 24, 2024
0070e17
code cleanup
BitcoinZavior Oct 24, 2024
a9bd4e6
created todos to resolve unhandled unwraps
BitcoinZavior Oct 24, 2024
879d6cb
Build on push to all branches
BitcoinZavior Oct 25, 2024
6cbadd9
Build on push to all branches
BitcoinZavior Oct 25, 2024
507a759
bindings updated
BitcoinZavior Oct 28, 2024
302aa4e
handled PanicExceptions
BitcoinZavior Oct 28, 2024
4290df6
code cleanup
BitcoinZavior Oct 28, 2024
2678536
sync updated
BitcoinZavior Oct 29, 2024
fc295ee
code cleanup
BitcoinZavior Oct 29, 2024
6aeba84
class name updated
BitcoinZavior Oct 31, 2024
66ecae7
Merge branch 'main' into v1.0.0-alpha.11
BitcoinZavior Nov 3, 2024
867979e
restoreWallet updated
BitcoinZavior Nov 5, 2024
04da44c
Code cleanup
BitcoinZavior Nov 5, 2024
85967cd
code cleanup
BitcoinZavior Nov 6, 2024
2d74b97
feat: expose wallet.policies
BitcoinZavior Nov 7, 2024
b093aae
feat: expose txBuilder.policyPath
BitcoinZavior Nov 7, 2024
660d5b8
Merge branch 'upgrade-to-v0.31.2' into minor-fixes
BitcoinZavior Nov 8, 2024
6e153bf
Merge pull request #146 from LtbLightning/minor-fixes
BitcoinZavior Nov 8, 2024
6c62a20
Merge pull request #145 from LtbLightning/upgrade-to-v0.31.2
BitcoinZavior Nov 8, 2024
ddfdf70
flutter pub publish issue resolved
BitcoinZavior Sep 2, 2024
8ca4b83
Update CHANGELOG.md
BitcoinZavior Nov 8, 2024
2fbb172
Update precompile_binaries.yml
BitcoinZavior Nov 8, 2024
8f01157
Merge branch 'main' into v1.0.0-alpha.11
BitcoinZavior Nov 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/precompile_binaries.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
on:
push:
branches: [0.31.2, master, main]
branches: '*'

name: Precompile Binaries

Expand Down Expand Up @@ -51,4 +51,4 @@ jobs:
working-directory: cargokit/build_tool
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
PRIVATE_KEY: ${{ secrets.CARGOKIT_PRIVATE_KEY }}
PRIVATE_KEY: ${{ secrets.CARGOKIT_PRIVATE_KEY }}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## [1.0.0-alpha.11]

## [0.31.2]
Updated `flutter_rust_bridge` to `2.0.0`.
#### APIs added
Expand All @@ -6,6 +8,9 @@ Updated `flutter_rust_bridge` to `2.0.0`.
- `PartiallySignedTransaction`, `ScriptBuf` & `Transaction`.
#### Changed
- `partiallySignedTransaction.serialize()` serialize the data as raw binary.
#### Fixed
- Thread `frb_workerpool` panicked on Sql database access.


## [0.31.2-dev.2]
#### Fixed
Expand Down
2 changes: 1 addition & 1 deletion 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.31.2
bdk_flutter: "1.0.0-alpha.11"
```

### Examples
Expand Down
48 changes: 48 additions & 0 deletions example/integration_test/full_cycle_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:bdk_flutter/bdk_flutter.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('Descriptor & Keys', () {
setUp(() async {});
testWidgets('Muti-sig wallet generation', (_) async {
final descriptor = await Descriptor.create(
descriptor:
"wsh(or_d(pk([24d87569/84'/1'/0'/0/0]tpubDHebJGZWZaZ3JkhwTx5DytaRpFhK9ffFaN9PMBm7m63bdkdxqKgXkSPMzYzfDAGStx8LWt4b2CgGm86BwtNuG6PdsxsLVmuf6EjREX3oHjL/0/0/*),and_v(v:older(12),pk([24d87569/84'/1'/0'/0/0]tpubDHebJGZWZaZ3JkhwTx5DytaRpFhK9ffFaN9PMBm7m63bdkdxqKgXkSPMzYzfDAGStx8LWt4b2CgGm86BwtNuG6PdsxsLVmuf6EjREX3oHjL/0/1/*))))",
network: Network.testnet);
final changeDescriptor = await Descriptor.create(
descriptor:
"wsh(or_d(pk([24d87569/84'/1'/0'/1/0]tpubDHebJGZWZaZ3JkhwTx5DytaRpFhK9ffFaN9PMBm7m63bdkdxqKgXkSPMzYzfDAGStx8LWt4b2CgGm86BwtNuG6PdsxsLVmuf6EjREX3oHjL/1/0/*),and_v(v:older(12),pk([24d87569/84'/1'/0'/1/0]tpubDHebJGZWZaZ3JkhwTx5DytaRpFhK9ffFaN9PMBm7m63bdkdxqKgXkSPMzYzfDAGStx8LWt4b2CgGm86BwtNuG6PdsxsLVmuf6EjREX3oHjL/1/1/*))))",
network: Network.testnet);

final wallet = await Wallet.create(
descriptor: descriptor,
changeDescriptor: changeDescriptor,
network: Network.testnet,
connection: await Connection.createInMemory());
debugPrint(wallet.network().toString());
});
testWidgets('Derive descriptorSecretKey Manually', (_) async {
final mnemonic = await Mnemonic.create(WordCount.words12);
final descriptorSecretKey = await DescriptorSecretKey.create(
network: Network.testnet, mnemonic: mnemonic);
debugPrint(descriptorSecretKey.toString());

for (var e in [0, 1]) {
final derivationPath =
await DerivationPath.create(path: "m/84'/1'/0'/$e");
final derivedDescriptorSecretKey =
await descriptorSecretKey.derive(derivationPath);
debugPrint(derivedDescriptorSecretKey.toString());
debugPrint(derivedDescriptorSecretKey.toPublic().toString());
final descriptor = await Descriptor.create(
descriptor: "wpkh($derivedDescriptorSecretKey)",
network: Network.testnet);

debugPrint(descriptor.toString());
}
});
});
}
2 changes: 1 addition & 1 deletion example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import Flutter

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down
138 changes: 82 additions & 56 deletions example/lib/bdk_library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,105 @@ class BdkLibrary {
return res;
}

Future<Descriptor> createDescriptor(Mnemonic mnemonic) async {
Future<List<Descriptor>> createDescriptor(Mnemonic mnemonic) async {
final descriptorSecretKey = await DescriptorSecretKey.create(
network: Network.signet,
mnemonic: mnemonic,
);
if (kDebugMode) {
print(descriptorSecretKey.toPublic());
print(descriptorSecretKey.secretBytes());
print(descriptorSecretKey);
}

final descriptor = await Descriptor.newBip84(
secretKey: descriptorSecretKey,
network: Network.signet,
keychain: KeychainKind.externalChain);
return descriptor;
}

Future<Blockchain> initializeBlockchain() async {
return Blockchain.createMutinynet();
final changeDescriptor = await Descriptor.newBip84(
secretKey: descriptorSecretKey,
network: Network.signet,
keychain: KeychainKind.internalChain);
return [descriptor, changeDescriptor];
}

Future<Wallet> restoreWallet(Descriptor descriptor) async {
final wallet = await Wallet.create(
descriptor: descriptor,
network: Network.testnet,
databaseConfig: const DatabaseConfig.memory());
return wallet;
Future<EsploraClient> initializeBlockchain() async {
return EsploraClient.createMutinynet();
}

Future<void> sync(Blockchain blockchain, Wallet wallet) async {
Future<Wallet> crateOrLoadWallet(Descriptor descriptor,
Descriptor changeDescriptor, Connection connection) async {
try {
await wallet.sync(blockchain: blockchain);
} on FormatException catch (e) {
debugPrint(e.message);
final wallet = await Wallet.create(
descriptor: descriptor,
changeDescriptor: changeDescriptor,
network: Network.signet,
connection: connection);
return wallet;
} on CreateWithPersistException catch (e) {
if (e.code == "DatabaseExists") {
final res = await Wallet.load(
descriptor: descriptor,
changeDescriptor: changeDescriptor,
connection: connection);
return res;
} else {
rethrow;
}
}
}

AddressInfo getAddressInfo(Wallet wallet) {
return wallet.getAddress(addressIndex: const AddressIndex.increase());
Future<void> sync(
EsploraClient esploraClient, Wallet wallet, bool fullScan) async {
try {
if (fullScan) {
final fullScanRequestBuilder = await wallet.startFullScan();
final fullScanRequest = await (await fullScanRequestBuilder
.inspectSpksForAllKeychains(inspector: (e, f, g) {
debugPrint(
"Syncing: index: ${f.toString()}, script: ${g.toString()}");
}))
.build();
final update = await esploraClient.fullScan(
request: fullScanRequest,
stopGap: BigInt.from(1),
parallelRequests: BigInt.from(1));
await wallet.applyUpdate(update: update);
} else {
final syncRequestBuilder = await wallet.startSyncWithRevealedSpks();
final syncRequest = await (await syncRequestBuilder.inspectSpks(
inspector: (script, progress) {
debugPrint(
"syncing spk: ${(progress.spksConsumed / (progress.spksConsumed + progress.spksRemaining)) * 100} %");
}))
.build();
final update = await esploraClient.sync(
request: syncRequest, parallelRequests: BigInt.from(1));
await wallet.applyUpdate(update: update);
}
} on Exception catch (e) {
debugPrint(e.toString());
}
}

Future<Input> getPsbtInput(
Wallet wallet, LocalUtxo utxo, bool onlyWitnessUtxo) async {
final input =
await wallet.getPsbtInput(utxo: utxo, onlyWitnessUtxo: onlyWitnessUtxo);
return input;
AddressInfo revealNextAddress(Wallet wallet) {
return wallet.revealNextAddress(keychainKind: KeychainKind.externalChain);
}

List<TransactionDetails> getUnConfirmedTransactions(Wallet wallet) {
List<TransactionDetails> unConfirmed = [];
final res = wallet.listTransactions(includeRaw: true);
List<CanonicalTx> getUnConfirmedTransactions(Wallet wallet) {
List<CanonicalTx> unConfirmed = [];
final res = wallet.transactions();
for (var e in res) {
if (e.confirmationTime == null) unConfirmed.add(e);
if (e.chainPosition
.maybeMap(orElse: () => false, unconfirmed: (_) => true)) {
unConfirmed.add(e);
}
}
return unConfirmed;
}

List<TransactionDetails> getConfirmedTransactions(Wallet wallet) {
List<TransactionDetails> confirmed = [];
final res = wallet.listTransactions(includeRaw: true);

List<CanonicalTx> getConfirmedTransactions(Wallet wallet) {
List<CanonicalTx> confirmed = [];
final res = wallet.transactions();
for (var e in res) {
if (e.confirmationTime != null) confirmed.add(e);
if (e.chainPosition
.maybeMap(orElse: () => false, confirmed: (_) => true)) {
confirmed.add(e);
}
}
return confirmed;
}
Expand All @@ -79,39 +114,30 @@ class BdkLibrary {
return wallet.getBalance();
}

List<LocalUtxo> listUnspent(Wallet wallet) {
List<LocalOutput> listUnspent(Wallet wallet) {
return wallet.listUnspent();
}

Future<FeeRate> estimateFeeRate(
int blocks,
Blockchain blockchain,
) async {
final feeRate = await blockchain.estimateFee(target: BigInt.from(blocks));
return feeRate;
}

sendBitcoin(Blockchain blockchain, Wallet wallet, String receiverAddress,
sendBitcoin(EsploraClient blockchain, Wallet wallet, String receiverAddress,
int amountSat) async {
try {
final txBuilder = TxBuilder();
final address = await Address.fromString(
s: receiverAddress, network: wallet.network());
final script = address.scriptPubkey();
final feeRate = await estimateFeeRate(25, blockchain);
final (psbt, _) = await txBuilder
.addRecipient(script, BigInt.from(amountSat))
.feeRate(feeRate.satPerVb)
final unspentUtxo =
wallet.listUnspent().firstWhere((e) => e.isSpent == false);
final psbt = await txBuilder
.addRecipient(address.script(), BigInt.from(amountSat))
.addUtxo(unspentUtxo.outpoint)
.finish(wallet);
final isFinalized = await wallet.sign(psbt: psbt);
if (isFinalized) {
final tx = psbt.extractTx();
final res = await blockchain.broadcast(transaction: tx);
debugPrint(res);
await blockchain.broadcast(transaction: tx);
debugPrint(tx.computeTxid());
} else {
debugPrint("psbt not finalized!");
}
// Isolate.run(() async => {});
} on Exception catch (_) {
rethrow;
}
Expand Down
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:bdk_flutter_example/simple_wallet.dart';
import 'package:bdk_flutter_example/wallet.dart';
import 'package:flutter/material.dart';

void main() {
runApp(const SimpleWallet());
runApp(const BdkWallet());
}
97 changes: 0 additions & 97 deletions example/lib/multi_sig_wallet.dart

This file was deleted.

Loading
Loading