Skip to content

Commit

Permalink
Update CHANGELOG.md
Browse files Browse the repository at this point in the history
  • Loading branch information
BitcoinZavior committed Oct 23, 2024
1 parent 133b199 commit fe59610
Show file tree
Hide file tree
Showing 60 changed files with 46,477 additions and 73,984 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/precompile_binaries.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
on:
push:
branches: [v1.0.0-alpha.11, master, main]
branches: [0.31.2, master, main]

name: Precompile Binaries

Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
## [1.0.0-alpha.11]

## [0.31.2]
Updated `flutter_rust_bridge` to `2.0.0`.
#### APIs added
Expand All @@ -8,6 +6,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: "1.0.0-alpha.11"
bdk_flutter: ^0.31.2
```

### Examples
Expand Down
48 changes: 0 additions & 48 deletions example/integration_test/full_cycle_test.dart

This file was deleted.

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

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

Future<List<Descriptor>> createDescriptor(Mnemonic mnemonic) async {
Future<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);
final changeDescriptor = await Descriptor.newBip84(
secretKey: descriptorSecretKey,
network: Network.signet,
keychain: KeychainKind.internalChain);
return [descriptor, changeDescriptor];
return descriptor;
}

Future<EsploraClient> initializeBlockchain() async {
return EsploraClient.createMutinynet();
Future<Blockchain> initializeBlockchain() async {
return Blockchain.createMutinynet();
}

Future<Wallet> crateOrLoadWallet(Descriptor descriptor,
Descriptor changeDescriptor, Connection connection) async {
try {
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;
}
}
Future<Wallet> restoreWallet(Descriptor descriptor) async {
final wallet = await Wallet.create(
descriptor: descriptor,
network: Network.testnet,
databaseConfig: const DatabaseConfig.memory());
return wallet;
}

Future<void> sync(
EsploraClient esploraClient, Wallet wallet, bool fullScan) async {
Future<void> sync(Blockchain blockchain, Wallet wallet) 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());
await wallet.sync(blockchain: blockchain);
} on FormatException catch (e) {
debugPrint(e.message);
}
}

AddressInfo revealNextAddress(Wallet wallet) {
return wallet.revealNextAddress(keychainKind: KeychainKind.externalChain);
AddressInfo getAddressInfo(Wallet wallet) {
return wallet.getAddress(addressIndex: const AddressIndex.increase());
}

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

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

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

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

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

sendBitcoin(EsploraClient blockchain, Wallet wallet, String receiverAddress,
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,
int amountSat) async {
try {
final txBuilder = TxBuilder();
final address = await Address.fromString(
s: receiverAddress, network: wallet.network());
final unspentUtxo =
wallet.listUnspent().firstWhere((e) => e.isSpent == false);
final psbt = await txBuilder
.addRecipient(address.script(), BigInt.from(amountSat))
.addUtxo(unspentUtxo.outpoint)
final script = address.scriptPubkey();
final feeRate = await estimateFeeRate(25, blockchain);
final (psbt, _) = await txBuilder
.addRecipient(script, BigInt.from(amountSat))
.feeRate(feeRate.satPerVb)
.finish(wallet);
final isFinalized = await wallet.sign(psbt: psbt);
if (isFinalized) {
final tx = psbt.extractTx();
await blockchain.broadcast(transaction: tx);
debugPrint(tx.computeTxid());
final res = await blockchain.broadcast(transaction: tx);
debugPrint(res);
} 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/wallet.dart';
import 'package:bdk_flutter_example/simple_wallet.dart';
import 'package:flutter/material.dart';

void main() {
runApp(const BdkWallet());
runApp(const SimpleWallet());
}
97 changes: 97 additions & 0 deletions example/lib/multi_sig_wallet.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import 'package:bdk_flutter/bdk_flutter.dart';
import 'package:flutter/foundation.dart';

class MultiSigWallet {
Future<List<Descriptor>> init2Of3Descriptors(List<Mnemonic> mnemonics) async {
final List<DescriptorKeyInfo> descriptorInfos = [];
for (var e in mnemonics) {
final secret = await DescriptorSecretKey.create(
network: Network.testnet, mnemonic: e);
final public = secret.toPublic();
descriptorInfos.add(DescriptorKeyInfo(secret, public));
}
final alice =
"wsh(sortedmulti(2,${descriptorInfos[0].xprv},${descriptorInfos[1].xpub},${descriptorInfos[2].xpub}))";
final bob =
"wsh(sortedmulti(2,${descriptorInfos[1].xprv},${descriptorInfos[2].xpub},${descriptorInfos[0].xpub}))";
final dave =
"wsh(sortedmulti(2,${descriptorInfos[2].xprv},${descriptorInfos[0].xpub},${descriptorInfos[1].xpub}))";
final List<Descriptor> descriptors = [];
final parsedDes = [alice, bob, dave];
for (var e in parsedDes) {
final res =
await Descriptor.create(descriptor: e, network: Network.testnet);
descriptors.add(res);
}
return descriptors;
}

Future<List<Descriptor>> createDescriptors() async {
final alice = await Mnemonic.fromString(
'thumb member wage display inherit music elevator need side setup tube panther broom giant auction banner split potato');
final bob = await Mnemonic.fromString(
'tired shine hat tired hover timber reward bridge verb aerobic safe economy');
final dave = await Mnemonic.fromString(
'lawsuit upper gospel minimum cinnamon common boss wage benefit betray ribbon hour');
final descriptors = await init2Of3Descriptors([alice, bob, dave]);
return descriptors;
}

Future<List<Wallet>> init20f3Wallets() async {
final descriptors = await createDescriptors();
final alice = await Wallet.create(
descriptor: descriptors[0],
network: Network.testnet,
databaseConfig: const DatabaseConfig.memory());
final bob = await Wallet.create(
descriptor: descriptors[1],
network: Network.testnet,
databaseConfig: const DatabaseConfig.memory());
final dave = await Wallet.create(
descriptor: descriptors[2],
network: Network.testnet,
databaseConfig: const DatabaseConfig.memory());
return [alice, bob, dave];
}

sendBitcoin(Blockchain blockchain, Wallet wallet, Wallet bobWallet,
String addressStr) async {
try {
final txBuilder = TxBuilder();
final address =
await Address.fromString(s: addressStr, network: wallet.network());
final script = address.scriptPubkey();
final feeRate = await blockchain.estimateFee(target: BigInt.from(25));
final (psbt, _) = await txBuilder
.addRecipient(script, BigInt.from(1200))
.feeRate(feeRate.satPerVb)
.finish(wallet);
await wallet.sign(
psbt: psbt,
signOptions: const SignOptions(
trustWitnessUtxo: false,
allowAllSighashes: true,
removePartialSigs: true,
tryFinalize: true,
signWithTapInternalKey: true,
allowGrinding: true));
final isFinalized = await bobWallet.sign(psbt: psbt);
if (isFinalized) {
final tx = psbt.extractTx();
await blockchain.broadcast(transaction: tx);
} else {
debugPrint("Psbt not finalized!");
}
} on FormatException catch (e) {
if (kDebugMode) {
print(e.message);
}
}
}
}

class DescriptorKeyInfo {
final DescriptorSecretKey xprv;
final DescriptorPublicKey xpub;
DescriptorKeyInfo(this.xprv, this.xpub);
}
Loading

0 comments on commit fe59610

Please sign in to comment.