Skip to content

Commit

Permalink
Merge pull request #95 from LtbLightning/v0.29.0
Browse files Browse the repository at this point in the history
v0.29.0
  • Loading branch information
BitcoinZavior authored Jul 22, 2023
2 parents 606cfdf + f9465a5 commit f0c8e31
Show file tree
Hide file tree
Showing 29 changed files with 648 additions and 618 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
## [0.29.0]
Support Dart 3.
Updated Rust and Flutter dependencies.
#### APIs added
- Add `isMine` method to `Wallet`.
- Expose script.toBytes() method.

## [0.28.3]
### Fixed
- Multisig issue resolved by adding isMultiSig to signOptions.

## [0.28.2]

#### APIs added
- Expose `Wallet` class's `getDescriptorForKeyChain` and `getPsbtInput` functions.
- Expose `TxBuilder` class's `addForeignUtxo` function.
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To use the `bdk_flutter` package in your project, add it as a dependency in your

```dart
dependencies:
bdk_flutter: ^0.28.3
bdk_flutter: ^0.29.0
```

### Examples
Expand Down Expand Up @@ -195,7 +195,12 @@ _Note that Flutter version `3.0` or later is required to build the plugin._
Please use the [Dart documentation generator](https://pub.dev/packages/dartdoc) to generate the API documentation.
_Note: Caution this is pre-Alpha at this stage
### References:
- Setting up a local Esplora instance for testing:
https://bitcoin.stackexchange.com/questions/116937/how-do-i-setup-an-esplora-instance-for-local-testing/116938#116938
_Note: Caution this is Beta at this stage
Please consider reviewing, experimenting, and contributing ⚡️_
Thanks for taking a look!
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.
1 change: 1 addition & 0 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand Down
2 changes: 1 addition & 1 deletion example/lib/bdk_library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class BdkLibrary {
final script = await address.scriptPubKey();
final feeRate = await estimateFeeRate(25, blockchain);
final txBuilderResult = await txBuilder
.addRecipient(script, 800)
.addRecipient(script, 750)
.feeRate(feeRate.asSatPerVb())
.finish(aliceWallet);
getInputOutPuts(txBuilderResult, blockchain);
Expand Down
330 changes: 2 additions & 328 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,332 +1,6 @@
import 'package:bdk_flutter/bdk_flutter.dart';
import 'package:flutter/foundation.dart';
import 'package:bdk_flutter_example/simple_wallet.dart';
import 'package:flutter/material.dart';

import 'bdk_library.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatefulWidget {
const MyApp({super.key});

@override
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
String displayText = "";
int balance = 0;
late Wallet aliceWallet;
Blockchain? blockchain;
BdkLibrary lib = BdkLibrary();
@override
void initState() {
restoreWallet();
super.initState();
}

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

restoreWallet() async {
final mnemonic = await Mnemonic.fromString(
'puppy interest whip tonight dad never sudden response push zone pig patch');
final descriptors = await lib.createDescriptor(mnemonic);
aliceWallet = await lib.restoreWallet(descriptors);
setState(() {
displayText = "Wallets restored";
});
}

initBlockchain(bool isElectrumBlockchain) async {
blockchain = await lib.initializeBlockchain(isElectrumBlockchain);
}

sync() async {
if (blockchain == null) {
await initBlockchain(false);
}
await lib.sync(blockchain!, aliceWallet);
}

getNewAddress() async {
final res = await lib.getAddress(aliceWallet);
debugPrint(res.address);
setState(() {
displayText = "Address: ${res.address} \n Index: ${res.index}";
});
}

getUnConfirmedTransactions() async {
final unConfirmed = await lib.getUnConfirmedTransactions(aliceWallet);
setState(() {
displayText = "You have ${unConfirmed.length} unConfirmed transactions";
});
for (var e in unConfirmed) {
final txOut = await e.transaction!.output();
if (kDebugMode) {
print(" txid: ${e.txid}");
print(" fee: ${e.fee}");
print(" received: ${e.received}");
print(" send: ${e.sent}");
print(" output address: ${txOut.last.scriptPubkey.internal}");
print("===========================");
}
}
}

getConfirmedTransactions() async {
final confirmed = await lib.getConfirmedTransactions(aliceWallet);
setState(() {
displayText = "You have ${confirmed.length} confirmed transactions";
});
for (var e in confirmed) {
if (kDebugMode) {
print(" txid: ${e.txid}");
print(" confirmationTime: ${e.confirmationTime?.timestamp}");
print(" confirmationTime Height: ${e.confirmationTime?.height}");
final txIn = await e.transaction!.input();
final txOut = await e.transaction!.output();
print(" =============TxIn==============");
for (var e in txIn) {
print(" previousOutout Txid: ${e.previousOutput.txid}");
print(" previousOutout vout: ${e.previousOutput.vout}");
print(" witness: ${e.witness}");
}
print(" =============TxOut==============");
for (var e in txOut) {
print(" script: ${e.scriptPubkey.internal}");
print(" value: ${e.value}");
}
print("========================================");
}
}
}

getBalance() async {
final alice = await lib.getBalance(aliceWallet);
setState(() {
balance = alice.total;
displayText =
"Total Balance: ${alice.total} \n Immature Balance: ${alice.immature}";
});
}

listUnspent() async {
final res = await lib.listUnspend(aliceWallet);
for (var e in res) {
setState(() {
displayText =
" OutPoint: { txid:${res.first.outpoint.txid}, vout: ${res.first.outpoint.vout} }";
});
if (kDebugMode) {
print("isSpent: ${e.isSpent}");
print(
"outPoint: { txid:${e.outpoint.txid}, vout: ${e.outpoint.vout} } ");
print(
"txout: { address:${e.txout.scriptPubkey.internal.toString()}, value: ${e.txout.value} }");
print("===========================");
}
}
}

Future<int> getBlockHeight() async {
final res = await blockchain!.getHeight();
if (kDebugMode) {
print(res);
}
setState(() {
displayText = "Height: $res";
});
return res;
}

getBlockHash() async {
final height = await getBlockHeight();
final blockHash = await blockchain!.getBlockHash(height);
setState(() {
displayText = "BlockHash: $blockHash";
});
if (kDebugMode) {
print(blockHash);
}
}

sendBit() async {
await lib.sendBitcoin(
blockchain!, aliceWallet, "mv4rnyY3Su5gjcDNzbMLKBQkBicCtHUtFB");
}

@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
elevation: 0,
centerTitle: false,
title: const Text('Bdk Wallet',
style: TextStyle(
fontWeight: FontWeight.w900,
fontSize: 16,
color: Colors.white)), // Set this heigh
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.only(bottom: 50),
padding: const EdgeInsets.only(left: 15, right: 15, bottom: 20),
color: Colors.blue,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text("Response: ",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w700)),
Expanded(
child: SelectableText(
displayText,
maxLines: 3,
textAlign: TextAlign.start,
style: const TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w700),
),
),
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
balance.toString(),
style: const TextStyle(
fontWeight: FontWeight.w900,
fontSize: 40,
color: Colors.blue),
),
const Text(
" sats",
style: TextStyle(
fontWeight: FontWeight.w900,
fontSize: 20,
color: Colors.blue),
),
],
),
TextButton(
onPressed: () => getNewAddress(),
child: const Text(
'Press to create new Address',
style: TextStyle(
color: Colors.indigoAccent,
fontSize: 12,
height: 1.5,
fontWeight: FontWeight.w800),
)),
TextButton(
onPressed: () async {
await sync();
},
child: const Text(
'Press to sync',
style: TextStyle(
color: Colors.indigoAccent,
fontSize: 12,
height: 1.5,
fontWeight: FontWeight.w800),
)),
TextButton(
onPressed: () => getConfirmedTransactions(),
child: const Text(
'Get ConfirmedTransactions',
style: TextStyle(
color: Colors.indigoAccent,
fontSize: 12,
height: 1.5,
fontWeight: FontWeight.w800),
)),
TextButton(
onPressed: () => getUnConfirmedTransactions(),
child: const Text(
'getPendingTransactions',
style: TextStyle(
color: Colors.indigoAccent,
fontSize: 12,
height: 1.5,
fontWeight: FontWeight.w800),
)),
TextButton(
onPressed: () => getBalance(),
child: const Text(
'get Balance',
style: TextStyle(
color: Colors.indigoAccent,
fontSize: 12,
height: 1.5,
fontWeight: FontWeight.w800),
)),
TextButton(
onPressed: () => listUnspent(),
child: const Text(
'list Unspent',
style: TextStyle(
color: Colors.indigoAccent,
fontSize: 12,
height: 1.5,
fontWeight: FontWeight.w800),
)),
TextButton(
onPressed: () => sendBit(),
child: const Text(
'Press to send 1200 satoshi',
style: TextStyle(
color: Colors.indigoAccent,
fontSize: 12,
height: 1.5,
fontWeight: FontWeight.w800),
)),
TextButton(
onPressed: () => getBlockHash(),
child: const Text(
'get BlockHash',
style: TextStyle(
color: Colors.indigoAccent,
fontSize: 12,
height: 1.5,
fontWeight: FontWeight.w800),
)),
TextButton(
onPressed: () => generateMnemonicKeys(),
child: const Text(
'generate Mnemonic',
style: TextStyle(
color: Colors.indigoAccent,
fontSize: 12,
height: 1.5,
fontWeight: FontWeight.w800),
)),
],
),
),
),
);
}
runApp(const SimpleWallet());
}
Loading

0 comments on commit f0c8e31

Please sign in to comment.