Skip to content

Commit

Permalink
Merge pull request #140 from LtbLightning/upgrade-v0.31.2
Browse files Browse the repository at this point in the history
Upgrade v0.31.2
  • Loading branch information
BitcoinZavior authored Jul 19, 2024
2 parents 78c55c5 + a371352 commit 8a9bd98
Show file tree
Hide file tree
Showing 46 changed files with 6,416 additions and 12,319 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: [v0.31.2-dev.2, master, main]
branches: [0.31.2, master, main]

name: Precompile Binaries

Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [0.31.2]
Updated `flutter_rust_bridge` to `2.0.0`.
#### APIs added
- Exposed `createTestnet` & `createMutinynet` to `Blockchain`.
- Overrode `toString()` for `Address`, `DerivationPath`, `Descriptor`, `DescriptorPublicKey` , `DescriptorSecretKey`, `Mnemonic`,
- `PartiallySignedTransaction`, `ScriptBuf` & `Transaction`.
#### Changed
- `partiallySignedTransaction.serialize()` serialize the data as raw binary.

## [0.31.2-dev.2]
#### Fixed
- Thread `frb_workerpool` panicked on invalid `Fingerprint`.
Expand Down
5 changes: 2 additions & 3 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.31.2-dev.2
bdk_flutter: ^0.31.2
```

### Examples
Expand Down Expand Up @@ -86,8 +86,7 @@ final descriptorSecretKey = await DescriptorSecretKey.create( network: Network.t
final externalDescriptor = await Descriptor.newBip44( secretKey: descriptorSecretKey,
network: Network.testnet,
keychain: KeychainKind.externalChain );
final externalPublicDescriptorStr = await externalDescriptor.asString();
final externalPublicDescriptor = await Descriptor.( descriptor: externalPublicDescriptorStr,
final externalPublicDescriptor = await Descriptor.create( descriptor: externalDescriptor.toString(),
network: Network.testnet);
```

Expand Down
67 changes: 31 additions & 36 deletions example/lib/bdk_library.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:bdk_flutter/bdk_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';

class BdkLibrary {
Future<Mnemonic> createMnemonic() async {
Expand All @@ -12,6 +12,12 @@ class BdkLibrary {
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,
Expand All @@ -31,86 +37,75 @@ class BdkLibrary {
return wallet;
}

Future<void> sync(Blockchain blockchain, Wallet aliceWallet) async {
Future<void> sync(Blockchain blockchain, Wallet wallet) async {
try {
await aliceWallet.sync(blockchain: blockchain);
await wallet.sync(blockchain: blockchain);
} on FormatException catch (e) {
debugPrint(e.message);
}
}

Future<AddressInfo> getAddress(Wallet aliceWallet) async {
final address = await aliceWallet.getAddress(
addressIndex: const AddressIndex.increase());
return address;
AddressInfo getAddressInfo(Wallet wallet) {
return wallet.getAddress(addressIndex: const AddressIndex.increase());
}

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

Future<List<TransactionDetails>> getUnConfirmedTransactions(
Wallet aliceWallet) async {
List<TransactionDetails> getUnConfirmedTransactions(Wallet wallet) {
List<TransactionDetails> unConfirmed = [];
final res = await aliceWallet.listTransactions(includeRaw: true);
final res = wallet.listTransactions(includeRaw: true);
for (var e in res) {
if (e.confirmationTime == null) unConfirmed.add(e);
}
return unConfirmed;
}

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

for (var e in res) {
if (e.confirmationTime != null) confirmed.add(e);
}
return confirmed;
}

Future<Balance> getBalance(Wallet aliceWallet) async {
final res = await aliceWallet.getBalance();
return res;
Future<Balance> getBalance(Wallet wallet) async {
return wallet.getBalance();
}

Future<List<LocalUtxo>> listUnspend(Wallet aliceWallet) async {
final res = await aliceWallet.listUnspent();
return res;
List<LocalUtxo> listUnspent(Wallet wallet) {
return wallet.listUnspent();
}

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

sendBitcoin(
Blockchain blockchain,
Wallet aliceWallet,
String addressStr,
int amountSat,
) async {
sendBitcoin(Blockchain blockchain, Wallet wallet, String receiverAddress,
int amountSat) async {
try {
final txBuilder = TxBuilder();
final address = await Address.fromString(
s: addressStr, network: (await aliceWallet.network()));

final script = await address.scriptPubkey();
s: receiverAddress, network: wallet.network());
final script = address.scriptPubkey();
final feeRate = await estimateFeeRate(25, blockchain);
final (psbt, _) = await txBuilder
.addRecipient(script, amountSat)
.addRecipient(script, BigInt.from(amountSat))
.feeRate(feeRate.satPerVb)
.finish(aliceWallet);
final isFinalized = await aliceWallet.sign(psbt: psbt);
.finish(wallet);
final isFinalized = await wallet.sign(psbt: psbt);
if (isFinalized) {
final tx = await psbt.extractTx();
final tx = psbt.extractTx();
final res = await blockchain.broadcast(transaction: tx);
debugPrint(res);
} else {
Expand Down
20 changes: 10 additions & 10 deletions example/lib/multi_sig_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class MultiSigWallet {
for (var e in mnemonics) {
final secret = await DescriptorSecretKey.create(
network: Network.testnet, mnemonic: e);
final public = await secret.asPublic();
final public = secret.toPublic();
descriptorInfos.add(DescriptorKeyInfo(secret, public));
}
final alice =
Expand Down Expand Up @@ -54,19 +54,19 @@ class MultiSigWallet {
return [alice, bob, dave];
}

sendBitcoin(Blockchain blockchain, Wallet aliceWallet, Wallet bobWallet,
sendBitcoin(Blockchain blockchain, Wallet wallet, Wallet bobWallet,
String addressStr) async {
try {
final txBuilder = TxBuilder();
final address = await Address.fromString(
s: addressStr, network: (await aliceWallet.network()));
final script = await address.scriptPubkey();
final feeRate = await blockchain.estimateFee(target: 25);
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, 1000)
.addRecipient(script, BigInt.from(1200))
.feeRate(feeRate.satPerVb)
.finish(aliceWallet);
await aliceWallet.sign(
.finish(wallet);
await wallet.sign(
psbt: psbt,
signOptions: const SignOptions(
trustWitnessUtxo: false,
Expand All @@ -77,7 +77,7 @@ class MultiSigWallet {
allowGrinding: true));
final isFinalized = await bobWallet.sign(psbt: psbt);
if (isFinalized) {
final tx = await psbt.extractTx();
final tx = psbt.extractTx();
await blockchain.broadcast(transaction: tx);
} else {
debugPrint("Psbt not finalized!");
Expand Down
40 changes: 17 additions & 23 deletions example/lib/simple_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class SimpleWallet extends StatefulWidget {

class _SimpleWalletState extends State<SimpleWallet> {
String displayText = "";
int balance = 0;
late Wallet aliceWallet;
BigInt balance = BigInt.zero;
late Wallet wallet;
Blockchain? blockchain;
BdkLibrary lib = BdkLibrary();
@override
Expand All @@ -25,43 +25,41 @@ class _SimpleWalletState extends State<SimpleWallet> {

generateMnemonicKeys() async {
final res = await lib.createMnemonic();
final mnemonic = await res.asString();
setState(() {
displayText = mnemonic;
displayText = res.toString();
});
if (kDebugMode) {
print(mnemonic);
print(res.toString());
}
}

restoreWallet() async {
final aliceMnemonic = await Mnemonic.fromString(
'give rate trigger race embrace dream wish column upon steel wrist rice');
final aliceDescriptor = await lib.createDescriptor(aliceMnemonic);
aliceWallet = await lib.restoreWallet(aliceDescriptor);
wallet = await lib.restoreWallet(aliceDescriptor);
setState(() {
displayText = "Wallets restored";
});
}

sync() async {
blockchain ??= await lib.initializeBlockchain();
await lib.sync(blockchain!, aliceWallet);
await lib.sync(blockchain!, wallet);
}

getNewAddress() async {
final addressInfo = await lib.getAddress(aliceWallet);
final address = await addressInfo.address.asString();

debugPrint(address);
final addressInfo = lib.getAddressInfo(wallet);
debugPrint(addressInfo.address.toString());

setState(() {
displayText = "Address: $address \n Index: ${addressInfo.index}";
displayText =
"Address: ${addressInfo.address.toString()} \n Index: ${addressInfo.index}";
});
}

getUnConfirmedTransactions() async {
final unConfirmed = await lib.getUnConfirmedTransactions(aliceWallet);
final unConfirmed = lib.getUnConfirmedTransactions(wallet);
setState(() {
displayText = "You have ${unConfirmed.length} unConfirmed transactions";
});
Expand All @@ -79,7 +77,7 @@ class _SimpleWalletState extends State<SimpleWallet> {
}

getConfirmedTransactions() async {
final confirmed = await lib.getConfirmedTransactions(aliceWallet);
final confirmed = lib.getConfirmedTransactions(wallet);
setState(() {
displayText = "You have ${confirmed.length} confirmed transactions";
});
Expand Down Expand Up @@ -107,7 +105,7 @@ class _SimpleWalletState extends State<SimpleWallet> {
}

getBalance() async {
final alice = await lib.getBalance(aliceWallet);
final alice = await lib.getBalance(wallet);
setState(() {
balance = alice.total;
displayText =
Expand All @@ -116,7 +114,7 @@ class _SimpleWalletState extends State<SimpleWallet> {
}

listUnspent() async {
final res = await lib.listUnspend(aliceWallet);
final res = lib.listUnspent(wallet);
for (var e in res) {
setState(() {
displayText =
Expand Down Expand Up @@ -156,12 +154,8 @@ class _SimpleWalletState extends State<SimpleWallet> {
}

sendBit(int amountSat) async {
await lib.sendBitcoin(
blockchain!,
aliceWallet,
"tb1qyhssajdx5vfxuatt082m9tsfmxrxludgqwe52f",
amountSat,
);
await lib.sendBitcoin(blockchain!, wallet,
"tb1qyhssajdx5vfxuatt082m9tsfmxrxludgqwe52f", amountSat);
}

@override
Expand Down Expand Up @@ -295,7 +289,7 @@ class _SimpleWalletState extends State<SimpleWallet> {
TextButton(
onPressed: () => sendBit(100000),
child: const Text(
'Press to send 100k sats',
'Press to send 1200 satoshi',
style: TextStyle(
color: Colors.indigoAccent,
fontSize: 12,
Expand Down
4 changes: 2 additions & 2 deletions example/macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- bdk_flutter (0.31.2-dev.2):
- bdk_flutter (0.31.2):
- FlutterMacOS
- FlutterMacOS (1.0.0)

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

SPEC CHECKSUMS:
bdk_flutter: 5135d700e746fe36b8fb7e3e4dac539652aa3a2b
bdk_flutter: f31096ce6d28094dbbb43d2a3fb130f7c54683df
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24

PODFILE CHECKSUM: 6acf97521436d16fc31cd5e1a02000905acdb3ae
Expand Down
Loading

0 comments on commit 8a9bd98

Please sign in to comment.